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 | 40f3582 | 2016-06-23 11:12:53 -0600 | [diff] [blame] | 1019 | |
| 1020 | // This is a positive test. No failures are expected. |
| 1021 | TEST_F(VkLayerTest, IgnoreUnrelatedDescriptor) { |
| 1022 | TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSet validation code " |
| 1023 | "is ignoring VkWriteDescriptorSet members that are not " |
| 1024 | "related to the descriptor type specified by " |
| 1025 | "VkWriteDescriptorSet::descriptorType. Correct " |
| 1026 | "validation behavior will result in the test running to " |
| 1027 | "completion without validation errors."); |
| 1028 | |
Dustin Graves | 5e2d8fc | 2016-07-07 16:18:49 -0600 | [diff] [blame] | 1029 | const uintptr_t invalid_ptr = 0xcdcdcdcd; |
| 1030 | |
Dustin Graves | 40f3582 | 2016-06-23 11:12:53 -0600 | [diff] [blame] | 1031 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1032 | |
| 1033 | // Image Case |
| 1034 | { |
| 1035 | m_errorMonitor->ExpectSuccess(); |
| 1036 | |
| 1037 | VkImage image; |
| 1038 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 1039 | const int32_t tex_width = 32; |
| 1040 | const int32_t tex_height = 32; |
| 1041 | VkImageCreateInfo image_create_info = {}; |
| 1042 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 1043 | image_create_info.pNext = NULL; |
| 1044 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 1045 | image_create_info.format = tex_format; |
| 1046 | image_create_info.extent.width = tex_width; |
| 1047 | image_create_info.extent.height = tex_height; |
| 1048 | image_create_info.extent.depth = 1; |
| 1049 | image_create_info.mipLevels = 1; |
| 1050 | image_create_info.arrayLayers = 1; |
| 1051 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 1052 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 1053 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 1054 | image_create_info.flags = 0; |
| 1055 | VkResult err = |
| 1056 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 1057 | ASSERT_VK_SUCCESS(err); |
| 1058 | |
| 1059 | VkMemoryRequirements memory_reqs; |
| 1060 | VkDeviceMemory image_memory; |
| 1061 | bool pass; |
| 1062 | VkMemoryAllocateInfo memory_info = {}; |
| 1063 | memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1064 | memory_info.pNext = NULL; |
| 1065 | memory_info.allocationSize = 0; |
| 1066 | memory_info.memoryTypeIndex = 0; |
| 1067 | vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs); |
| 1068 | memory_info.allocationSize = memory_reqs.size; |
| 1069 | pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, |
| 1070 | &memory_info, 0); |
| 1071 | ASSERT_TRUE(pass); |
| 1072 | err = vkAllocateMemory(m_device->device(), &memory_info, NULL, |
| 1073 | &image_memory); |
| 1074 | ASSERT_VK_SUCCESS(err); |
| 1075 | err = vkBindImageMemory(m_device->device(), image, image_memory, 0); |
| 1076 | ASSERT_VK_SUCCESS(err); |
| 1077 | |
| 1078 | VkImageViewCreateInfo image_view_create_info = {}; |
| 1079 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 1080 | image_view_create_info.image = image; |
| 1081 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 1082 | image_view_create_info.format = tex_format; |
| 1083 | image_view_create_info.subresourceRange.layerCount = 1; |
| 1084 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 1085 | image_view_create_info.subresourceRange.levelCount = 1; |
| 1086 | image_view_create_info.subresourceRange.aspectMask = |
| 1087 | VK_IMAGE_ASPECT_COLOR_BIT; |
| 1088 | |
| 1089 | VkImageView view; |
| 1090 | err = vkCreateImageView(m_device->device(), &image_view_create_info, |
| 1091 | NULL, &view); |
| 1092 | ASSERT_VK_SUCCESS(err); |
| 1093 | |
| 1094 | VkDescriptorPoolSize ds_type_count = {}; |
| 1095 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 1096 | ds_type_count.descriptorCount = 1; |
| 1097 | |
| 1098 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 1099 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 1100 | ds_pool_ci.pNext = NULL; |
| 1101 | ds_pool_ci.maxSets = 1; |
| 1102 | ds_pool_ci.poolSizeCount = 1; |
| 1103 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 1104 | |
| 1105 | VkDescriptorPool ds_pool; |
| 1106 | err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, |
| 1107 | &ds_pool); |
| 1108 | ASSERT_VK_SUCCESS(err); |
| 1109 | |
| 1110 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 1111 | dsl_binding.binding = 0; |
| 1112 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 1113 | dsl_binding.descriptorCount = 1; |
| 1114 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 1115 | dsl_binding.pImmutableSamplers = NULL; |
| 1116 | |
| 1117 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 1118 | ds_layout_ci.sType = |
| 1119 | VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 1120 | ds_layout_ci.pNext = NULL; |
| 1121 | ds_layout_ci.bindingCount = 1; |
| 1122 | ds_layout_ci.pBindings = &dsl_binding; |
| 1123 | VkDescriptorSetLayout ds_layout; |
| 1124 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, |
| 1125 | NULL, &ds_layout); |
| 1126 | ASSERT_VK_SUCCESS(err); |
| 1127 | |
| 1128 | VkDescriptorSet descriptor_set; |
| 1129 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 1130 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 1131 | alloc_info.descriptorSetCount = 1; |
| 1132 | alloc_info.descriptorPool = ds_pool; |
| 1133 | alloc_info.pSetLayouts = &ds_layout; |
| 1134 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 1135 | &descriptor_set); |
| 1136 | ASSERT_VK_SUCCESS(err); |
| 1137 | |
| 1138 | VkDescriptorImageInfo image_info = {}; |
| 1139 | image_info.imageView = view; |
| 1140 | image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 1141 | |
| 1142 | VkWriteDescriptorSet descriptor_write; |
| 1143 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 1144 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 1145 | descriptor_write.dstSet = descriptor_set; |
| 1146 | descriptor_write.dstBinding = 0; |
| 1147 | descriptor_write.descriptorCount = 1; |
| 1148 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 1149 | descriptor_write.pImageInfo = &image_info; |
| 1150 | |
| 1151 | // Set pBufferInfo and pTexelBufferView to invalid values, which should |
| 1152 | // be |
| 1153 | // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE. |
| 1154 | // This will most likely produce a crash if the parameter_validation |
| 1155 | // layer |
| 1156 | // does not correctly ignore pBufferInfo. |
| 1157 | descriptor_write.pBufferInfo = |
Dustin Graves | 5e2d8fc | 2016-07-07 16:18:49 -0600 | [diff] [blame] | 1158 | reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr); |
Dustin Graves | 40f3582 | 2016-06-23 11:12:53 -0600 | [diff] [blame] | 1159 | descriptor_write.pTexelBufferView = |
Dustin Graves | 5e2d8fc | 2016-07-07 16:18:49 -0600 | [diff] [blame] | 1160 | reinterpret_cast<const VkBufferView *>(invalid_ptr); |
Dustin Graves | 40f3582 | 2016-06-23 11:12:53 -0600 | [diff] [blame] | 1161 | |
| 1162 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, |
| 1163 | NULL); |
| 1164 | |
| 1165 | m_errorMonitor->VerifyNotFound(); |
| 1166 | |
| 1167 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set); |
| 1168 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 1169 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 1170 | vkDestroyImageView(m_device->device(), view, NULL); |
| 1171 | vkDestroyImage(m_device->device(), image, NULL); |
| 1172 | vkFreeMemory(m_device->device(), image_memory, NULL); |
| 1173 | } |
| 1174 | |
| 1175 | // Buffer Case |
| 1176 | { |
| 1177 | m_errorMonitor->ExpectSuccess(); |
| 1178 | |
| 1179 | VkBuffer buffer; |
| 1180 | uint32_t queue_family_index = 0; |
| 1181 | VkBufferCreateInfo buffer_create_info = {}; |
| 1182 | buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1183 | buffer_create_info.size = 1024; |
| 1184 | buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 1185 | buffer_create_info.queueFamilyIndexCount = 1; |
| 1186 | buffer_create_info.pQueueFamilyIndices = &queue_family_index; |
| 1187 | |
| 1188 | VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, |
| 1189 | NULL, &buffer); |
| 1190 | ASSERT_VK_SUCCESS(err); |
| 1191 | |
| 1192 | VkMemoryRequirements memory_reqs; |
| 1193 | VkDeviceMemory buffer_memory; |
| 1194 | bool pass; |
| 1195 | VkMemoryAllocateInfo memory_info = {}; |
| 1196 | memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1197 | memory_info.pNext = NULL; |
| 1198 | memory_info.allocationSize = 0; |
| 1199 | memory_info.memoryTypeIndex = 0; |
| 1200 | |
| 1201 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs); |
| 1202 | memory_info.allocationSize = memory_reqs.size; |
| 1203 | pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, |
| 1204 | &memory_info, 0); |
| 1205 | ASSERT_TRUE(pass); |
| 1206 | |
| 1207 | err = vkAllocateMemory(m_device->device(), &memory_info, NULL, |
| 1208 | &buffer_memory); |
| 1209 | ASSERT_VK_SUCCESS(err); |
| 1210 | err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0); |
| 1211 | ASSERT_VK_SUCCESS(err); |
| 1212 | |
| 1213 | VkDescriptorPoolSize ds_type_count = {}; |
| 1214 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 1215 | ds_type_count.descriptorCount = 1; |
| 1216 | |
| 1217 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 1218 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 1219 | ds_pool_ci.pNext = NULL; |
| 1220 | ds_pool_ci.maxSets = 1; |
| 1221 | ds_pool_ci.poolSizeCount = 1; |
| 1222 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 1223 | |
| 1224 | VkDescriptorPool ds_pool; |
| 1225 | err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, |
| 1226 | &ds_pool); |
| 1227 | ASSERT_VK_SUCCESS(err); |
| 1228 | |
| 1229 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 1230 | dsl_binding.binding = 0; |
| 1231 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 1232 | dsl_binding.descriptorCount = 1; |
| 1233 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 1234 | dsl_binding.pImmutableSamplers = NULL; |
| 1235 | |
| 1236 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 1237 | ds_layout_ci.sType = |
| 1238 | VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 1239 | ds_layout_ci.pNext = NULL; |
| 1240 | ds_layout_ci.bindingCount = 1; |
| 1241 | ds_layout_ci.pBindings = &dsl_binding; |
| 1242 | VkDescriptorSetLayout ds_layout; |
| 1243 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, |
| 1244 | NULL, &ds_layout); |
| 1245 | ASSERT_VK_SUCCESS(err); |
| 1246 | |
| 1247 | VkDescriptorSet descriptor_set; |
| 1248 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 1249 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 1250 | alloc_info.descriptorSetCount = 1; |
| 1251 | alloc_info.descriptorPool = ds_pool; |
| 1252 | alloc_info.pSetLayouts = &ds_layout; |
| 1253 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 1254 | &descriptor_set); |
| 1255 | ASSERT_VK_SUCCESS(err); |
| 1256 | |
| 1257 | VkDescriptorBufferInfo buffer_info = {}; |
| 1258 | buffer_info.buffer = buffer; |
| 1259 | buffer_info.offset = 0; |
| 1260 | buffer_info.range = 1024; |
| 1261 | |
| 1262 | VkWriteDescriptorSet descriptor_write; |
| 1263 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 1264 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 1265 | descriptor_write.dstSet = descriptor_set; |
| 1266 | descriptor_write.dstBinding = 0; |
| 1267 | descriptor_write.descriptorCount = 1; |
| 1268 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 1269 | descriptor_write.pBufferInfo = &buffer_info; |
| 1270 | |
| 1271 | // Set pImageInfo and pTexelBufferView to invalid values, which should |
| 1272 | // be |
| 1273 | // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER. |
| 1274 | // This will most likely produce a crash if the parameter_validation |
| 1275 | // layer |
| 1276 | // does not correctly ignore pImageInfo. |
| 1277 | descriptor_write.pImageInfo = |
Dustin Graves | 5e2d8fc | 2016-07-07 16:18:49 -0600 | [diff] [blame] | 1278 | reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr); |
Dustin Graves | 40f3582 | 2016-06-23 11:12:53 -0600 | [diff] [blame] | 1279 | descriptor_write.pTexelBufferView = |
Dustin Graves | 5e2d8fc | 2016-07-07 16:18:49 -0600 | [diff] [blame] | 1280 | reinterpret_cast<const VkBufferView *>(invalid_ptr); |
Dustin Graves | 40f3582 | 2016-06-23 11:12:53 -0600 | [diff] [blame] | 1281 | |
| 1282 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, |
| 1283 | NULL); |
| 1284 | |
| 1285 | m_errorMonitor->VerifyNotFound(); |
| 1286 | |
| 1287 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set); |
| 1288 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 1289 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 1290 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1291 | vkFreeMemory(m_device->device(), buffer_memory, NULL); |
| 1292 | } |
| 1293 | |
| 1294 | // Texel Buffer Case |
| 1295 | { |
| 1296 | m_errorMonitor->ExpectSuccess(); |
| 1297 | |
| 1298 | VkBuffer buffer; |
| 1299 | uint32_t queue_family_index = 0; |
| 1300 | VkBufferCreateInfo buffer_create_info = {}; |
| 1301 | buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1302 | buffer_create_info.size = 1024; |
| 1303 | buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT; |
| 1304 | buffer_create_info.queueFamilyIndexCount = 1; |
| 1305 | buffer_create_info.pQueueFamilyIndices = &queue_family_index; |
| 1306 | |
| 1307 | VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, |
| 1308 | NULL, &buffer); |
| 1309 | ASSERT_VK_SUCCESS(err); |
| 1310 | |
| 1311 | VkMemoryRequirements memory_reqs; |
| 1312 | VkDeviceMemory buffer_memory; |
| 1313 | bool pass; |
| 1314 | VkMemoryAllocateInfo memory_info = {}; |
| 1315 | memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1316 | memory_info.pNext = NULL; |
| 1317 | memory_info.allocationSize = 0; |
| 1318 | memory_info.memoryTypeIndex = 0; |
| 1319 | |
| 1320 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs); |
| 1321 | memory_info.allocationSize = memory_reqs.size; |
| 1322 | pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, |
| 1323 | &memory_info, 0); |
| 1324 | ASSERT_TRUE(pass); |
| 1325 | |
| 1326 | err = vkAllocateMemory(m_device->device(), &memory_info, NULL, |
| 1327 | &buffer_memory); |
| 1328 | ASSERT_VK_SUCCESS(err); |
| 1329 | err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0); |
| 1330 | ASSERT_VK_SUCCESS(err); |
| 1331 | |
| 1332 | VkBufferViewCreateInfo buff_view_ci = {}; |
| 1333 | buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; |
| 1334 | buff_view_ci.buffer = buffer; |
| 1335 | buff_view_ci.format = VK_FORMAT_R8_UNORM; |
| 1336 | buff_view_ci.range = VK_WHOLE_SIZE; |
| 1337 | VkBufferView buffer_view; |
| 1338 | err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, |
| 1339 | &buffer_view); |
| 1340 | |
| 1341 | VkDescriptorPoolSize ds_type_count = {}; |
| 1342 | ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
| 1343 | ds_type_count.descriptorCount = 1; |
| 1344 | |
| 1345 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 1346 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 1347 | ds_pool_ci.pNext = NULL; |
| 1348 | ds_pool_ci.maxSets = 1; |
| 1349 | ds_pool_ci.poolSizeCount = 1; |
| 1350 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 1351 | |
| 1352 | VkDescriptorPool ds_pool; |
| 1353 | err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, |
| 1354 | &ds_pool); |
| 1355 | ASSERT_VK_SUCCESS(err); |
| 1356 | |
| 1357 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 1358 | dsl_binding.binding = 0; |
| 1359 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
| 1360 | dsl_binding.descriptorCount = 1; |
| 1361 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 1362 | dsl_binding.pImmutableSamplers = NULL; |
| 1363 | |
| 1364 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 1365 | ds_layout_ci.sType = |
| 1366 | VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 1367 | ds_layout_ci.pNext = NULL; |
| 1368 | ds_layout_ci.bindingCount = 1; |
| 1369 | ds_layout_ci.pBindings = &dsl_binding; |
| 1370 | VkDescriptorSetLayout ds_layout; |
| 1371 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, |
| 1372 | NULL, &ds_layout); |
| 1373 | ASSERT_VK_SUCCESS(err); |
| 1374 | |
| 1375 | VkDescriptorSet descriptor_set; |
| 1376 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 1377 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 1378 | alloc_info.descriptorSetCount = 1; |
| 1379 | alloc_info.descriptorPool = ds_pool; |
| 1380 | alloc_info.pSetLayouts = &ds_layout; |
| 1381 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 1382 | &descriptor_set); |
| 1383 | ASSERT_VK_SUCCESS(err); |
| 1384 | |
| 1385 | VkWriteDescriptorSet descriptor_write; |
| 1386 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 1387 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 1388 | descriptor_write.dstSet = descriptor_set; |
| 1389 | descriptor_write.dstBinding = 0; |
| 1390 | descriptor_write.descriptorCount = 1; |
| 1391 | descriptor_write.descriptorType = |
| 1392 | VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
| 1393 | descriptor_write.pTexelBufferView = &buffer_view; |
| 1394 | |
| 1395 | // Set pImageInfo and pBufferInfo to invalid values, which should be |
| 1396 | // ignored for descriptorType == |
| 1397 | // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER. |
| 1398 | // This will most likely produce a crash if the parameter_validation |
| 1399 | // layer |
| 1400 | // does not correctly ignore pImageInfo and pBufferInfo. |
| 1401 | descriptor_write.pImageInfo = |
Dustin Graves | 5e2d8fc | 2016-07-07 16:18:49 -0600 | [diff] [blame] | 1402 | reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr); |
Dustin Graves | 40f3582 | 2016-06-23 11:12:53 -0600 | [diff] [blame] | 1403 | descriptor_write.pBufferInfo = |
Dustin Graves | 5e2d8fc | 2016-07-07 16:18:49 -0600 | [diff] [blame] | 1404 | reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr); |
Dustin Graves | 40f3582 | 2016-06-23 11:12:53 -0600 | [diff] [blame] | 1405 | |
| 1406 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, |
| 1407 | NULL); |
| 1408 | |
| 1409 | m_errorMonitor->VerifyNotFound(); |
| 1410 | |
| 1411 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set); |
| 1412 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 1413 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 1414 | vkDestroyBufferView(m_device->device(), buffer_view, NULL); |
| 1415 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1416 | vkFreeMemory(m_device->device(), buffer_memory, NULL); |
| 1417 | } |
| 1418 | } |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 1419 | #endif // PARAMETER_VALIDATION_TESTS |
| 1420 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 1421 | #if MEM_TRACKER_TESTS |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 1422 | #if 0 |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1423 | TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion) |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1424 | { |
| 1425 | vk_testing::Fence testFence; |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1426 | VkFenceCreateInfo fenceInfo = {}; |
| 1427 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 1428 | fenceInfo.pNext = NULL; |
| 1429 | fenceInfo.flags = 0; |
| 1430 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1431 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 1432 | |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1433 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tony Barbour | c1eb1a5 | 2015-07-20 13:00:10 -0600 | [diff] [blame] | 1434 | |
| 1435 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 1436 | vk_testing::Buffer buffer; |
| 1437 | buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1438 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1439 | BeginCommandBuffer(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1440 | m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1441 | EndCommandBuffer(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1442 | |
| 1443 | testFence.init(*m_device, fenceInfo); |
| 1444 | |
| 1445 | // Bypass framework since it does the waits automatically |
| 1446 | VkResult err = VK_SUCCESS; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1447 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 1448 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 1449 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1450 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1451 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 1452 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1453 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1454 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1455 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1456 | submit_info.pSignalSemaphores = NULL; |
Courtney Goeltzenleuchter | 646b907 | 2015-10-20 18:04:07 -0600 | [diff] [blame] | 1457 | |
| 1458 | err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle()); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1459 | ASSERT_VK_SUCCESS( err ); |
| 1460 | |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1461 | // Introduce failure by calling begin again before checking fence |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1462 | vkResetCommandBuffer(m_commandBuffer->handle(), 0); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1463 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 1464 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1465 | } |
| 1466 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1467 | TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion) |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1468 | { |
| 1469 | vk_testing::Fence testFence; |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1470 | VkFenceCreateInfo fenceInfo = {}; |
| 1471 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 1472 | fenceInfo.pNext = NULL; |
| 1473 | fenceInfo.flags = 0; |
| 1474 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1475 | 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] | 1476 | |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1477 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1478 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1479 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 1480 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1481 | BeginCommandBuffer(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1482 | 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] | 1483 | EndCommandBuffer(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1484 | |
| 1485 | testFence.init(*m_device, fenceInfo); |
| 1486 | |
| 1487 | // Bypass framework since it does the waits automatically |
| 1488 | VkResult err = VK_SUCCESS; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1489 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 1490 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 1491 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1492 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1493 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 1494 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1495 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1496 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1497 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1498 | submit_info.pSignalSemaphores = NULL; |
Courtney Goeltzenleuchter | 646b907 | 2015-10-20 18:04:07 -0600 | [diff] [blame] | 1499 | |
| 1500 | err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle()); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1501 | ASSERT_VK_SUCCESS( err ); |
| 1502 | |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 1503 | VkCommandBufferInheritanceInfo hinfo = {}; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1504 | VkCommandBufferBeginInfo info = {}; |
| 1505 | info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
| 1506 | info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 1507 | info.renderPass = VK_NULL_HANDLE; |
| 1508 | info.subpass = 0; |
| 1509 | info.framebuffer = VK_NULL_HANDLE; |
Chia-I Wu | b8d47ae | 2015-11-11 10:18:12 +0800 | [diff] [blame] | 1510 | info.occlusionQueryEnable = VK_FALSE; |
| 1511 | info.queryFlags = 0; |
| 1512 | info.pipelineStatistics = 0; |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 1513 | |
| 1514 | // Introduce failure by calling BCB again before checking fence |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1515 | vkBeginCommandBuffer(m_commandBuffer->handle(), &info); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1516 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 1517 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1518 | } |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 1519 | #endif |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 1520 | |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1521 | // This is a positive test. No failures are expected. |
| 1522 | TEST_F(VkLayerTest, TestAliasedMemoryTracking) { |
| 1523 | VkResult err; |
| 1524 | bool pass; |
| 1525 | |
| 1526 | TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy " |
| 1527 | "the buffer, create an image, and bind the same memory to " |
| 1528 | "it"); |
| 1529 | |
| 1530 | m_errorMonitor->ExpectSuccess(); |
| 1531 | |
| 1532 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1533 | |
| 1534 | VkBuffer buffer; |
| 1535 | VkImage image; |
| 1536 | VkDeviceMemory mem; |
| 1537 | VkMemoryRequirements mem_reqs; |
| 1538 | |
| 1539 | VkBufferCreateInfo buf_info = {}; |
| 1540 | buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1541 | buf_info.pNext = NULL; |
| 1542 | buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 1543 | buf_info.size = 256; |
| 1544 | buf_info.queueFamilyIndexCount = 0; |
| 1545 | buf_info.pQueueFamilyIndices = NULL; |
| 1546 | buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1547 | buf_info.flags = 0; |
| 1548 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer); |
| 1549 | ASSERT_VK_SUCCESS(err); |
| 1550 | |
| 1551 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs); |
| 1552 | |
| 1553 | VkMemoryAllocateInfo alloc_info = {}; |
| 1554 | alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1555 | alloc_info.pNext = NULL; |
| 1556 | alloc_info.memoryTypeIndex = 0; |
| 1557 | |
| 1558 | // Ensure memory is big enough for both bindings |
| 1559 | alloc_info.allocationSize = 0x10000; |
| 1560 | |
| 1561 | pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, |
| 1562 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 1563 | if (!pass) { |
| 1564 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1565 | return; |
| 1566 | } |
| 1567 | |
| 1568 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem); |
| 1569 | ASSERT_VK_SUCCESS(err); |
| 1570 | |
| 1571 | uint8_t *pData; |
| 1572 | err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, |
| 1573 | (void **)&pData); |
| 1574 | ASSERT_VK_SUCCESS(err); |
| 1575 | |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 1576 | memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size)); |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1577 | |
| 1578 | vkUnmapMemory(m_device->device(), mem); |
| 1579 | |
| 1580 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 1581 | ASSERT_VK_SUCCESS(err); |
| 1582 | |
| 1583 | // NOW, destroy the buffer. Obviously, the resource no longer occupies this |
| 1584 | // memory. In fact, it was never used by the GPU. |
| 1585 | // Just be be sure, wait for idle. |
| 1586 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1587 | vkDeviceWaitIdle(m_device->device()); |
| 1588 | |
| 1589 | VkImageCreateInfo image_create_info = {}; |
| 1590 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 1591 | image_create_info.pNext = NULL; |
| 1592 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 1593 | image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 1594 | image_create_info.extent.width = 64; |
| 1595 | image_create_info.extent.height = 64; |
| 1596 | image_create_info.extent.depth = 1; |
| 1597 | image_create_info.mipLevels = 1; |
| 1598 | image_create_info.arrayLayers = 1; |
| 1599 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 1600 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 1601 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 1602 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 1603 | image_create_info.queueFamilyIndexCount = 0; |
| 1604 | image_create_info.pQueueFamilyIndices = NULL; |
| 1605 | image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1606 | image_create_info.flags = 0; |
| 1607 | |
| 1608 | VkMemoryAllocateInfo mem_alloc = {}; |
| 1609 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1610 | mem_alloc.pNext = NULL; |
| 1611 | mem_alloc.allocationSize = 0; |
| 1612 | mem_alloc.memoryTypeIndex = 0; |
| 1613 | |
| 1614 | /* Create a mappable image. It will be the texture if linear images are ok |
| 1615 | * to be textures or it will be the staging image if they are not. |
| 1616 | */ |
| 1617 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 1618 | ASSERT_VK_SUCCESS(err); |
| 1619 | |
| 1620 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 1621 | |
| 1622 | mem_alloc.allocationSize = mem_reqs.size; |
| 1623 | |
| 1624 | pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, |
| 1625 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 1626 | if (!pass) { |
| 1627 | vkDestroyImage(m_device->device(), image, NULL); |
| 1628 | return; |
| 1629 | } |
| 1630 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1631 | // VALIDATION FAILURE: |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1632 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 1633 | ASSERT_VK_SUCCESS(err); |
| 1634 | |
| 1635 | m_errorMonitor->VerifyNotFound(); |
| 1636 | |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 1637 | vkFreeMemory(m_device->device(), mem, NULL); |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1638 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1639 | vkDestroyImage(m_device->device(), image, NULL); |
| 1640 | } |
| 1641 | |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1642 | TEST_F(VkLayerTest, InvalidMemoryAliasing) { |
| 1643 | TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the " |
| 1644 | "buffer and image to memory such that they will alias."); |
| 1645 | VkResult err; |
| 1646 | bool pass; |
| 1647 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1648 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1649 | VkBuffer buffer, buffer2; |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1650 | VkImage image; |
| 1651 | VkDeviceMemory mem; // buffer will be bound first |
| 1652 | VkDeviceMemory mem_img; // image bound first |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1653 | VkMemoryRequirements buff_mem_reqs, img_mem_reqs; |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1654 | |
| 1655 | VkBufferCreateInfo buf_info = {}; |
| 1656 | buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1657 | buf_info.pNext = NULL; |
| 1658 | buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 1659 | buf_info.size = 256; |
| 1660 | buf_info.queueFamilyIndexCount = 0; |
| 1661 | buf_info.pQueueFamilyIndices = NULL; |
| 1662 | buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1663 | buf_info.flags = 0; |
| 1664 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer); |
| 1665 | ASSERT_VK_SUCCESS(err); |
| 1666 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1667 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1668 | |
| 1669 | VkImageCreateInfo image_create_info = {}; |
| 1670 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 1671 | image_create_info.pNext = NULL; |
| 1672 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 1673 | image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 1674 | image_create_info.extent.width = 64; |
| 1675 | image_create_info.extent.height = 64; |
| 1676 | image_create_info.extent.depth = 1; |
| 1677 | image_create_info.mipLevels = 1; |
| 1678 | image_create_info.arrayLayers = 1; |
| 1679 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 1680 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 1681 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 1682 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 1683 | image_create_info.queueFamilyIndexCount = 0; |
| 1684 | image_create_info.pQueueFamilyIndices = NULL; |
| 1685 | image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1686 | image_create_info.flags = 0; |
| 1687 | |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1688 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 1689 | ASSERT_VK_SUCCESS(err); |
| 1690 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1691 | vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs); |
| 1692 | |
| 1693 | VkMemoryAllocateInfo alloc_info = {}; |
| 1694 | alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1695 | alloc_info.pNext = NULL; |
| 1696 | alloc_info.memoryTypeIndex = 0; |
| 1697 | // Ensure memory is big enough for both bindings |
| 1698 | alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size; |
| 1699 | pass = m_device->phy().set_memory_type( |
| 1700 | buff_mem_reqs.memoryTypeBits | img_mem_reqs.memoryTypeBits, &alloc_info, |
| 1701 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1702 | if (!pass) { |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1703 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1704 | vkDestroyImage(m_device->device(), image, NULL); |
| 1705 | return; |
| 1706 | } |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1707 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem); |
| 1708 | ASSERT_VK_SUCCESS(err); |
| 1709 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 1710 | ASSERT_VK_SUCCESS(err); |
| 1711 | |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1712 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1713 | " is aliased with buffer 0x"); |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1714 | // VALIDATION FAILURE due to image mapping overlapping buffer mapping |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1715 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 1716 | m_errorMonitor->VerifyFound(); |
| 1717 | |
| 1718 | // Now correctly bind image to second mem allocation before incorrectly |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1719 | // aliasing buffer2 |
| 1720 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2); |
| 1721 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1722 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img); |
| 1723 | ASSERT_VK_SUCCESS(err); |
| 1724 | err = vkBindImageMemory(m_device->device(), image, mem_img, 0); |
| 1725 | ASSERT_VK_SUCCESS(err); |
| 1726 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1727 | " is aliased with image 0x"); |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1728 | err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1729 | m_errorMonitor->VerifyFound(); |
| 1730 | |
| 1731 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1732 | vkDestroyBuffer(m_device->device(), buffer2, NULL); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1733 | vkDestroyImage(m_device->device(), image, NULL); |
| 1734 | vkFreeMemory(m_device->device(), mem, NULL); |
| 1735 | vkFreeMemory(m_device->device(), mem_img, NULL); |
| 1736 | } |
| 1737 | |
Tobin Ehlis | 3537252 | 2016-05-12 08:32:31 -0600 | [diff] [blame] | 1738 | TEST_F(VkLayerTest, InvalidMemoryMapping) { |
| 1739 | TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways"); |
| 1740 | VkResult err; |
| 1741 | bool pass; |
| 1742 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1743 | |
| 1744 | VkBuffer buffer; |
| 1745 | VkDeviceMemory mem; |
| 1746 | VkMemoryRequirements mem_reqs; |
| 1747 | |
| 1748 | VkBufferCreateInfo buf_info = {}; |
| 1749 | buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1750 | buf_info.pNext = NULL; |
| 1751 | buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 1752 | buf_info.size = 256; |
| 1753 | buf_info.queueFamilyIndexCount = 0; |
| 1754 | buf_info.pQueueFamilyIndices = NULL; |
| 1755 | buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1756 | buf_info.flags = 0; |
| 1757 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer); |
| 1758 | ASSERT_VK_SUCCESS(err); |
| 1759 | |
| 1760 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs); |
| 1761 | VkMemoryAllocateInfo alloc_info = {}; |
| 1762 | alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1763 | alloc_info.pNext = NULL; |
| 1764 | alloc_info.memoryTypeIndex = 0; |
| 1765 | |
| 1766 | // Ensure memory is big enough for both bindings |
| 1767 | static const VkDeviceSize allocation_size = 0x10000; |
| 1768 | alloc_info.allocationSize = allocation_size; |
| 1769 | pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, |
| 1770 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 1771 | if (!pass) { |
| 1772 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1773 | return; |
| 1774 | } |
| 1775 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem); |
| 1776 | ASSERT_VK_SUCCESS(err); |
| 1777 | |
| 1778 | uint8_t *pData; |
| 1779 | // Attempt to map memory size 0 is invalid |
| 1780 | m_errorMonitor->SetDesiredFailureMsg( |
| 1781 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1782 | "VkMapMemory: Attempting to map memory range of size zero"); |
| 1783 | err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData); |
| 1784 | m_errorMonitor->VerifyFound(); |
| 1785 | // Map memory twice |
| 1786 | err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, |
| 1787 | (void **)&pData); |
| 1788 | ASSERT_VK_SUCCESS(err); |
| 1789 | m_errorMonitor->SetDesiredFailureMsg( |
| 1790 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1791 | "VkMapMemory: Attempting to map memory on an already-mapped object "); |
| 1792 | err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, |
| 1793 | (void **)&pData); |
| 1794 | m_errorMonitor->VerifyFound(); |
| 1795 | |
| 1796 | // Unmap the memory to avoid re-map error |
| 1797 | vkUnmapMemory(m_device->device(), mem); |
| 1798 | // overstep allocation with VK_WHOLE_SIZE |
| 1799 | m_errorMonitor->SetDesiredFailureMsg( |
| 1800 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1801 | " with size of VK_WHOLE_SIZE oversteps total array size 0x"); |
| 1802 | err = vkMapMemory(m_device->device(), mem, allocation_size + 1, |
| 1803 | VK_WHOLE_SIZE, 0, (void **)&pData); |
| 1804 | m_errorMonitor->VerifyFound(); |
| 1805 | // overstep allocation w/o VK_WHOLE_SIZE |
| 1806 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1807 | " oversteps total array size 0x"); |
| 1808 | err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, |
| 1809 | (void **)&pData); |
| 1810 | m_errorMonitor->VerifyFound(); |
| 1811 | // Now error due to unmapping memory that's not mapped |
| 1812 | m_errorMonitor->SetDesiredFailureMsg( |
| 1813 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1814 | "Unmapping Memory without memory being mapped: "); |
| 1815 | vkUnmapMemory(m_device->device(), mem); |
| 1816 | m_errorMonitor->VerifyFound(); |
| 1817 | // Now map memory and cause errors due to flushing invalid ranges |
| 1818 | err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0, |
| 1819 | (void **)&pData); |
| 1820 | ASSERT_VK_SUCCESS(err); |
| 1821 | VkMappedMemoryRange mmr = {}; |
Chris Forbes | 3aec089 | 2016-06-13 10:29:26 +1200 | [diff] [blame] | 1822 | mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; |
Tobin Ehlis | 3537252 | 2016-05-12 08:32:31 -0600 | [diff] [blame] | 1823 | mmr.memory = mem; |
| 1824 | mmr.offset = 15; // Error b/c offset less than offset of mapped mem |
| 1825 | m_errorMonitor->SetDesiredFailureMsg( |
| 1826 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1827 | ") is less than Memory Object's offset ("); |
| 1828 | vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr); |
| 1829 | m_errorMonitor->VerifyFound(); |
| 1830 | // Now flush range that oversteps mapped range |
| 1831 | vkUnmapMemory(m_device->device(), mem); |
| 1832 | err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData); |
| 1833 | ASSERT_VK_SUCCESS(err); |
| 1834 | mmr.offset = 16; |
| 1835 | mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256) |
| 1836 | m_errorMonitor->SetDesiredFailureMsg( |
| 1837 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1838 | ") exceeds the Memory Object's upper-bound ("); |
| 1839 | vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr); |
| 1840 | m_errorMonitor->VerifyFound(); |
| 1841 | |
| 1842 | pass = |
| 1843 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, |
| 1844 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, |
| 1845 | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); |
| 1846 | if (!pass) { |
| 1847 | vkFreeMemory(m_device->device(), mem, NULL); |
| 1848 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1849 | return; |
| 1850 | } |
| 1851 | // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of |
| 1852 | // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver() |
| 1853 | |
| 1854 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1855 | vkFreeMemory(m_device->device(), mem, NULL); |
| 1856 | } |
| 1857 | |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1858 | TEST_F(VkLayerTest, EnableWsiBeforeUse) { |
| 1859 | VkResult err; |
| 1860 | bool pass; |
| 1861 | |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1862 | // FIXME: After we turn on this code for non-Linux platforms, uncomment the |
| 1863 | // following declaration (which is temporarily being moved below): |
| 1864 | // VkSurfaceKHR surface = VK_NULL_HANDLE; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1865 | VkSwapchainKHR swapchain = VK_NULL_HANDLE; |
| 1866 | VkSwapchainCreateInfoKHR swapchain_create_info = {}; |
| 1867 | uint32_t swapchain_image_count = 0; |
| 1868 | // VkImage swapchain_images[1] = {VK_NULL_HANDLE}; |
| 1869 | uint32_t image_index = 0; |
| 1870 | // VkPresentInfoKHR present_info = {}; |
| 1871 | |
| 1872 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1873 | |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1874 | #ifdef NEED_TO_TEST_THIS_ON_PLATFORM |
| 1875 | #if defined(VK_USE_PLATFORM_ANDROID_KHR) |
| 1876 | // Use the functions from the VK_KHR_android_surface extension without |
| 1877 | // enabling that extension: |
| 1878 | |
| 1879 | // Create a surface: |
| 1880 | VkAndroidSurfaceCreateInfoKHR android_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1881 | m_errorMonitor->SetDesiredFailureMsg( |
| 1882 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1883 | "extension was not enabled for this"); |
| 1884 | err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, |
| 1885 | &surface); |
| 1886 | pass = (err != VK_SUCCESS); |
| 1887 | ASSERT_TRUE(pass); |
| 1888 | m_errorMonitor->VerifyFound(); |
| 1889 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 1890 | |
| 1891 | |
| 1892 | #if defined(VK_USE_PLATFORM_MIR_KHR) |
| 1893 | // Use the functions from the VK_KHR_mir_surface extension without enabling |
| 1894 | // that extension: |
| 1895 | |
| 1896 | // Create a surface: |
| 1897 | VkMirSurfaceCreateInfoKHR mir_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1898 | m_errorMonitor->SetDesiredFailureMsg( |
| 1899 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1900 | "extension was not enabled for this"); |
| 1901 | err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface); |
| 1902 | pass = (err != VK_SUCCESS); |
| 1903 | ASSERT_TRUE(pass); |
| 1904 | m_errorMonitor->VerifyFound(); |
| 1905 | |
| 1906 | // Tell whether an mir_connection supports presentation: |
| 1907 | MirConnection *mir_connection = NULL; |
| 1908 | m_errorMonitor->SetDesiredFailureMsg( |
| 1909 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1910 | "extension was not enabled for this"); |
| 1911 | vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, |
| 1912 | visual_id); |
| 1913 | m_errorMonitor->VerifyFound(); |
| 1914 | #endif // VK_USE_PLATFORM_MIR_KHR |
| 1915 | |
| 1916 | |
| 1917 | #if defined(VK_USE_PLATFORM_WAYLAND_KHR) |
| 1918 | // Use the functions from the VK_KHR_wayland_surface extension without |
| 1919 | // enabling that extension: |
| 1920 | |
| 1921 | // Create a surface: |
| 1922 | VkWaylandSurfaceCreateInfoKHR wayland_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1923 | m_errorMonitor->SetDesiredFailureMsg( |
| 1924 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1925 | "extension was not enabled for this"); |
| 1926 | err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, |
| 1927 | &surface); |
| 1928 | pass = (err != VK_SUCCESS); |
| 1929 | ASSERT_TRUE(pass); |
| 1930 | m_errorMonitor->VerifyFound(); |
| 1931 | |
| 1932 | // Tell whether an wayland_display supports presentation: |
| 1933 | struct wl_display wayland_display = {}; |
| 1934 | m_errorMonitor->SetDesiredFailureMsg( |
| 1935 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1936 | "extension was not enabled for this"); |
| 1937 | vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, |
| 1938 | &wayland_display); |
| 1939 | m_errorMonitor->VerifyFound(); |
| 1940 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1941 | #endif // NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1942 | |
| 1943 | |
| 1944 | #if defined(VK_USE_PLATFORM_WIN32_KHR) |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1945 | // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED |
| 1946 | // TO NON-LINUX PLATFORMS: |
| 1947 | VkSurfaceKHR surface = VK_NULL_HANDLE; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1948 | // Use the functions from the VK_KHR_win32_surface extension without |
| 1949 | // enabling that extension: |
| 1950 | |
| 1951 | // Create a surface: |
| 1952 | VkWin32SurfaceCreateInfoKHR win32_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1953 | m_errorMonitor->SetDesiredFailureMsg( |
| 1954 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1955 | "extension was not enabled for this"); |
| 1956 | err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, |
| 1957 | &surface); |
| 1958 | pass = (err != VK_SUCCESS); |
| 1959 | ASSERT_TRUE(pass); |
| 1960 | m_errorMonitor->VerifyFound(); |
| 1961 | |
| 1962 | // Tell whether win32 supports presentation: |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1963 | m_errorMonitor->SetDesiredFailureMsg( |
| 1964 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1965 | "extension was not enabled for this"); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1966 | vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0); |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1967 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1968 | // Set this (for now, until all platforms are supported and tested): |
| 1969 | #define NEED_TO_TEST_THIS_ON_PLATFORM |
| 1970 | #endif // VK_USE_PLATFORM_WIN32_KHR |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1971 | |
| 1972 | |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1973 | #if defined(VK_USE_PLATFORM_XCB_KHR) |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1974 | // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED |
| 1975 | // TO NON-LINUX PLATFORMS: |
| 1976 | VkSurfaceKHR surface = VK_NULL_HANDLE; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1977 | // Use the functions from the VK_KHR_xcb_surface extension without enabling |
| 1978 | // that extension: |
| 1979 | |
| 1980 | // Create a surface: |
| 1981 | VkXcbSurfaceCreateInfoKHR xcb_create_info = {}; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1982 | m_errorMonitor->SetDesiredFailureMsg( |
| 1983 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1984 | "extension was not enabled for this"); |
| 1985 | err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface); |
| 1986 | pass = (err != VK_SUCCESS); |
| 1987 | ASSERT_TRUE(pass); |
| 1988 | m_errorMonitor->VerifyFound(); |
| 1989 | |
| 1990 | // Tell whether an xcb_visualid_t supports presentation: |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1991 | xcb_connection_t *xcb_connection = NULL; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1992 | xcb_visualid_t visual_id = 0; |
| 1993 | m_errorMonitor->SetDesiredFailureMsg( |
| 1994 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1995 | "extension was not enabled for this"); |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1996 | vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1997 | visual_id); |
| 1998 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1999 | // Set this (for now, until all platforms are supported and tested): |
| 2000 | #define NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 2001 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 2002 | |
| 2003 | |
Ian Elliott | 1263081 | 2016-04-29 14:35:43 -0600 | [diff] [blame] | 2004 | #if defined(VK_USE_PLATFORM_XLIB_KHR) |
| 2005 | // Use the functions from the VK_KHR_xlib_surface extension without enabling |
| 2006 | // that extension: |
| 2007 | |
| 2008 | // Create a surface: |
| 2009 | VkXlibSurfaceCreateInfoKHR xlib_create_info = {}; |
Ian Elliott | 1263081 | 2016-04-29 14:35:43 -0600 | [diff] [blame] | 2010 | m_errorMonitor->SetDesiredFailureMsg( |
| 2011 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2012 | "extension was not enabled for this"); |
| 2013 | err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface); |
| 2014 | pass = (err != VK_SUCCESS); |
| 2015 | ASSERT_TRUE(pass); |
| 2016 | m_errorMonitor->VerifyFound(); |
| 2017 | |
| 2018 | // Tell whether an Xlib VisualID supports presentation: |
| 2019 | Display *dpy = NULL; |
| 2020 | VisualID visual = 0; |
| 2021 | m_errorMonitor->SetDesiredFailureMsg( |
| 2022 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2023 | "extension was not enabled for this"); |
| 2024 | vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual); |
| 2025 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 2026 | // Set this (for now, until all platforms are supported and tested): |
| 2027 | #define NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1263081 | 2016-04-29 14:35:43 -0600 | [diff] [blame] | 2028 | #endif // VK_USE_PLATFORM_XLIB_KHR |
| 2029 | |
| 2030 | |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 2031 | // Use the functions from the VK_KHR_surface extension without enabling |
| 2032 | // that extension: |
| 2033 | |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 2034 | #ifdef NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 2035 | // Destroy a surface: |
| 2036 | m_errorMonitor->SetDesiredFailureMsg( |
| 2037 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2038 | "extension was not enabled for this"); |
| 2039 | vkDestroySurfaceKHR(instance(), surface, NULL); |
| 2040 | m_errorMonitor->VerifyFound(); |
| 2041 | |
| 2042 | // Check if surface supports presentation: |
| 2043 | VkBool32 supported = false; |
| 2044 | m_errorMonitor->SetDesiredFailureMsg( |
| 2045 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2046 | "extension was not enabled for this"); |
| 2047 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported); |
| 2048 | pass = (err != VK_SUCCESS); |
| 2049 | ASSERT_TRUE(pass); |
| 2050 | m_errorMonitor->VerifyFound(); |
| 2051 | |
| 2052 | // Check surface capabilities: |
| 2053 | VkSurfaceCapabilitiesKHR capabilities = {}; |
| 2054 | m_errorMonitor->SetDesiredFailureMsg( |
| 2055 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2056 | "extension was not enabled for this"); |
| 2057 | err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, |
| 2058 | &capabilities); |
| 2059 | pass = (err != VK_SUCCESS); |
| 2060 | ASSERT_TRUE(pass); |
| 2061 | m_errorMonitor->VerifyFound(); |
| 2062 | |
| 2063 | // Check surface formats: |
| 2064 | uint32_t format_count = 0; |
| 2065 | VkSurfaceFormatKHR *formats = NULL; |
| 2066 | m_errorMonitor->SetDesiredFailureMsg( |
| 2067 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2068 | "extension was not enabled for this"); |
| 2069 | err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, |
| 2070 | &format_count, formats); |
| 2071 | pass = (err != VK_SUCCESS); |
| 2072 | ASSERT_TRUE(pass); |
| 2073 | m_errorMonitor->VerifyFound(); |
| 2074 | |
| 2075 | // Check surface present modes: |
| 2076 | uint32_t present_mode_count = 0; |
| 2077 | VkSurfaceFormatKHR *present_modes = NULL; |
| 2078 | m_errorMonitor->SetDesiredFailureMsg( |
| 2079 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2080 | "extension was not enabled for this"); |
| 2081 | err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, |
| 2082 | &present_mode_count, present_modes); |
| 2083 | pass = (err != VK_SUCCESS); |
| 2084 | ASSERT_TRUE(pass); |
| 2085 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 2086 | #endif // NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 2087 | |
| 2088 | |
| 2089 | // Use the functions from the VK_KHR_swapchain extension without enabling |
| 2090 | // that extension: |
| 2091 | |
| 2092 | // Create a swapchain: |
| 2093 | m_errorMonitor->SetDesiredFailureMsg( |
| 2094 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2095 | "extension was not enabled for this"); |
| 2096 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 2097 | swapchain_create_info.pNext = NULL; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 2098 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, |
| 2099 | NULL, &swapchain); |
| 2100 | pass = (err != VK_SUCCESS); |
| 2101 | ASSERT_TRUE(pass); |
| 2102 | m_errorMonitor->VerifyFound(); |
| 2103 | |
| 2104 | // Get the images from the swapchain: |
| 2105 | m_errorMonitor->SetDesiredFailureMsg( |
| 2106 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2107 | "extension was not enabled for this"); |
| 2108 | err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, |
| 2109 | &swapchain_image_count, NULL); |
| 2110 | pass = (err != VK_SUCCESS); |
| 2111 | ASSERT_TRUE(pass); |
| 2112 | m_errorMonitor->VerifyFound(); |
| 2113 | |
| 2114 | // Try to acquire an image: |
| 2115 | m_errorMonitor->SetDesiredFailureMsg( |
| 2116 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2117 | "extension was not enabled for this"); |
| 2118 | err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, |
| 2119 | VK_NULL_HANDLE, VK_NULL_HANDLE, &image_index); |
| 2120 | pass = (err != VK_SUCCESS); |
| 2121 | ASSERT_TRUE(pass); |
| 2122 | m_errorMonitor->VerifyFound(); |
| 2123 | |
| 2124 | // Try to present an image: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2125 | // |
| 2126 | // NOTE: Currently can't test this because a real swapchain is needed (as |
| 2127 | // opposed to the fake one we created) in order for the layer to lookup the |
| 2128 | // VkDevice used to enable the extension: |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 2129 | |
| 2130 | // Destroy the swapchain: |
| 2131 | m_errorMonitor->SetDesiredFailureMsg( |
| 2132 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2133 | "extension was not enabled for this"); |
| 2134 | vkDestroySwapchainKHR(m_device->device(), swapchain, NULL); |
| 2135 | m_errorMonitor->VerifyFound(); |
| 2136 | } |
| 2137 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2138 | TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) { |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2139 | |
Dustin Graves | 6c6d898 | 2016-05-17 10:09:21 -0600 | [diff] [blame] | 2140 | #if defined(VK_USE_PLATFORM_XCB_KHR) |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2141 | VkSurfaceKHR surface = VK_NULL_HANDLE; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2142 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2143 | VkResult err; |
| 2144 | bool pass; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2145 | VkSwapchainKHR swapchain = VK_NULL_HANDLE; |
| 2146 | VkSwapchainCreateInfoKHR swapchain_create_info = {}; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2147 | // uint32_t swapchain_image_count = 0; |
| 2148 | // VkImage swapchain_images[1] = {VK_NULL_HANDLE}; |
| 2149 | // uint32_t image_index = 0; |
| 2150 | // VkPresentInfoKHR present_info = {}; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2151 | |
| 2152 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2153 | |
| 2154 | // Use the create function from one of the VK_KHR_*_surface extension in |
| 2155 | // order to create a surface, testing all known errors in the process, |
| 2156 | // before successfully creating a surface: |
| 2157 | // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2158 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2159 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2160 | err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface); |
| 2161 | pass = (err != VK_SUCCESS); |
| 2162 | ASSERT_TRUE(pass); |
| 2163 | m_errorMonitor->VerifyFound(); |
| 2164 | |
| 2165 | // Next, try to create a surface with the wrong |
| 2166 | // VkXcbSurfaceCreateInfoKHR::sType: |
| 2167 | VkXcbSurfaceCreateInfoKHR xcb_create_info = {}; |
| 2168 | xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2169 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2170 | "called with the wrong value for"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2171 | err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface); |
| 2172 | pass = (err != VK_SUCCESS); |
| 2173 | ASSERT_TRUE(pass); |
| 2174 | m_errorMonitor->VerifyFound(); |
| 2175 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2176 | // Create a native window, and then correctly create a surface: |
| 2177 | xcb_connection_t *connection; |
| 2178 | xcb_screen_t *screen; |
| 2179 | xcb_window_t xcb_window; |
| 2180 | xcb_intern_atom_reply_t *atom_wm_delete_window; |
| 2181 | |
| 2182 | const xcb_setup_t *setup; |
| 2183 | xcb_screen_iterator_t iter; |
| 2184 | int scr; |
| 2185 | uint32_t value_mask, value_list[32]; |
| 2186 | int width = 1; |
| 2187 | int height = 1; |
| 2188 | |
| 2189 | connection = xcb_connect(NULL, &scr); |
| 2190 | ASSERT_TRUE(connection != NULL); |
| 2191 | setup = xcb_get_setup(connection); |
| 2192 | iter = xcb_setup_roots_iterator(setup); |
| 2193 | while (scr-- > 0) |
| 2194 | xcb_screen_next(&iter); |
| 2195 | screen = iter.data; |
| 2196 | |
| 2197 | xcb_window = xcb_generate_id(connection); |
| 2198 | |
| 2199 | value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; |
| 2200 | value_list[0] = screen->black_pixel; |
| 2201 | value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | |
| 2202 | XCB_EVENT_MASK_STRUCTURE_NOTIFY; |
| 2203 | |
| 2204 | xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, |
| 2205 | screen->root, 0, 0, width, height, 0, |
| 2206 | XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, |
| 2207 | value_mask, value_list); |
| 2208 | |
| 2209 | /* Magic code that will send notification when window is destroyed */ |
| 2210 | xcb_intern_atom_cookie_t cookie = |
| 2211 | xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS"); |
| 2212 | xcb_intern_atom_reply_t *reply = |
| 2213 | xcb_intern_atom_reply(connection, cookie, 0); |
| 2214 | |
| 2215 | xcb_intern_atom_cookie_t cookie2 = |
| 2216 | xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW"); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2217 | atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2218 | xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, |
| 2219 | (*reply).atom, 4, 32, 1, |
| 2220 | &(*atom_wm_delete_window).atom); |
| 2221 | free(reply); |
| 2222 | |
| 2223 | xcb_map_window(connection, xcb_window); |
| 2224 | |
| 2225 | // Force the x/y coordinates to 100,100 results are identical in consecutive |
| 2226 | // runs |
| 2227 | const uint32_t coords[] = {100, 100}; |
| 2228 | xcb_configure_window(connection, xcb_window, |
| 2229 | XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords); |
| 2230 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2231 | // Finally, try to correctly create a surface: |
| 2232 | xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; |
| 2233 | xcb_create_info.pNext = NULL; |
| 2234 | xcb_create_info.flags = 0; |
| 2235 | xcb_create_info.connection = connection; |
| 2236 | xcb_create_info.window = xcb_window; |
| 2237 | err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface); |
| 2238 | pass = (err == VK_SUCCESS); |
| 2239 | ASSERT_TRUE(pass); |
| 2240 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2241 | // Check if surface supports presentation: |
| 2242 | |
| 2243 | // 1st, do so without having queried the queue families: |
| 2244 | VkBool32 supported = false; |
| 2245 | // TODO: Get the following error to come out: |
| 2246 | m_errorMonitor->SetDesiredFailureMsg( |
| 2247 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2248 | "called before calling the vkGetPhysicalDeviceQueueFamilyProperties " |
| 2249 | "function"); |
| 2250 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported); |
| 2251 | pass = (err != VK_SUCCESS); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2252 | // ASSERT_TRUE(pass); |
| 2253 | // m_errorMonitor->VerifyFound(); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2254 | |
| 2255 | // Next, query a queue family index that's too large: |
| 2256 | m_errorMonitor->SetDesiredFailureMsg( |
| 2257 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2258 | "called with a queueFamilyIndex that is too large"); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2259 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, |
| 2260 | &supported); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2261 | pass = (err != VK_SUCCESS); |
| 2262 | ASSERT_TRUE(pass); |
| 2263 | m_errorMonitor->VerifyFound(); |
| 2264 | |
| 2265 | // Finally, do so correctly: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2266 | // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S |
| 2267 | // SUPPORTED |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2268 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported); |
| 2269 | pass = (err == VK_SUCCESS); |
| 2270 | ASSERT_TRUE(pass); |
| 2271 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2272 | // Before proceeding, try to create a swapchain without having called |
| 2273 | // vkGetPhysicalDeviceSurfaceCapabilitiesKHR(): |
| 2274 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 2275 | swapchain_create_info.pNext = NULL; |
| 2276 | swapchain_create_info.flags = 0; |
| 2277 | m_errorMonitor->SetDesiredFailureMsg( |
| 2278 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2279 | "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR()."); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2280 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2281 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2282 | pass = (err != VK_SUCCESS); |
| 2283 | ASSERT_TRUE(pass); |
| 2284 | m_errorMonitor->VerifyFound(); |
| 2285 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2286 | // Get the surface capabilities: |
| 2287 | VkSurfaceCapabilitiesKHR surface_capabilities; |
| 2288 | |
| 2289 | // Do so correctly (only error logged by this entrypoint is if the |
| 2290 | // extension isn't enabled): |
| 2291 | err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, |
| 2292 | &surface_capabilities); |
| 2293 | pass = (err == VK_SUCCESS); |
| 2294 | ASSERT_TRUE(pass); |
| 2295 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2296 | // Get the surface formats: |
| 2297 | uint32_t surface_format_count; |
| 2298 | |
| 2299 | // First, try without a pointer to surface_format_count: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2300 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2301 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2302 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL); |
| 2303 | pass = (err == VK_SUCCESS); |
| 2304 | ASSERT_TRUE(pass); |
| 2305 | m_errorMonitor->VerifyFound(); |
| 2306 | |
| 2307 | // Next, call with a non-NULL pSurfaceFormats, even though we haven't |
| 2308 | // correctly done a 1st try (to get the count): |
| 2309 | m_errorMonitor->SetDesiredFailureMsg( |
| 2310 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2311 | "but no prior positive value has been seen for"); |
| 2312 | surface_format_count = 0; |
| 2313 | vkGetPhysicalDeviceSurfaceFormatsKHR( |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2314 | gpu(), surface, &surface_format_count, |
| 2315 | (VkSurfaceFormatKHR *)&surface_format_count); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2316 | pass = (err == VK_SUCCESS); |
| 2317 | ASSERT_TRUE(pass); |
| 2318 | m_errorMonitor->VerifyFound(); |
| 2319 | |
| 2320 | // 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] | 2321 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
| 2322 | NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2323 | pass = (err == VK_SUCCESS); |
| 2324 | ASSERT_TRUE(pass); |
| 2325 | |
| 2326 | // Allocate memory for the correct number of VkSurfaceFormatKHR's: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2327 | VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc( |
| 2328 | surface_format_count * sizeof(VkSurfaceFormatKHR)); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2329 | |
| 2330 | // Next, do a 2nd try with surface_format_count being set too high: |
| 2331 | surface_format_count += 5; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2332 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2333 | "that is greater than the value"); |
| 2334 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2335 | surface_formats); |
| 2336 | pass = (err == VK_SUCCESS); |
| 2337 | ASSERT_TRUE(pass); |
| 2338 | m_errorMonitor->VerifyFound(); |
| 2339 | |
| 2340 | // Finally, do a correct 1st and 2nd try: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2341 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
| 2342 | NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2343 | pass = (err == VK_SUCCESS); |
| 2344 | ASSERT_TRUE(pass); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2345 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2346 | surface_formats); |
| 2347 | pass = (err == VK_SUCCESS); |
| 2348 | ASSERT_TRUE(pass); |
| 2349 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2350 | // Get the surface present modes: |
| 2351 | uint32_t surface_present_mode_count; |
| 2352 | |
| 2353 | // First, try without a pointer to surface_format_count: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2354 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2355 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2356 | vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL); |
| 2357 | pass = (err == VK_SUCCESS); |
| 2358 | ASSERT_TRUE(pass); |
| 2359 | m_errorMonitor->VerifyFound(); |
| 2360 | |
| 2361 | // Next, call with a non-NULL VkPresentModeKHR, even though we haven't |
| 2362 | // correctly done a 1st try (to get the count): |
| 2363 | m_errorMonitor->SetDesiredFailureMsg( |
| 2364 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2365 | "but no prior positive value has been seen for"); |
| 2366 | surface_present_mode_count = 0; |
| 2367 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2368 | gpu(), surface, &surface_present_mode_count, |
| 2369 | (VkPresentModeKHR *)&surface_present_mode_count); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2370 | pass = (err == VK_SUCCESS); |
| 2371 | ASSERT_TRUE(pass); |
| 2372 | m_errorMonitor->VerifyFound(); |
| 2373 | |
| 2374 | // 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] | 2375 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 2376 | gpu(), surface, &surface_present_mode_count, NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2377 | pass = (err == VK_SUCCESS); |
| 2378 | ASSERT_TRUE(pass); |
| 2379 | |
| 2380 | // Allocate memory for the correct number of VkSurfaceFormatKHR's: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2381 | VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc( |
| 2382 | surface_present_mode_count * sizeof(VkPresentModeKHR)); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2383 | |
| 2384 | // Next, do a 2nd try with surface_format_count being set too high: |
| 2385 | surface_present_mode_count += 5; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2386 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2387 | "that is greater than the value"); |
| 2388 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 2389 | gpu(), surface, &surface_present_mode_count, surface_present_modes); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2390 | pass = (err == VK_SUCCESS); |
| 2391 | ASSERT_TRUE(pass); |
| 2392 | m_errorMonitor->VerifyFound(); |
| 2393 | |
| 2394 | // Finally, do a correct 1st and 2nd try: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2395 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 2396 | gpu(), surface, &surface_present_mode_count, NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2397 | pass = (err == VK_SUCCESS); |
| 2398 | ASSERT_TRUE(pass); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2399 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 2400 | gpu(), surface, &surface_present_mode_count, surface_present_modes); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2401 | pass = (err == VK_SUCCESS); |
| 2402 | ASSERT_TRUE(pass); |
| 2403 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2404 | // Create a swapchain: |
| 2405 | |
| 2406 | // First, try without a pointer to swapchain_create_info: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2407 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2408 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2409 | err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain); |
| 2410 | pass = (err != VK_SUCCESS); |
| 2411 | ASSERT_TRUE(pass); |
| 2412 | m_errorMonitor->VerifyFound(); |
| 2413 | |
| 2414 | // Next, call with a non-NULL swapchain_create_info, that has the wrong |
| 2415 | // sType: |
| 2416 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2417 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2418 | "called with the wrong value for"); |
| 2419 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2420 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2421 | pass = (err != VK_SUCCESS); |
| 2422 | ASSERT_TRUE(pass); |
| 2423 | m_errorMonitor->VerifyFound(); |
| 2424 | |
| 2425 | // Next, call with a NULL swapchain pointer: |
| 2426 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 2427 | swapchain_create_info.pNext = NULL; |
| 2428 | swapchain_create_info.flags = 0; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2429 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2430 | "called with NULL pointer"); |
| 2431 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2432 | NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2433 | pass = (err != VK_SUCCESS); |
| 2434 | ASSERT_TRUE(pass); |
| 2435 | m_errorMonitor->VerifyFound(); |
| 2436 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2437 | // TODO: Enhance swapchain layer so that |
| 2438 | // swapchain_create_info.queueFamilyIndexCount is checked against something? |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2439 | |
| 2440 | // Next, call with a queue family index that's too large: |
| 2441 | uint32_t queueFamilyIndex[2] = {100000, 0}; |
| 2442 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT; |
| 2443 | swapchain_create_info.queueFamilyIndexCount = 2; |
| 2444 | swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex; |
| 2445 | m_errorMonitor->SetDesiredFailureMsg( |
| 2446 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2447 | "called with a queueFamilyIndex that is too large"); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2448 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2449 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2450 | pass = (err != VK_SUCCESS); |
| 2451 | ASSERT_TRUE(pass); |
| 2452 | m_errorMonitor->VerifyFound(); |
| 2453 | |
| 2454 | // Next, call a queueFamilyIndexCount that's too small for CONCURRENT: |
| 2455 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT; |
| 2456 | swapchain_create_info.queueFamilyIndexCount = 1; |
| 2457 | m_errorMonitor->SetDesiredFailureMsg( |
| 2458 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2459 | "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or " |
| 2460 | "pCreateInfo->pQueueFamilyIndices)."); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2461 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2462 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2463 | pass = (err != VK_SUCCESS); |
| 2464 | ASSERT_TRUE(pass); |
| 2465 | m_errorMonitor->VerifyFound(); |
| 2466 | |
| 2467 | // Next, call with an invalid imageSharingMode: |
| 2468 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM; |
| 2469 | swapchain_create_info.queueFamilyIndexCount = 1; |
| 2470 | m_errorMonitor->SetDesiredFailureMsg( |
| 2471 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2472 | "called with a non-supported pCreateInfo->imageSharingMode (i.e."); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2473 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2474 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2475 | pass = (err != VK_SUCCESS); |
| 2476 | ASSERT_TRUE(pass); |
| 2477 | m_errorMonitor->VerifyFound(); |
| 2478 | // Fix for the future: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2479 | // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S |
| 2480 | // SUPPORTED |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2481 | swapchain_create_info.queueFamilyIndexCount = 0; |
| 2482 | queueFamilyIndex[0] = 0; |
| 2483 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 2484 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2485 | // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ... |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2486 | // Get the images from a swapchain: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2487 | // Acquire an image from a swapchain: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2488 | // Present an image to a swapchain: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2489 | // Destroy the swapchain: |
| 2490 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2491 | // TODOs: |
| 2492 | // |
| 2493 | // - Try destroying the device without first destroying the swapchain |
| 2494 | // |
| 2495 | // - Try destroying the device without first destroying the surface |
| 2496 | // |
| 2497 | // - Try destroying the surface without first destroying the swapchain |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2498 | |
| 2499 | // Destroy the surface: |
| 2500 | vkDestroySurfaceKHR(instance(), surface, NULL); |
| 2501 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2502 | // Tear down the window: |
| 2503 | xcb_destroy_window(connection, xcb_window); |
| 2504 | xcb_disconnect(connection); |
| 2505 | |
| 2506 | #else // VK_USE_PLATFORM_XCB_KHR |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2507 | return; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2508 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 2509 | } |
| 2510 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2511 | TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) { |
| 2512 | VkResult err; |
| 2513 | bool pass; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2514 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2515 | m_errorMonitor->SetDesiredFailureMsg( |
| 2516 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2517 | "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT"); |
| 2518 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2519 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2520 | |
| 2521 | // 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] | 2522 | VkImage image; |
| 2523 | VkDeviceMemory mem; |
| 2524 | VkMemoryRequirements mem_reqs; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2525 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2526 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2527 | const int32_t tex_width = 32; |
| 2528 | const int32_t tex_height = 32; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2529 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2530 | VkImageCreateInfo image_create_info = {}; |
| 2531 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2532 | image_create_info.pNext = NULL; |
| 2533 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2534 | image_create_info.format = tex_format; |
| 2535 | image_create_info.extent.width = tex_width; |
| 2536 | image_create_info.extent.height = tex_height; |
| 2537 | image_create_info.extent.depth = 1; |
| 2538 | image_create_info.mipLevels = 1; |
| 2539 | image_create_info.arrayLayers = 1; |
| 2540 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2541 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2542 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2543 | image_create_info.flags = 0; |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 2544 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2545 | VkMemoryAllocateInfo mem_alloc = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 2546 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2547 | mem_alloc.pNext = NULL; |
| 2548 | mem_alloc.allocationSize = 0; |
| 2549 | // Introduce failure, do NOT set memProps to |
| 2550 | // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
| 2551 | mem_alloc.memoryTypeIndex = 1; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2552 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2553 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2554 | ASSERT_VK_SUCCESS(err); |
| 2555 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2556 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2557 | |
Mark Lobodzinski | 2306535 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 2558 | mem_alloc.allocationSize = mem_reqs.size; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2559 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2560 | pass = |
| 2561 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, |
| 2562 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 2563 | if (!pass) { // If we can't find any unmappable memory this test doesn't |
| 2564 | // make sense |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2565 | vkDestroyImage(m_device->device(), image, NULL); |
Tony Barbour | 02fdc7d | 2015-08-04 16:13:01 -0600 | [diff] [blame] | 2566 | return; |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2567 | } |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 2568 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2569 | // allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2570 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2571 | ASSERT_VK_SUCCESS(err); |
| 2572 | |
| 2573 | // Try to bind free memory that has been freed |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 2574 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2575 | ASSERT_VK_SUCCESS(err); |
| 2576 | |
| 2577 | // Map memory as if to initialize the image |
| 2578 | void *mappedAddress = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2579 | err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, |
| 2580 | &mappedAddress); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2581 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2582 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2583 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2584 | vkDestroyImage(m_device->device(), image, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 2585 | vkFreeMemory(m_device->device(), mem, NULL); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2586 | } |
| 2587 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2588 | TEST_F(VkLayerTest, RebindMemory) { |
| 2589 | VkResult err; |
| 2590 | bool pass; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2591 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2592 | m_errorMonitor->SetDesiredFailureMsg( |
| 2593 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2594 | "which has already been bound to mem object"); |
| 2595 | |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2596 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2597 | |
| 2598 | // 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] | 2599 | VkImage image; |
| 2600 | VkDeviceMemory mem1; |
| 2601 | VkDeviceMemory mem2; |
| 2602 | VkMemoryRequirements mem_reqs; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2603 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2604 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2605 | const int32_t tex_width = 32; |
| 2606 | const int32_t tex_height = 32; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2607 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2608 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2609 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2610 | image_create_info.pNext = NULL; |
| 2611 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2612 | image_create_info.format = tex_format; |
| 2613 | image_create_info.extent.width = tex_width; |
| 2614 | image_create_info.extent.height = tex_height; |
| 2615 | image_create_info.extent.depth = 1; |
| 2616 | image_create_info.mipLevels = 1; |
| 2617 | image_create_info.arrayLayers = 1; |
| 2618 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2619 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2620 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2621 | image_create_info.flags = 0; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2622 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2623 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2624 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2625 | mem_alloc.pNext = NULL; |
| 2626 | mem_alloc.allocationSize = 0; |
| 2627 | mem_alloc.memoryTypeIndex = 0; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2628 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2629 | // Introduce failure, do NOT set memProps to |
| 2630 | // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2631 | mem_alloc.memoryTypeIndex = 1; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2632 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2633 | ASSERT_VK_SUCCESS(err); |
| 2634 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2635 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2636 | |
| 2637 | mem_alloc.allocationSize = mem_reqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2638 | pass = |
| 2639 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 2640 | ASSERT_TRUE(pass); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2641 | |
| 2642 | // allocate 2 memory objects |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2643 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2644 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2645 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2646 | ASSERT_VK_SUCCESS(err); |
| 2647 | |
| 2648 | // Bind first memory object to Image object |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 2649 | err = vkBindImageMemory(m_device->device(), image, mem1, 0); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2650 | ASSERT_VK_SUCCESS(err); |
| 2651 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2652 | // Introduce validation failure, try to bind a different memory object to |
| 2653 | // the same image object |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 2654 | err = vkBindImageMemory(m_device->device(), image, mem2, 0); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2655 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2656 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2657 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2658 | vkDestroyImage(m_device->device(), image, NULL); |
| 2659 | vkFreeMemory(m_device->device(), mem1, NULL); |
| 2660 | vkFreeMemory(m_device->device(), mem2, NULL); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2661 | } |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2662 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2663 | TEST_F(VkLayerTest, SubmitSignaledFence) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2664 | vk_testing::Fence testFence; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2665 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2666 | m_errorMonitor->SetDesiredFailureMsg( |
| 2667 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences " |
| 2668 | "must be reset before being submitted"); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 2669 | |
| 2670 | VkFenceCreateInfo fenceInfo = {}; |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2671 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 2672 | fenceInfo.pNext = NULL; |
| 2673 | fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2674 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2675 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2676 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 2677 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 2678 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2679 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2680 | m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 2681 | m_stencil_clear_color, NULL); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2682 | EndCommandBuffer(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2683 | |
| 2684 | testFence.init(*m_device, fenceInfo); |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 2685 | |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 2686 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 2687 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 2688 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 2689 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 2690 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 2691 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 2692 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2693 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 2694 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 2695 | submit_info.pSignalSemaphores = NULL; |
Courtney Goeltzenleuchter | 646b907 | 2015-10-20 18:04:07 -0600 | [diff] [blame] | 2696 | |
| 2697 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2698 | vkQueueWaitIdle(m_device->m_queue); |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 2699 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2700 | m_errorMonitor->VerifyFound(); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2701 | } |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2702 | // This is a positive test. We used to expect error in this case but spec now |
| 2703 | // allows it |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2704 | TEST_F(VkLayerTest, ResetUnsignaledFence) { |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2705 | m_errorMonitor->ExpectSuccess(); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2706 | vk_testing::Fence testFence; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 2707 | VkFenceCreateInfo fenceInfo = {}; |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2708 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 2709 | fenceInfo.pNext = NULL; |
| 2710 | |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2711 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2712 | testFence.init(*m_device, fenceInfo); |
Chia-I Wu | d9e8e82 | 2015-07-03 11:45:55 +0800 | [diff] [blame] | 2713 | VkFence fences[1] = {testFence.handle()}; |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2714 | VkResult result = vkResetFences(m_device->device(), 1, fences); |
| 2715 | ASSERT_VK_SUCCESS(result); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2716 | |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2717 | m_errorMonitor->VerifyNotFound(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2718 | } |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2719 | |
Chris Forbes | e70b7d3 | 2016-06-15 15:49:12 +1200 | [diff] [blame] | 2720 | #if 0 |
| 2721 | TEST_F(VkLayerTest, LongFenceChain) |
| 2722 | { |
| 2723 | m_errorMonitor->ExpectSuccess(); |
| 2724 | |
| 2725 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2726 | VkResult err; |
| 2727 | |
| 2728 | std::vector<VkFence> fences; |
| 2729 | |
| 2730 | const int chainLength = 32768; |
| 2731 | |
| 2732 | for (int i = 0; i < chainLength; i++) { |
| 2733 | VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 }; |
| 2734 | VkFence fence; |
| 2735 | err = vkCreateFence(m_device->device(), &fci, nullptr, &fence); |
| 2736 | ASSERT_VK_SUCCESS(err); |
| 2737 | |
| 2738 | fences.push_back(fence); |
| 2739 | |
| 2740 | VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, |
| 2741 | 0, nullptr, 0, nullptr }; |
| 2742 | err = vkQueueSubmit(m_device->m_queue, 1, &si, fence); |
| 2743 | ASSERT_VK_SUCCESS(err); |
| 2744 | |
| 2745 | } |
| 2746 | |
| 2747 | // BOOM, stack overflow. |
| 2748 | vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX); |
| 2749 | |
| 2750 | for (auto fence : fences) |
| 2751 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 2752 | |
| 2753 | m_errorMonitor->VerifyNotFound(); |
| 2754 | } |
| 2755 | #endif |
| 2756 | |
Chris Forbes | 18127d1 | 2016-06-08 16:52:28 +1200 | [diff] [blame] | 2757 | TEST_F(VkLayerTest, CommandBufferSimultaneousUseSync) |
| 2758 | { |
| 2759 | m_errorMonitor->ExpectSuccess(); |
| 2760 | |
| 2761 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2762 | VkResult err; |
| 2763 | |
| 2764 | // Record (empty!) command buffer that can be submitted multiple times |
| 2765 | // simultaneously. |
| 2766 | VkCommandBufferBeginInfo cbbi = { |
| 2767 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, |
| 2768 | VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr |
| 2769 | }; |
| 2770 | m_commandBuffer->BeginCommandBuffer(&cbbi); |
| 2771 | m_commandBuffer->EndCommandBuffer(); |
| 2772 | |
| 2773 | VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 }; |
| 2774 | VkFence fence; |
| 2775 | err = vkCreateFence(m_device->device(), &fci, nullptr, &fence); |
| 2776 | ASSERT_VK_SUCCESS(err); |
| 2777 | |
| 2778 | VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 }; |
| 2779 | VkSemaphore s1, s2; |
| 2780 | err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1); |
| 2781 | ASSERT_VK_SUCCESS(err); |
| 2782 | err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2); |
| 2783 | ASSERT_VK_SUCCESS(err); |
| 2784 | |
| 2785 | // Submit CB once signaling s1, with fence so we can roll forward to its retirement. |
| 2786 | VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, |
| 2787 | 1, &m_commandBuffer->handle(), 1, &s1 }; |
| 2788 | err = vkQueueSubmit(m_device->m_queue, 1, &si, fence); |
| 2789 | ASSERT_VK_SUCCESS(err); |
| 2790 | |
| 2791 | // Submit CB again, signaling s2. |
| 2792 | si.pSignalSemaphores = &s2; |
| 2793 | err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE); |
| 2794 | ASSERT_VK_SUCCESS(err); |
| 2795 | |
| 2796 | // Wait for fence. |
| 2797 | err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 2798 | ASSERT_VK_SUCCESS(err); |
| 2799 | |
| 2800 | // CB is still in flight from second submission, but semaphore s1 is no |
| 2801 | // longer in flight. delete it. |
| 2802 | vkDestroySemaphore(m_device->device(), s1, nullptr); |
| 2803 | |
| 2804 | m_errorMonitor->VerifyNotFound(); |
| 2805 | |
| 2806 | // Force device idle and clean up remaining objects |
| 2807 | vkDeviceWaitIdle(m_device->device()); |
| 2808 | vkDestroySemaphore(m_device->device(), s2, nullptr); |
| 2809 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 2810 | } |
| 2811 | |
Chris Forbes | 4e44c91 | 2016-06-16 10:20:00 +1200 | [diff] [blame] | 2812 | TEST_F(VkLayerTest, FenceCreateSignaledWaitHandling) |
| 2813 | { |
| 2814 | m_errorMonitor->ExpectSuccess(); |
| 2815 | |
| 2816 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2817 | VkResult err; |
| 2818 | |
| 2819 | // A fence created signaled |
| 2820 | VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT }; |
| 2821 | VkFence f1; |
| 2822 | err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1); |
| 2823 | ASSERT_VK_SUCCESS(err); |
| 2824 | |
| 2825 | // A fence created not |
| 2826 | VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 }; |
| 2827 | VkFence f2; |
| 2828 | err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2); |
| 2829 | ASSERT_VK_SUCCESS(err); |
| 2830 | |
| 2831 | // Submit the unsignaled fence |
| 2832 | VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, |
| 2833 | 0, nullptr, 0, nullptr }; |
| 2834 | err = vkQueueSubmit(m_device->m_queue, 1, &si, f2); |
| 2835 | |
| 2836 | // Wait on both fences, with signaled first. |
| 2837 | VkFence fences[] = { f1, f2 }; |
| 2838 | vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX); |
| 2839 | |
| 2840 | // Should have both retired! |
| 2841 | vkDestroyFence(m_device->device(), f1, nullptr); |
| 2842 | vkDestroyFence(m_device->device(), f2, nullptr); |
| 2843 | |
| 2844 | m_errorMonitor->VerifyNotFound(); |
| 2845 | } |
| 2846 | |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2847 | TEST_F(VkLayerTest, InvalidUsageBits) |
| 2848 | { |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2849 | TEST_DESCRIPTION( |
Karl Schultz | b5bc11e | 2016-05-04 08:36:08 -0600 | [diff] [blame] | 2850 | "Specify wrong usage for image then create conflicting view of image " |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2851 | "Initialize buffer with wrong usage then perform copy expecting errors " |
| 2852 | "from both the image and the buffer (2 calls)"); |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2853 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2854 | "Invalid usage flag for image "); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2855 | |
| 2856 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2857 | VkImageObj image(m_device); |
| 2858 | // Initialize image with USAGE_INPUT_ATTACHMENT |
Tobin Ehlis | 8b313c0 | 2016-05-25 15:01:52 -0600 | [diff] [blame] | 2859 | image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, |
Karl Schultz | b5bc11e | 2016-05-04 08:36:08 -0600 | [diff] [blame] | 2860 | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 2861 | ASSERT_TRUE(image.initialized()); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2862 | |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2863 | VkImageView dsv; |
| 2864 | VkImageViewCreateInfo dsvci = {}; |
| 2865 | dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 2866 | dsvci.image = image.handle(); |
| 2867 | dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 2868 | dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT; |
| 2869 | dsvci.subresourceRange.layerCount = 1; |
| 2870 | dsvci.subresourceRange.baseMipLevel = 0; |
| 2871 | dsvci.subresourceRange.levelCount = 1; |
| 2872 | dsvci.subresourceRange.aspectMask = |
| 2873 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2874 | |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2875 | // Create a view with depth / stencil aspect for image with different usage |
| 2876 | vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2877 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2878 | m_errorMonitor->VerifyFound(); |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2879 | |
| 2880 | // Initialize buffer with TRANSFER_DST usage |
| 2881 | vk_testing::Buffer buffer; |
| 2882 | VkMemoryPropertyFlags reqs = 0; |
| 2883 | buffer.init_as_dst(*m_device, 128 * 128, reqs); |
| 2884 | VkBufferImageCopy region = {}; |
| 2885 | region.bufferRowLength = 128; |
| 2886 | region.bufferImageHeight = 128; |
| 2887 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 2888 | region.imageSubresource.layerCount = 1; |
| 2889 | region.imageExtent.height = 16; |
| 2890 | region.imageExtent.width = 16; |
| 2891 | region.imageExtent.depth = 1; |
| 2892 | |
| 2893 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2894 | "Invalid usage flag for buffer "); |
| 2895 | // Buffer usage not set to TRANSFER_SRC and image usage not set to |
| 2896 | // TRANSFER_DST |
| 2897 | BeginCommandBuffer(); |
| 2898 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 2899 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 2900 | 1, ®ion); |
| 2901 | m_errorMonitor->VerifyFound(); |
| 2902 | |
| 2903 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2904 | "Invalid usage flag for image "); |
| 2905 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 2906 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 2907 | 1, ®ion); |
| 2908 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2909 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 2910 | #endif // MEM_TRACKER_TESTS |
| 2911 | |
Tobin Ehlis | 4bf96d1 | 2015-06-25 11:58:41 -0600 | [diff] [blame] | 2912 | #if OBJ_TRACKER_TESTS |
Mark Lobodzinski | fc5cc66 | 2016-05-02 17:17:41 -0600 | [diff] [blame] | 2913 | |
| 2914 | TEST_F(VkLayerTest, LeakAnObject) { |
| 2915 | VkResult err; |
| 2916 | |
| 2917 | TEST_DESCRIPTION( |
| 2918 | "Create a fence and destroy its device without first destroying the fence."); |
| 2919 | |
| 2920 | // Note that we have to create a new device since destroying the |
| 2921 | // framework's device causes Teardown() to fail and just calling Teardown |
| 2922 | // will destroy the errorMonitor. |
| 2923 | |
| 2924 | m_errorMonitor->SetDesiredFailureMsg( |
| 2925 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2926 | "OBJ ERROR : VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT object"); |
| 2927 | |
| 2928 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2929 | |
| 2930 | const std::vector<VkQueueFamilyProperties> queue_props = |
| 2931 | m_device->queue_props; |
| 2932 | std::vector<VkDeviceQueueCreateInfo> queue_info; |
| 2933 | queue_info.reserve(queue_props.size()); |
| 2934 | std::vector<std::vector<float>> queue_priorities; |
| 2935 | for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) { |
| 2936 | VkDeviceQueueCreateInfo qi = {}; |
| 2937 | qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; |
| 2938 | qi.pNext = NULL; |
| 2939 | qi.queueFamilyIndex = i; |
| 2940 | qi.queueCount = queue_props[i].queueCount; |
| 2941 | queue_priorities.emplace_back(qi.queueCount, 0.0f); |
| 2942 | qi.pQueuePriorities = queue_priorities[i].data(); |
| 2943 | queue_info.push_back(qi); |
| 2944 | } |
| 2945 | |
| 2946 | std::vector<const char *> device_layer_names; |
| 2947 | std::vector<const char *> device_extension_names; |
| 2948 | device_layer_names.push_back("VK_LAYER_GOOGLE_threading"); |
| 2949 | device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation"); |
| 2950 | device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker"); |
| 2951 | device_layer_names.push_back("VK_LAYER_LUNARG_core_validation"); |
Mark Lobodzinski | fc5cc66 | 2016-05-02 17:17:41 -0600 | [diff] [blame] | 2952 | device_layer_names.push_back("VK_LAYER_LUNARG_image"); |
| 2953 | device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects"); |
| 2954 | |
| 2955 | // The sacrificial device object |
| 2956 | VkDevice testDevice; |
| 2957 | VkDeviceCreateInfo device_create_info = {}; |
| 2958 | auto features = m_device->phy().features(); |
| 2959 | device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; |
| 2960 | device_create_info.pNext = NULL; |
| 2961 | device_create_info.queueCreateInfoCount = queue_info.size(); |
| 2962 | device_create_info.pQueueCreateInfos = queue_info.data(); |
| 2963 | device_create_info.enabledLayerCount = device_layer_names.size(); |
| 2964 | device_create_info.ppEnabledLayerNames = device_layer_names.data(); |
| 2965 | device_create_info.pEnabledFeatures = &features; |
| 2966 | err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice); |
| 2967 | ASSERT_VK_SUCCESS(err); |
| 2968 | |
| 2969 | VkFence fence; |
| 2970 | VkFenceCreateInfo fence_create_info = {}; |
| 2971 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 2972 | fence_create_info.pNext = NULL; |
| 2973 | fence_create_info.flags = 0; |
| 2974 | err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence); |
| 2975 | ASSERT_VK_SUCCESS(err); |
| 2976 | |
| 2977 | // Induce failure by not calling vkDestroyFence |
| 2978 | vkDestroyDevice(testDevice, NULL); |
| 2979 | m_errorMonitor->VerifyFound(); |
| 2980 | } |
| 2981 | |
| 2982 | TEST_F(VkLayerTest, InvalidCommandPoolConsistency) { |
| 2983 | |
| 2984 | TEST_DESCRIPTION("Allocate command buffers from one command pool and " |
| 2985 | "attempt to delete them from another."); |
| 2986 | |
| 2987 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2988 | "FreeCommandBuffers is attempting to free Command Buffer"); |
| 2989 | |
| 2990 | VkCommandPool command_pool_one; |
| 2991 | VkCommandPool command_pool_two; |
| 2992 | |
| 2993 | VkCommandPoolCreateInfo pool_create_info{}; |
| 2994 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 2995 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 2996 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 2997 | |
| 2998 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 2999 | &command_pool_one); |
| 3000 | |
| 3001 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3002 | &command_pool_two); |
| 3003 | |
| 3004 | VkCommandBuffer command_buffer[9]; |
| 3005 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3006 | command_buffer_allocate_info.sType = |
| 3007 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3008 | command_buffer_allocate_info.commandPool = command_pool_one; |
| 3009 | command_buffer_allocate_info.commandBufferCount = 9; |
| 3010 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3011 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3012 | command_buffer); |
| 3013 | |
| 3014 | vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, |
| 3015 | &command_buffer[3]); |
| 3016 | |
| 3017 | m_errorMonitor->VerifyFound(); |
| 3018 | |
| 3019 | vkDestroyCommandPool(m_device->device(), command_pool_one, NULL); |
| 3020 | vkDestroyCommandPool(m_device->device(), command_pool_two, NULL); |
| 3021 | } |
| 3022 | |
| 3023 | TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) { |
| 3024 | VkResult err; |
| 3025 | |
| 3026 | TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and " |
| 3027 | "attempt to delete them from another."); |
| 3028 | |
| 3029 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3030 | "FreeDescriptorSets is attempting to free descriptorSet"); |
| 3031 | |
| 3032 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3033 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 3034 | |
| 3035 | VkDescriptorPoolSize ds_type_count = {}; |
| 3036 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 3037 | ds_type_count.descriptorCount = 1; |
| 3038 | |
| 3039 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 3040 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 3041 | ds_pool_ci.pNext = NULL; |
| 3042 | ds_pool_ci.flags = 0; |
| 3043 | ds_pool_ci.maxSets = 1; |
| 3044 | ds_pool_ci.poolSizeCount = 1; |
| 3045 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 3046 | |
| 3047 | VkDescriptorPool ds_pool_one; |
| 3048 | err = |
| 3049 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one); |
| 3050 | ASSERT_VK_SUCCESS(err); |
| 3051 | |
| 3052 | // Create a second descriptor pool |
| 3053 | VkDescriptorPool ds_pool_two; |
| 3054 | err = |
| 3055 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two); |
| 3056 | ASSERT_VK_SUCCESS(err); |
| 3057 | |
| 3058 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 3059 | dsl_binding.binding = 0; |
| 3060 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 3061 | dsl_binding.descriptorCount = 1; |
| 3062 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 3063 | dsl_binding.pImmutableSamplers = NULL; |
| 3064 | |
| 3065 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 3066 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 3067 | ds_layout_ci.pNext = NULL; |
| 3068 | ds_layout_ci.bindingCount = 1; |
| 3069 | ds_layout_ci.pBindings = &dsl_binding; |
| 3070 | |
| 3071 | VkDescriptorSetLayout ds_layout; |
| 3072 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 3073 | &ds_layout); |
| 3074 | ASSERT_VK_SUCCESS(err); |
| 3075 | |
| 3076 | VkDescriptorSet descriptorSet; |
| 3077 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 3078 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 3079 | alloc_info.descriptorSetCount = 1; |
| 3080 | alloc_info.descriptorPool = ds_pool_one; |
| 3081 | alloc_info.pSetLayouts = &ds_layout; |
| 3082 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 3083 | &descriptorSet); |
| 3084 | ASSERT_VK_SUCCESS(err); |
| 3085 | |
| 3086 | err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet); |
| 3087 | |
| 3088 | m_errorMonitor->VerifyFound(); |
| 3089 | |
| 3090 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 3091 | vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL); |
| 3092 | vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL); |
| 3093 | } |
| 3094 | |
| 3095 | TEST_F(VkLayerTest, CreateUnknownObject) { |
| 3096 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3097 | "Invalid VkImage Object "); |
| 3098 | |
| 3099 | TEST_DESCRIPTION( |
| 3100 | "Pass an invalid image object handle into a Vulkan API call."); |
| 3101 | |
| 3102 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3103 | |
| 3104 | // Pass bogus handle into GetImageMemoryRequirements |
| 3105 | VkMemoryRequirements mem_reqs; |
| 3106 | uint64_t fakeImageHandle = 0xCADECADE; |
| 3107 | VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle); |
| 3108 | |
| 3109 | vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs); |
| 3110 | |
| 3111 | m_errorMonitor->VerifyFound(); |
| 3112 | } |
| 3113 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3114 | TEST_F(VkLayerTest, PipelineNotBound) { |
| 3115 | VkResult err; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3116 | |
Mark Lobodzinski | fc5cc66 | 2016-05-02 17:17:41 -0600 | [diff] [blame] | 3117 | TEST_DESCRIPTION( |
| 3118 | "Pass in an invalid pipeline object handle into a Vulkan API call."); |
| 3119 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 3120 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3121 | "Invalid VkPipeline Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 3122 | |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3123 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3124 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3125 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 3126 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3127 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 3128 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3129 | |
| 3130 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3131 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 3132 | ds_pool_ci.pNext = NULL; |
| 3133 | ds_pool_ci.maxSets = 1; |
| 3134 | ds_pool_ci.poolSizeCount = 1; |
| 3135 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3136 | |
| 3137 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3138 | err = |
| 3139 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3140 | ASSERT_VK_SUCCESS(err); |
| 3141 | |
| 3142 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3143 | dsl_binding.binding = 0; |
| 3144 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 3145 | dsl_binding.descriptorCount = 1; |
| 3146 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 3147 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3148 | |
| 3149 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3150 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 3151 | ds_layout_ci.pNext = NULL; |
| 3152 | ds_layout_ci.bindingCount = 1; |
| 3153 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3154 | |
| 3155 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3156 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 3157 | &ds_layout); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3158 | ASSERT_VK_SUCCESS(err); |
| 3159 | |
| 3160 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 3161 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 3162 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 3163 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 3164 | alloc_info.descriptorPool = ds_pool; |
| 3165 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3166 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 3167 | &descriptorSet); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3168 | ASSERT_VK_SUCCESS(err); |
| 3169 | |
| 3170 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3171 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 3172 | pipeline_layout_ci.pNext = NULL; |
| 3173 | pipeline_layout_ci.setLayoutCount = 1; |
| 3174 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3175 | |
| 3176 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3177 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 3178 | &pipeline_layout); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3179 | ASSERT_VK_SUCCESS(err); |
| 3180 | |
Mark Young | ad77905 | 2016-01-06 14:26:04 -0700 | [diff] [blame] | 3181 | VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3182 | |
| 3183 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3184 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 3185 | VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3186 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 3187 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 3188 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 3189 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 3190 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 3191 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3192 | } |
Mike Stroyan | 80fc6c3 | 2016-06-20 15:42:29 -0600 | [diff] [blame] | 3193 | |
Mark Lobodzinski | bc18576 | 2016-06-15 16:28:53 -0600 | [diff] [blame] | 3194 | TEST_F(VkLayerTest, BindImageInvalidMemoryType) { |
| 3195 | VkResult err; |
| 3196 | |
| 3197 | TEST_DESCRIPTION("Test validation check for an invalid memory type index " |
| 3198 | "during bind[Buffer|Image]Memory time"); |
| 3199 | |
Mark Lobodzinski | bc18576 | 2016-06-15 16:28:53 -0600 | [diff] [blame] | 3200 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3201 | |
| 3202 | // Create an image, allocate memory, set a bad typeIndex and then try to |
| 3203 | // bind it |
| 3204 | VkImage image; |
| 3205 | VkDeviceMemory mem; |
| 3206 | VkMemoryRequirements mem_reqs; |
| 3207 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 3208 | const int32_t tex_width = 32; |
| 3209 | const int32_t tex_height = 32; |
| 3210 | |
| 3211 | VkImageCreateInfo image_create_info = {}; |
| 3212 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 3213 | image_create_info.pNext = NULL; |
| 3214 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 3215 | image_create_info.format = tex_format; |
| 3216 | image_create_info.extent.width = tex_width; |
| 3217 | image_create_info.extent.height = tex_height; |
| 3218 | image_create_info.extent.depth = 1; |
| 3219 | image_create_info.mipLevels = 1; |
| 3220 | image_create_info.arrayLayers = 1; |
| 3221 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 3222 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 3223 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 3224 | image_create_info.flags = 0; |
| 3225 | |
| 3226 | VkMemoryAllocateInfo mem_alloc = {}; |
| 3227 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 3228 | mem_alloc.pNext = NULL; |
| 3229 | mem_alloc.allocationSize = 0; |
| 3230 | mem_alloc.memoryTypeIndex = 0; |
| 3231 | |
| 3232 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 3233 | ASSERT_VK_SUCCESS(err); |
| 3234 | |
| 3235 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 3236 | mem_alloc.allocationSize = mem_reqs.size; |
Mike Stroyan | 80fc6c3 | 2016-06-20 15:42:29 -0600 | [diff] [blame] | 3237 | |
| 3238 | // Introduce Failure, select invalid TypeIndex |
| 3239 | VkPhysicalDeviceMemoryProperties memory_info; |
| 3240 | |
| 3241 | vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info); |
| 3242 | unsigned int i; |
| 3243 | for (i = 0; i < memory_info.memoryTypeCount; i++) { |
| 3244 | if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) { |
| 3245 | mem_alloc.memoryTypeIndex = i; |
| 3246 | break; |
| 3247 | } |
| 3248 | } |
| 3249 | if (i >= memory_info.memoryTypeCount) { |
| 3250 | printf("No invalid memory type index could be found; skipped.\n"); |
| 3251 | vkDestroyImage(m_device->device(), image, NULL); |
| 3252 | return; |
| 3253 | } |
| 3254 | |
| 3255 | m_errorMonitor->SetDesiredFailureMsg( |
| 3256 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3257 | "for this object type are not compatible with the memory"); |
Mark Lobodzinski | bc18576 | 2016-06-15 16:28:53 -0600 | [diff] [blame] | 3258 | |
| 3259 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 3260 | ASSERT_VK_SUCCESS(err); |
| 3261 | |
| 3262 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 3263 | (void)err; |
| 3264 | |
| 3265 | m_errorMonitor->VerifyFound(); |
| 3266 | |
| 3267 | vkDestroyImage(m_device->device(), image, NULL); |
| 3268 | vkFreeMemory(m_device->device(), mem, NULL); |
| 3269 | } |
Mike Stroyan | 80fc6c3 | 2016-06-20 15:42:29 -0600 | [diff] [blame] | 3270 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3271 | TEST_F(VkLayerTest, BindInvalidMemory) { |
| 3272 | VkResult err; |
| 3273 | bool pass; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3274 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 3275 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3276 | "Invalid VkDeviceMemory Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 3277 | |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3278 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3279 | |
| 3280 | // 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] | 3281 | VkImage image; |
| 3282 | VkDeviceMemory mem; |
| 3283 | VkMemoryRequirements mem_reqs; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3284 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3285 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 3286 | const int32_t tex_width = 32; |
| 3287 | const int32_t tex_height = 32; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3288 | |
| 3289 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3290 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 3291 | image_create_info.pNext = NULL; |
| 3292 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 3293 | image_create_info.format = tex_format; |
| 3294 | image_create_info.extent.width = tex_width; |
| 3295 | image_create_info.extent.height = tex_height; |
| 3296 | image_create_info.extent.depth = 1; |
| 3297 | image_create_info.mipLevels = 1; |
| 3298 | image_create_info.arrayLayers = 1; |
| 3299 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 3300 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 3301 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 3302 | image_create_info.flags = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3303 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 3304 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3305 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 3306 | mem_alloc.pNext = NULL; |
| 3307 | mem_alloc.allocationSize = 0; |
| 3308 | mem_alloc.memoryTypeIndex = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3309 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 3310 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3311 | ASSERT_VK_SUCCESS(err); |
| 3312 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3313 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3314 | |
| 3315 | mem_alloc.allocationSize = mem_reqs.size; |
| 3316 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3317 | pass = |
| 3318 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 3319 | ASSERT_TRUE(pass); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3320 | |
| 3321 | // allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 3322 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3323 | ASSERT_VK_SUCCESS(err); |
| 3324 | |
| 3325 | // Introduce validation failure, free memory before binding |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 3326 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3327 | |
| 3328 | // Try to bind free memory that has been freed |
| 3329 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 3330 | // This may very well return an error. |
| 3331 | (void)err; |
| 3332 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 3333 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 3334 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 3335 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3336 | } |
| 3337 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3338 | TEST_F(VkLayerTest, BindMemoryToDestroyedObject) { |
| 3339 | VkResult err; |
| 3340 | bool pass; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3341 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3342 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3343 | "Invalid VkImage Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 3344 | |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3345 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3346 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3347 | // Create an image object, allocate memory, destroy the object and then try |
| 3348 | // to bind it |
| 3349 | VkImage image; |
| 3350 | VkDeviceMemory mem; |
| 3351 | VkMemoryRequirements mem_reqs; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3352 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3353 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 3354 | const int32_t tex_width = 32; |
| 3355 | const int32_t tex_height = 32; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3356 | |
| 3357 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3358 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 3359 | image_create_info.pNext = NULL; |
| 3360 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 3361 | image_create_info.format = tex_format; |
| 3362 | image_create_info.extent.width = tex_width; |
| 3363 | image_create_info.extent.height = tex_height; |
| 3364 | image_create_info.extent.depth = 1; |
| 3365 | image_create_info.mipLevels = 1; |
| 3366 | image_create_info.arrayLayers = 1; |
| 3367 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 3368 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 3369 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 3370 | image_create_info.flags = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3371 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 3372 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3373 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 3374 | mem_alloc.pNext = NULL; |
| 3375 | mem_alloc.allocationSize = 0; |
| 3376 | mem_alloc.memoryTypeIndex = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3377 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 3378 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3379 | ASSERT_VK_SUCCESS(err); |
| 3380 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3381 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3382 | |
| 3383 | mem_alloc.allocationSize = mem_reqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3384 | pass = |
| 3385 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 3386 | ASSERT_TRUE(pass); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3387 | |
| 3388 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 3389 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3390 | ASSERT_VK_SUCCESS(err); |
| 3391 | |
| 3392 | // Introduce validation failure, destroy Image object before binding |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 3393 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3394 | ASSERT_VK_SUCCESS(err); |
| 3395 | |
| 3396 | // Now Try to bind memory to this destroyed object |
| 3397 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 3398 | // This may very well return an error. |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3399 | (void)err; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3400 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 3401 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 3402 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 3403 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3404 | } |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 3405 | |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 3406 | #endif // OBJ_TRACKER_TESTS |
| 3407 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 3408 | #if DRAW_STATE_TESTS |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3409 | |
Chris Forbes | 48a5390 | 2016-06-30 11:46:27 +1200 | [diff] [blame] | 3410 | TEST_F(VkLayerTest, RenderPassInitialLayoutUndefined) { |
| 3411 | TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's " |
| 3412 | "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when " |
| 3413 | "the command buffer has prior knowledge of that " |
| 3414 | "attachment's layout."); |
| 3415 | |
| 3416 | m_errorMonitor->ExpectSuccess(); |
| 3417 | |
| 3418 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3419 | |
| 3420 | // A renderpass with one color attachment. |
| 3421 | VkAttachmentDescription attachment = { |
| 3422 | 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, |
| 3423 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_STORE, |
| 3424 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3425 | VK_IMAGE_LAYOUT_UNDEFINED, |
| 3426 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3427 | }; |
| 3428 | |
| 3429 | VkAttachmentReference att_ref = { |
| 3430 | 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3431 | }; |
| 3432 | |
| 3433 | VkSubpassDescription subpass = { |
| 3434 | 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, |
| 3435 | 1, &att_ref, nullptr, nullptr, 0, nullptr |
| 3436 | }; |
| 3437 | |
| 3438 | VkRenderPassCreateInfo rpci = { |
| 3439 | VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, |
| 3440 | 0, 1, &attachment, 1, &subpass, 0, nullptr |
| 3441 | }; |
| 3442 | |
| 3443 | VkRenderPass rp; |
| 3444 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp); |
| 3445 | ASSERT_VK_SUCCESS(err); |
| 3446 | |
| 3447 | // A compatible framebuffer. |
| 3448 | VkImageObj image(m_device); |
| 3449 | image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, |
| 3450 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, |
| 3451 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 3452 | ASSERT_TRUE(image.initialized()); |
| 3453 | |
| 3454 | VkImageViewCreateInfo ivci = { |
| 3455 | VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, nullptr, |
| 3456 | 0, image.handle(), VK_IMAGE_VIEW_TYPE_2D, VK_FORMAT_R8G8B8A8_UNORM, |
| 3457 | { |
| 3458 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3459 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3460 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3461 | VK_COMPONENT_SWIZZLE_IDENTITY |
| 3462 | }, |
| 3463 | { |
| 3464 | VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 |
| 3465 | }, |
| 3466 | }; |
| 3467 | VkImageView view; |
| 3468 | err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view); |
| 3469 | ASSERT_VK_SUCCESS(err); |
| 3470 | |
| 3471 | VkFramebufferCreateInfo fci = { |
| 3472 | VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, |
| 3473 | 0, rp, 1, &view, |
| 3474 | 32, 32, 1 |
| 3475 | }; |
| 3476 | VkFramebuffer fb; |
| 3477 | err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb); |
| 3478 | ASSERT_VK_SUCCESS(err); |
| 3479 | |
| 3480 | // Record a single command buffer which uses this renderpass twice. The |
| 3481 | // bug is triggered at the beginning of the second renderpass, when the |
| 3482 | // command buffer already has a layout recorded for the attachment. |
| 3483 | VkRenderPassBeginInfo rpbi = { |
| 3484 | VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, |
Tobin Ehlis | 0f9aa40 | 2016-07-01 08:47:12 -0600 | [diff] [blame] | 3485 | rp, fb, { { 0, 0 } , { 32, 32 } }, |
Chris Forbes | 48a5390 | 2016-06-30 11:46:27 +1200 | [diff] [blame] | 3486 | 0, nullptr |
| 3487 | }; |
| 3488 | BeginCommandBuffer(); |
| 3489 | vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, |
| 3490 | VK_SUBPASS_CONTENTS_INLINE); |
| 3491 | vkCmdEndRenderPass(m_commandBuffer->handle()); |
| 3492 | vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, |
| 3493 | VK_SUBPASS_CONTENTS_INLINE); |
| 3494 | |
| 3495 | m_errorMonitor->VerifyNotFound(); |
| 3496 | |
| 3497 | vkCmdEndRenderPass(m_commandBuffer->handle()); |
| 3498 | EndCommandBuffer(); |
| 3499 | |
| 3500 | vkDestroyFramebuffer(m_device->device(), fb, nullptr); |
| 3501 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3502 | vkDestroyImageView(m_device->device(), view, nullptr); |
| 3503 | } |
| 3504 | |
Chris Forbes | 51bf7c9 | 2016-06-30 15:22:08 +1200 | [diff] [blame] | 3505 | TEST_F(VkLayerTest, RenderPassSubpassZeroTransitionsApplied) { |
| 3506 | TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout " |
| 3507 | "transitions for the first subpass"); |
| 3508 | |
| 3509 | m_errorMonitor->ExpectSuccess(); |
| 3510 | |
| 3511 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3512 | |
| 3513 | // A renderpass with one color attachment. |
| 3514 | VkAttachmentDescription attachment = { |
| 3515 | 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, |
| 3516 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_STORE, |
| 3517 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3518 | VK_IMAGE_LAYOUT_UNDEFINED, |
| 3519 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3520 | }; |
| 3521 | |
| 3522 | VkAttachmentReference att_ref = { |
| 3523 | 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3524 | }; |
| 3525 | |
| 3526 | VkSubpassDescription subpass = { |
| 3527 | 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, |
| 3528 | 1, &att_ref, nullptr, nullptr, 0, nullptr |
| 3529 | }; |
| 3530 | |
| 3531 | VkSubpassDependency dep = { |
Chris Forbes | cb4c7ad | 2016-07-06 10:28:18 +1200 | [diff] [blame] | 3532 | 0, 0, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, |
| 3533 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, |
Chris Forbes | 51bf7c9 | 2016-06-30 15:22:08 +1200 | [diff] [blame] | 3534 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 3535 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 3536 | VK_DEPENDENCY_BY_REGION_BIT |
| 3537 | }; |
| 3538 | |
| 3539 | VkRenderPassCreateInfo rpci = { |
| 3540 | VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, |
| 3541 | 0, 1, &attachment, 1, &subpass, 1, &dep |
| 3542 | }; |
| 3543 | |
| 3544 | VkResult err; |
| 3545 | VkRenderPass rp; |
| 3546 | err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp); |
| 3547 | ASSERT_VK_SUCCESS(err); |
| 3548 | |
| 3549 | // A compatible framebuffer. |
| 3550 | VkImageObj image(m_device); |
| 3551 | image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, |
| 3552 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, |
| 3553 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 3554 | ASSERT_TRUE(image.initialized()); |
| 3555 | |
| 3556 | VkImageViewCreateInfo ivci = { |
| 3557 | VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, nullptr, |
| 3558 | 0, image.handle(), VK_IMAGE_VIEW_TYPE_2D, VK_FORMAT_R8G8B8A8_UNORM, |
| 3559 | { |
| 3560 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3561 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3562 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3563 | VK_COMPONENT_SWIZZLE_IDENTITY |
| 3564 | }, |
| 3565 | { |
| 3566 | VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 |
| 3567 | }, |
| 3568 | }; |
| 3569 | VkImageView view; |
| 3570 | err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view); |
| 3571 | ASSERT_VK_SUCCESS(err); |
| 3572 | |
| 3573 | VkFramebufferCreateInfo fci = { |
| 3574 | VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, |
| 3575 | 0, rp, 1, &view, |
| 3576 | 32, 32, 1 |
| 3577 | }; |
| 3578 | VkFramebuffer fb; |
| 3579 | err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb); |
| 3580 | ASSERT_VK_SUCCESS(err); |
| 3581 | |
| 3582 | // Record a single command buffer which issues a pipeline barrier w/ |
| 3583 | // image memory barrier for the attachment. This detects the previously |
| 3584 | // missing tracking of the subpass layout by throwing a validation error |
| 3585 | // if it doesn't occur. |
| 3586 | VkRenderPassBeginInfo rpbi = { |
| 3587 | VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, |
Tobin Ehlis | 0f9aa40 | 2016-07-01 08:47:12 -0600 | [diff] [blame] | 3588 | rp, fb, { { 0, 0 }, { 32, 32 } }, |
Chris Forbes | 51bf7c9 | 2016-06-30 15:22:08 +1200 | [diff] [blame] | 3589 | 0, nullptr |
| 3590 | }; |
| 3591 | BeginCommandBuffer(); |
| 3592 | vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, |
| 3593 | VK_SUBPASS_CONTENTS_INLINE); |
| 3594 | |
| 3595 | VkImageMemoryBarrier imb = { |
| 3596 | VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, nullptr, |
| 3597 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 3598 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 3599 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3600 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3601 | VK_QUEUE_FAMILY_IGNORED, VK_QUEUE_FAMILY_IGNORED, |
| 3602 | image.handle(), |
| 3603 | { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } |
| 3604 | }; |
| 3605 | vkCmdPipelineBarrier(m_commandBuffer->handle(), |
Chris Forbes | cb4c7ad | 2016-07-06 10:28:18 +1200 | [diff] [blame] | 3606 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, |
| 3607 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, |
Chris Forbes | 51bf7c9 | 2016-06-30 15:22:08 +1200 | [diff] [blame] | 3608 | VK_DEPENDENCY_BY_REGION_BIT, |
| 3609 | 0, nullptr, 0, nullptr, 1, &imb); |
| 3610 | |
| 3611 | vkCmdEndRenderPass(m_commandBuffer->handle()); |
| 3612 | m_errorMonitor->VerifyNotFound(); |
| 3613 | EndCommandBuffer(); |
| 3614 | |
| 3615 | vkDestroyFramebuffer(m_device->device(), fb, nullptr); |
| 3616 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3617 | vkDestroyImageView(m_device->device(), view, nullptr); |
| 3618 | } |
| 3619 | |
Chris Forbes | 6b3d3f4 | 2016-06-30 16:09:47 +1200 | [diff] [blame] | 3620 | TEST_F(VkLayerTest, RenderPassTransitionsAttachmentUnused) { |
| 3621 | TEST_DESCRIPTION("Ensure that layout transitions work correctly without " |
| 3622 | "errors, when an attachment reference is " |
| 3623 | "VK_ATTACHMENT_UNUSED"); |
| 3624 | |
| 3625 | m_errorMonitor->ExpectSuccess(); |
| 3626 | |
| 3627 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3628 | |
| 3629 | // A renderpass with no attachments |
| 3630 | VkAttachmentReference att_ref = { |
| 3631 | VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3632 | }; |
| 3633 | |
| 3634 | VkSubpassDescription subpass = { |
| 3635 | 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, |
| 3636 | 1, &att_ref, nullptr, nullptr, 0, nullptr |
| 3637 | }; |
| 3638 | |
| 3639 | VkRenderPassCreateInfo rpci = { |
| 3640 | VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, |
| 3641 | 0, 0, nullptr, 1, &subpass, 0, nullptr |
| 3642 | }; |
| 3643 | |
| 3644 | VkRenderPass rp; |
| 3645 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp); |
| 3646 | ASSERT_VK_SUCCESS(err); |
| 3647 | |
| 3648 | // A compatible framebuffer. |
| 3649 | VkFramebufferCreateInfo fci = { |
| 3650 | VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, |
| 3651 | 0, rp, 0, nullptr, |
| 3652 | 32, 32, 1 |
| 3653 | }; |
| 3654 | VkFramebuffer fb; |
| 3655 | err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb); |
| 3656 | ASSERT_VK_SUCCESS(err); |
| 3657 | |
| 3658 | // Record a command buffer which just begins and ends the renderpass. The |
| 3659 | // bug manifests in BeginRenderPass. |
| 3660 | VkRenderPassBeginInfo rpbi = { |
| 3661 | VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, |
Tobin Ehlis | 0f9aa40 | 2016-07-01 08:47:12 -0600 | [diff] [blame] | 3662 | rp, fb, { { 0, 0 }, { 32, 32 } }, |
Chris Forbes | 6b3d3f4 | 2016-06-30 16:09:47 +1200 | [diff] [blame] | 3663 | 0, nullptr |
| 3664 | }; |
| 3665 | BeginCommandBuffer(); |
| 3666 | vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, |
| 3667 | VK_SUBPASS_CONTENTS_INLINE); |
| 3668 | vkCmdEndRenderPass(m_commandBuffer->handle()); |
| 3669 | m_errorMonitor->VerifyNotFound(); |
| 3670 | EndCommandBuffer(); |
| 3671 | |
| 3672 | vkDestroyFramebuffer(m_device->device(), fb, nullptr); |
| 3673 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3674 | } |
| 3675 | |
Mark Lobodzinski | ce7eee7 | 2016-06-14 16:33:29 -0600 | [diff] [blame] | 3676 | // This is a positive test. No errors are expected. |
| 3677 | TEST_F(VkLayerTest, StencilLoadOp) { |
| 3678 | TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to " |
| 3679 | "CLEAR. stencil[Load|Store]Op used to be ignored."); |
| 3680 | VkResult result = VK_SUCCESS; |
| 3681 | VkImageFormatProperties formatProps; |
| 3682 | vkGetPhysicalDeviceImageFormatProperties( |
| 3683 | gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, |
| 3684 | VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 3685 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, |
| 3686 | 0, &formatProps); |
| 3687 | if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) { |
| 3688 | return; |
| 3689 | } |
| 3690 | |
| 3691 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3692 | VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT; |
| 3693 | m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt, |
| 3694 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 3695 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT); |
| 3696 | VkAttachmentDescription att = {}; |
| 3697 | VkAttachmentReference ref = {}; |
| 3698 | att.format = depth_stencil_fmt; |
| 3699 | att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 3700 | att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 3701 | att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 3702 | att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE; |
| 3703 | att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3704 | att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3705 | |
| 3706 | VkClearValue clear; |
| 3707 | clear.depthStencil.depth = 1.0; |
| 3708 | clear.depthStencil.stencil = 0; |
| 3709 | ref.attachment = 0; |
| 3710 | ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3711 | |
| 3712 | VkSubpassDescription subpass = {}; |
| 3713 | subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; |
| 3714 | subpass.flags = 0; |
| 3715 | subpass.inputAttachmentCount = 0; |
| 3716 | subpass.pInputAttachments = NULL; |
| 3717 | subpass.colorAttachmentCount = 0; |
| 3718 | subpass.pColorAttachments = NULL; |
| 3719 | subpass.pResolveAttachments = NULL; |
| 3720 | subpass.pDepthStencilAttachment = &ref; |
| 3721 | subpass.preserveAttachmentCount = 0; |
| 3722 | subpass.pPreserveAttachments = NULL; |
| 3723 | |
| 3724 | VkRenderPass rp; |
| 3725 | VkRenderPassCreateInfo rp_info = {}; |
| 3726 | rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 3727 | rp_info.attachmentCount = 1; |
| 3728 | rp_info.pAttachments = &att; |
| 3729 | rp_info.subpassCount = 1; |
| 3730 | rp_info.pSubpasses = &subpass; |
| 3731 | result = vkCreateRenderPass(device(), &rp_info, NULL, &rp); |
| 3732 | ASSERT_VK_SUCCESS(result); |
| 3733 | |
| 3734 | VkImageView *depthView = m_depthStencil->BindInfo(); |
| 3735 | VkFramebufferCreateInfo fb_info = {}; |
| 3736 | fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
| 3737 | fb_info.pNext = NULL; |
| 3738 | fb_info.renderPass = rp; |
| 3739 | fb_info.attachmentCount = 1; |
| 3740 | fb_info.pAttachments = depthView; |
| 3741 | fb_info.width = 100; |
| 3742 | fb_info.height = 100; |
| 3743 | fb_info.layers = 1; |
| 3744 | VkFramebuffer fb; |
| 3745 | result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3746 | ASSERT_VK_SUCCESS(result); |
| 3747 | |
| 3748 | |
| 3749 | VkRenderPassBeginInfo rpbinfo = {}; |
| 3750 | rpbinfo.clearValueCount = 1; |
| 3751 | rpbinfo.pClearValues = &clear; |
| 3752 | rpbinfo.pNext = NULL; |
| 3753 | rpbinfo.renderPass = rp; |
| 3754 | rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 3755 | rpbinfo.renderArea.extent.width = 100; |
| 3756 | rpbinfo.renderArea.extent.height = 100; |
| 3757 | rpbinfo.renderArea.offset.x = 0; |
| 3758 | rpbinfo.renderArea.offset.y = 0; |
| 3759 | rpbinfo.framebuffer = fb; |
| 3760 | |
| 3761 | VkFence fence = {}; |
| 3762 | VkFenceCreateInfo fence_ci = {}; |
| 3763 | fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3764 | fence_ci.pNext = nullptr; |
| 3765 | fence_ci.flags = 0; |
| 3766 | result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence); |
| 3767 | ASSERT_VK_SUCCESS(result); |
| 3768 | |
| 3769 | |
| 3770 | m_commandBuffer->BeginCommandBuffer(); |
| 3771 | m_commandBuffer->BeginRenderPass(rpbinfo); |
| 3772 | m_commandBuffer->EndRenderPass(); |
| 3773 | m_commandBuffer->EndCommandBuffer(); |
| 3774 | m_commandBuffer->QueueCommandBuffer(fence); |
| 3775 | |
| 3776 | VkImageObj destImage(m_device); |
| 3777 | destImage.init(100, 100, depth_stencil_fmt, |
| 3778 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 3779 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 3780 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 3781 | VkImageMemoryBarrier barrier = {}; |
| 3782 | VkImageSubresourceRange range; |
| 3783 | barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 3784 | barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | |
| 3785 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; |
| 3786 | barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | |
| 3787 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT; |
| 3788 | barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3789 | barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 3790 | barrier.image = m_depthStencil->handle(); |
| 3791 | range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3792 | range.baseMipLevel = 0; |
| 3793 | range.levelCount = 1; |
| 3794 | range.baseArrayLayer = 0; |
| 3795 | range.layerCount = 1; |
| 3796 | barrier.subresourceRange = range; |
| 3797 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 3798 | VkCommandBufferObj cmdbuf(m_device, m_commandPool); |
| 3799 | cmdbuf.BeginCommandBuffer(); |
| 3800 | cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3801 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, |
| 3802 | nullptr, 1, &barrier); |
| 3803 | barrier.srcAccessMask = 0; |
| 3804 | barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 3805 | barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; |
| 3806 | barrier.image = destImage.handle(); |
| 3807 | barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | |
| 3808 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; |
| 3809 | cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3810 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, |
| 3811 | nullptr, 1, &barrier); |
| 3812 | VkImageCopy cregion; |
| 3813 | cregion.srcSubresource.aspectMask = |
| 3814 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3815 | cregion.srcSubresource.mipLevel = 0; |
| 3816 | cregion.srcSubresource.baseArrayLayer = 0; |
| 3817 | cregion.srcSubresource.layerCount = 1; |
| 3818 | cregion.srcOffset.x = 0; |
| 3819 | cregion.srcOffset.y = 0; |
| 3820 | cregion.srcOffset.z = 0; |
| 3821 | cregion.dstSubresource.aspectMask = |
| 3822 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3823 | cregion.dstSubresource.mipLevel = 0; |
| 3824 | cregion.dstSubresource.baseArrayLayer = 0; |
| 3825 | cregion.dstSubresource.layerCount = 1; |
| 3826 | cregion.dstOffset.x = 0; |
| 3827 | cregion.dstOffset.y = 0; |
| 3828 | cregion.dstOffset.z = 0; |
| 3829 | cregion.extent.width = 100; |
| 3830 | cregion.extent.height = 100; |
| 3831 | cregion.extent.depth = 1; |
| 3832 | cmdbuf.CopyImage(m_depthStencil->handle(), |
| 3833 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(), |
| 3834 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion); |
| 3835 | cmdbuf.EndCommandBuffer(); |
| 3836 | |
| 3837 | VkSubmitInfo submit_info; |
| 3838 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3839 | submit_info.pNext = NULL; |
| 3840 | submit_info.waitSemaphoreCount = 0; |
| 3841 | submit_info.pWaitSemaphores = NULL; |
| 3842 | submit_info.pWaitDstStageMask = NULL; |
| 3843 | submit_info.commandBufferCount = 1; |
| 3844 | submit_info.pCommandBuffers = &cmdbuf.handle(); |
| 3845 | submit_info.signalSemaphoreCount = 0; |
| 3846 | submit_info.pSignalSemaphores = NULL; |
| 3847 | |
| 3848 | m_errorMonitor->ExpectSuccess(); |
| 3849 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3850 | m_errorMonitor->VerifyNotFound(); |
| 3851 | |
Mark Lobodzinski | d0440da | 2016-06-17 15:10:03 -0600 | [diff] [blame] | 3852 | vkQueueWaitIdle(m_device->m_queue); |
Mark Lobodzinski | ce7eee7 | 2016-06-14 16:33:29 -0600 | [diff] [blame] | 3853 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 3854 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3855 | vkDestroyFramebuffer(m_device->device(), fb, nullptr); |
| 3856 | } |
| 3857 | |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3858 | TEST_F(VkLayerTest, UnusedPreserveAttachment) { |
| 3859 | TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve " |
| 3860 | "attachment reference of VK_ATTACHMENT_UNUSED"); |
| 3861 | |
| 3862 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3863 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 3864 | |
| 3865 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3866 | "must not be VK_ATTACHMENT_UNUSED"); |
| 3867 | |
| 3868 | VkAttachmentReference color_attach = {}; |
| 3869 | color_attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 3870 | color_attach.attachment = 0; |
| 3871 | uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED; |
| 3872 | VkSubpassDescription subpass = {}; |
| 3873 | subpass.colorAttachmentCount = 1; |
| 3874 | subpass.pColorAttachments = &color_attach; |
| 3875 | subpass.preserveAttachmentCount = 1; |
| 3876 | subpass.pPreserveAttachments = &preserve_attachment; |
| 3877 | |
| 3878 | VkRenderPassCreateInfo rpci = {}; |
| 3879 | rpci.subpassCount = 1; |
| 3880 | rpci.pSubpasses = &subpass; |
| 3881 | rpci.attachmentCount = 1; |
| 3882 | VkAttachmentDescription attach_desc = {}; |
| 3883 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 3884 | rpci.pAttachments = &attach_desc; |
| 3885 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 3886 | VkRenderPass rp; |
Mark Lobodzinski | a4feeeb | 2016-06-17 12:00:46 -0600 | [diff] [blame] | 3887 | VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3888 | |
| 3889 | m_errorMonitor->VerifyFound(); |
| 3890 | |
Mark Lobodzinski | a4feeeb | 2016-06-17 12:00:46 -0600 | [diff] [blame] | 3891 | if (result == VK_SUCCESS) { |
| 3892 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 3893 | } |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3894 | } |
| 3895 | |
Chris Forbes | c538974 | 2016-06-29 11:49:23 +1200 | [diff] [blame] | 3896 | TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) { |
Chris Forbes | 6655bb3 | 2016-07-01 18:27:30 +1200 | [diff] [blame] | 3897 | TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error " |
| 3898 | "when the source of a subpass multisample resolve " |
| 3899 | "does not have multiple samples."); |
| 3900 | |
Chris Forbes | c538974 | 2016-06-29 11:49:23 +1200 | [diff] [blame] | 3901 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3902 | |
| 3903 | m_errorMonitor->SetDesiredFailureMsg( |
| 3904 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | 6655bb3 | 2016-07-01 18:27:30 +1200 | [diff] [blame] | 3905 | "Subpass 0 requests multisample resolve from attachment 0 which has " |
| 3906 | "VK_SAMPLE_COUNT_1_BIT"); |
Chris Forbes | c538974 | 2016-06-29 11:49:23 +1200 | [diff] [blame] | 3907 | |
| 3908 | VkAttachmentDescription attachments[] = { |
| 3909 | { |
| 3910 | 0, VK_FORMAT_R8G8B8A8_UNORM, |
| 3911 | VK_SAMPLE_COUNT_1_BIT, |
| 3912 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3913 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3914 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3915 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3916 | }, |
| 3917 | { |
| 3918 | 0, VK_FORMAT_R8G8B8A8_UNORM, |
| 3919 | VK_SAMPLE_COUNT_1_BIT, |
| 3920 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3921 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3922 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3923 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3924 | }, |
| 3925 | }; |
| 3926 | |
| 3927 | VkAttachmentReference color = { |
| 3928 | 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3929 | }; |
| 3930 | |
| 3931 | VkAttachmentReference resolve = { |
| 3932 | 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3933 | }; |
| 3934 | |
| 3935 | VkSubpassDescription subpass = { |
| 3936 | 0, VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 3937 | 0, nullptr, |
| 3938 | 1, &color, |
| 3939 | &resolve, |
| 3940 | nullptr, |
| 3941 | 0, nullptr |
| 3942 | }; |
| 3943 | |
| 3944 | VkRenderPassCreateInfo rpci = { |
| 3945 | VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, |
| 3946 | 0, 2, attachments, 1, &subpass, 0, nullptr |
| 3947 | }; |
| 3948 | |
| 3949 | VkRenderPass rp; |
| 3950 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp); |
| 3951 | |
| 3952 | m_errorMonitor->VerifyFound(); |
| 3953 | |
| 3954 | if (err == VK_SUCCESS) |
| 3955 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3956 | } |
| 3957 | |
| 3958 | TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) { |
Chris Forbes | 6655bb3 | 2016-07-01 18:27:30 +1200 | [diff] [blame] | 3959 | TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error " |
| 3960 | "when a subpass multisample resolve operation is " |
| 3961 | "requested, and the destination of that resolve has " |
| 3962 | "multiple samples."); |
| 3963 | |
Chris Forbes | c538974 | 2016-06-29 11:49:23 +1200 | [diff] [blame] | 3964 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3965 | |
| 3966 | m_errorMonitor->SetDesiredFailureMsg( |
| 3967 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3968 | "Subpass 0 requests multisample resolve into attachment 1, which " |
| 3969 | "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT"); |
| 3970 | |
| 3971 | VkAttachmentDescription attachments[] = { |
| 3972 | { |
| 3973 | 0, VK_FORMAT_R8G8B8A8_UNORM, |
| 3974 | VK_SAMPLE_COUNT_4_BIT, |
| 3975 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3976 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3977 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3978 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3979 | }, |
| 3980 | { |
| 3981 | 0, VK_FORMAT_R8G8B8A8_UNORM, |
| 3982 | VK_SAMPLE_COUNT_4_BIT, |
| 3983 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3984 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3985 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3986 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3987 | }, |
| 3988 | }; |
| 3989 | |
| 3990 | VkAttachmentReference color = { |
| 3991 | 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3992 | }; |
| 3993 | |
| 3994 | VkAttachmentReference resolve = { |
| 3995 | 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3996 | }; |
| 3997 | |
| 3998 | VkSubpassDescription subpass = { |
| 3999 | 0, VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 4000 | 0, nullptr, |
| 4001 | 1, &color, |
| 4002 | &resolve, |
| 4003 | nullptr, |
| 4004 | 0, nullptr |
| 4005 | }; |
| 4006 | |
| 4007 | VkRenderPassCreateInfo rpci = { |
| 4008 | VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, |
| 4009 | 0, 2, attachments, 1, &subpass, 0, nullptr |
| 4010 | }; |
| 4011 | |
| 4012 | VkRenderPass rp; |
| 4013 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp); |
| 4014 | |
| 4015 | m_errorMonitor->VerifyFound(); |
| 4016 | |
| 4017 | if (err == VK_SUCCESS) |
| 4018 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 4019 | } |
| 4020 | |
Chris Forbes | 3f128ef | 2016-06-29 14:58:53 +1200 | [diff] [blame] | 4021 | TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) { |
Chris Forbes | 6655bb3 | 2016-07-01 18:27:30 +1200 | [diff] [blame] | 4022 | TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error " |
| 4023 | "when the color and depth attachments used by a subpass " |
| 4024 | "have inconsistent sample counts"); |
| 4025 | |
Chris Forbes | 3f128ef | 2016-06-29 14:58:53 +1200 | [diff] [blame] | 4026 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4027 | |
| 4028 | m_errorMonitor->SetDesiredFailureMsg( |
| 4029 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4030 | "Subpass 0 attempts to render to attachments with inconsistent sample counts"); |
| 4031 | |
| 4032 | VkAttachmentDescription attachments[] = { |
| 4033 | { |
| 4034 | 0, VK_FORMAT_R8G8B8A8_UNORM, |
| 4035 | VK_SAMPLE_COUNT_1_BIT, |
| 4036 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 4037 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 4038 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 4039 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 4040 | }, |
| 4041 | { |
| 4042 | 0, VK_FORMAT_R8G8B8A8_UNORM, |
| 4043 | VK_SAMPLE_COUNT_4_BIT, |
| 4044 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 4045 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 4046 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 4047 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 4048 | }, |
| 4049 | }; |
| 4050 | |
| 4051 | VkAttachmentReference color[] = { |
| 4052 | { |
| 4053 | 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 4054 | }, |
| 4055 | { |
| 4056 | 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 4057 | }, |
| 4058 | }; |
| 4059 | |
| 4060 | VkSubpassDescription subpass = { |
| 4061 | 0, VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 4062 | 0, nullptr, |
| 4063 | 2, color, |
| 4064 | nullptr, |
| 4065 | nullptr, |
| 4066 | 0, nullptr |
| 4067 | }; |
| 4068 | |
| 4069 | VkRenderPassCreateInfo rpci = { |
| 4070 | VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, |
| 4071 | 0, 2, attachments, 1, &subpass, 0, nullptr |
| 4072 | }; |
| 4073 | |
| 4074 | VkRenderPass rp; |
| 4075 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp); |
| 4076 | |
| 4077 | m_errorMonitor->VerifyFound(); |
| 4078 | |
| 4079 | if (err == VK_SUCCESS) |
| 4080 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 4081 | } |
| 4082 | |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 4083 | TEST_F(VkLayerTest, FramebufferCreateErrors) { |
| 4084 | TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n" |
| 4085 | " 1. Mismatch between fb & renderPass attachmentCount\n" |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 4086 | " 2. Use a color image as depthStencil attachment\n" |
Tobin Ehlis | 77d717c | 2016-06-22 14:19:19 -0600 | [diff] [blame] | 4087 | " 3. Mismatch fb & renderPass attachment formats\n" |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 4088 | " 4. Mismatch fb & renderPass attachment #samples\n" |
Tobin Ehlis | 27f2ae8 | 2016-06-23 07:36:57 -0600 | [diff] [blame] | 4089 | " 5. FB attachment w/ non-1 mip-levels\n" |
Tobin Ehlis | b1f303b | 2016-06-23 08:19:55 -0600 | [diff] [blame] | 4090 | " 6. FB attachment where dimensions don't match\n" |
Tobin Ehlis | 08d4b5e | 2016-06-23 08:52:39 -0600 | [diff] [blame] | 4091 | " 7. FB attachment w/o identity swizzle\n" |
| 4092 | " 8. FB dimensions exceed physical device limits\n"); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 4093 | |
| 4094 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4095 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 4096 | |
| 4097 | m_errorMonitor->SetDesiredFailureMsg( |
| 4098 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 4099 | "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 " |
| 4100 | "does not match attachmentCount of 1 of "); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 4101 | |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 4102 | // Create a renderPass with a single color attachment |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 4103 | VkAttachmentReference attach = {}; |
| 4104 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 4105 | VkSubpassDescription subpass = {}; |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 4106 | subpass.pColorAttachments = &attach; |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 4107 | VkRenderPassCreateInfo rpci = {}; |
| 4108 | rpci.subpassCount = 1; |
| 4109 | rpci.pSubpasses = &subpass; |
| 4110 | rpci.attachmentCount = 1; |
| 4111 | VkAttachmentDescription attach_desc = {}; |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 4112 | attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM; |
Tobin Ehlis | 77d717c | 2016-06-22 14:19:19 -0600 | [diff] [blame] | 4113 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 4114 | rpci.pAttachments = &attach_desc; |
| 4115 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 4116 | VkRenderPass rp; |
| 4117 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 4118 | ASSERT_VK_SUCCESS(err); |
| 4119 | |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 4120 | VkImageView ivs[2]; |
| 4121 | ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM); |
| 4122 | ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 4123 | VkFramebufferCreateInfo fb_info = {}; |
| 4124 | fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
| 4125 | fb_info.pNext = NULL; |
| 4126 | fb_info.renderPass = rp; |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 4127 | // Set mis-matching attachmentCount |
| 4128 | fb_info.attachmentCount = 2; |
| 4129 | fb_info.pAttachments = ivs; |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 4130 | fb_info.width = 100; |
| 4131 | fb_info.height = 100; |
| 4132 | fb_info.layers = 1; |
| 4133 | |
| 4134 | VkFramebuffer fb; |
| 4135 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 4136 | |
| 4137 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 4138 | if (err == VK_SUCCESS) { |
| 4139 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 4140 | } |
| 4141 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 4142 | |
| 4143 | // Create a renderPass with a depth-stencil attachment created with |
| 4144 | // IMAGE_USAGE_COLOR_ATTACHMENT |
| 4145 | // Add our color attachment to pDepthStencilAttachment |
| 4146 | subpass.pDepthStencilAttachment = &attach; |
| 4147 | subpass.pColorAttachments = NULL; |
| 4148 | VkRenderPass rp_ds; |
| 4149 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds); |
| 4150 | ASSERT_VK_SUCCESS(err); |
| 4151 | // Set correct attachment count, but attachment has COLOR usage bit set |
| 4152 | fb_info.attachmentCount = 1; |
| 4153 | fb_info.renderPass = rp_ds; |
| 4154 | |
| 4155 | m_errorMonitor->SetDesiredFailureMsg( |
| 4156 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4157 | " conflicts with the image's IMAGE_USAGE flags "); |
| 4158 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 4159 | |
| 4160 | m_errorMonitor->VerifyFound(); |
| 4161 | if (err == VK_SUCCESS) { |
| 4162 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 4163 | } |
| 4164 | vkDestroyRenderPass(m_device->device(), rp_ds, NULL); |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 4165 | |
| 4166 | // Create new renderpass with alternate attachment format from fb |
| 4167 | attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 4168 | subpass.pDepthStencilAttachment = NULL; |
| 4169 | subpass.pColorAttachments = &attach; |
| 4170 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 4171 | ASSERT_VK_SUCCESS(err); |
| 4172 | |
| 4173 | // Cause error due to mis-matched formats between rp & fb |
| 4174 | // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8 |
| 4175 | fb_info.renderPass = rp; |
| 4176 | m_errorMonitor->SetDesiredFailureMsg( |
| 4177 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4178 | " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match "); |
| 4179 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 4180 | |
| 4181 | m_errorMonitor->VerifyFound(); |
| 4182 | if (err == VK_SUCCESS) { |
| 4183 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 4184 | } |
Tobin Ehlis | 77d717c | 2016-06-22 14:19:19 -0600 | [diff] [blame] | 4185 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 4186 | |
| 4187 | // Create new renderpass with alternate sample count from fb |
| 4188 | attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 4189 | attach_desc.samples = VK_SAMPLE_COUNT_4_BIT; |
| 4190 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 4191 | ASSERT_VK_SUCCESS(err); |
| 4192 | |
| 4193 | // Cause error due to mis-matched sample count between rp & fb |
| 4194 | fb_info.renderPass = rp; |
| 4195 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4196 | " has VK_SAMPLE_COUNT_1_BIT samples " |
| 4197 | "that do not match the " |
| 4198 | "VK_SAMPLE_COUNT_4_BIT "); |
| 4199 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 4200 | |
| 4201 | m_errorMonitor->VerifyFound(); |
| 4202 | if (err == VK_SUCCESS) { |
| 4203 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 4204 | } |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 4205 | |
| 4206 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 4207 | |
| 4208 | // Create a custom imageView with non-1 mip levels |
| 4209 | VkImageObj image(m_device); |
| 4210 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 4211 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 4212 | ASSERT_TRUE(image.initialized()); |
| 4213 | |
| 4214 | VkImageView view; |
| 4215 | VkImageViewCreateInfo ivci = {}; |
| 4216 | ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 4217 | ivci.image = image.handle(); |
| 4218 | ivci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 4219 | ivci.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 4220 | ivci.subresourceRange.layerCount = 1; |
| 4221 | ivci.subresourceRange.baseMipLevel = 0; |
| 4222 | // Set level count 2 (only 1 is allowed for FB attachment) |
| 4223 | ivci.subresourceRange.levelCount = 2; |
| 4224 | ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 4225 | err = vkCreateImageView(m_device->device(), &ivci, NULL, &view); |
| 4226 | ASSERT_VK_SUCCESS(err); |
| 4227 | // Re-create renderpass to have matching sample count |
| 4228 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
| 4229 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 4230 | ASSERT_VK_SUCCESS(err); |
| 4231 | |
| 4232 | fb_info.renderPass = rp; |
| 4233 | fb_info.pAttachments = &view; |
| 4234 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4235 | " has mip levelCount of 2 but only "); |
| 4236 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 4237 | |
| 4238 | m_errorMonitor->VerifyFound(); |
| 4239 | if (err == VK_SUCCESS) { |
| 4240 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 4241 | } |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 4242 | vkDestroyImageView(m_device->device(), view, NULL); |
Tobin Ehlis | 27f2ae8 | 2016-06-23 07:36:57 -0600 | [diff] [blame] | 4243 | // Update view to original color buffer and grow FB dimensions too big |
| 4244 | fb_info.pAttachments = ivs; |
| 4245 | fb_info.height = 1024; |
| 4246 | fb_info.width = 1024; |
| 4247 | fb_info.layers = 2; |
| 4248 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4249 | " Attachment dimensions must be at " |
| 4250 | "least as large. "); |
| 4251 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 4252 | |
| 4253 | m_errorMonitor->VerifyFound(); |
| 4254 | if (err == VK_SUCCESS) { |
| 4255 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 4256 | } |
Tobin Ehlis | b1f303b | 2016-06-23 08:19:55 -0600 | [diff] [blame] | 4257 | // Create view attachment with non-identity swizzle |
| 4258 | ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 4259 | ivci.image = image.handle(); |
| 4260 | ivci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 4261 | ivci.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 4262 | ivci.subresourceRange.layerCount = 1; |
| 4263 | ivci.subresourceRange.baseMipLevel = 0; |
| 4264 | ivci.subresourceRange.levelCount = 1; |
| 4265 | ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 4266 | ivci.components.r = VK_COMPONENT_SWIZZLE_G; |
| 4267 | ivci.components.g = VK_COMPONENT_SWIZZLE_R; |
| 4268 | ivci.components.b = VK_COMPONENT_SWIZZLE_A; |
| 4269 | ivci.components.a = VK_COMPONENT_SWIZZLE_B; |
| 4270 | err = vkCreateImageView(m_device->device(), &ivci, NULL, &view); |
| 4271 | ASSERT_VK_SUCCESS(err); |
| 4272 | |
| 4273 | fb_info.pAttachments = &view; |
| 4274 | fb_info.height = 100; |
| 4275 | fb_info.width = 100; |
| 4276 | fb_info.layers = 1; |
| 4277 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4278 | " has non-identy swizzle. All " |
| 4279 | "framebuffer attachments must have " |
| 4280 | "been created with the identity " |
| 4281 | "swizzle. "); |
| 4282 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 4283 | |
| 4284 | m_errorMonitor->VerifyFound(); |
| 4285 | if (err == VK_SUCCESS) { |
| 4286 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 4287 | } |
| 4288 | vkDestroyImageView(m_device->device(), view, NULL); |
Tobin Ehlis | 08d4b5e | 2016-06-23 08:52:39 -0600 | [diff] [blame] | 4289 | // Request fb that exceeds max dimensions |
| 4290 | // reset attachment to color attachment |
| 4291 | fb_info.pAttachments = ivs; |
| 4292 | fb_info.width = m_device->props.limits.maxFramebufferWidth + 1; |
| 4293 | fb_info.height = m_device->props.limits.maxFramebufferHeight + 1; |
| 4294 | fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1; |
| 4295 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4296 | " Requested VkFramebufferCreateInfo " |
| 4297 | "dimensions exceed physical device " |
| 4298 | "limits. "); |
| 4299 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 4300 | |
| 4301 | m_errorMonitor->VerifyFound(); |
| 4302 | if (err == VK_SUCCESS) { |
| 4303 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 4304 | } |
Tobin Ehlis | 27f2ae8 | 2016-06-23 07:36:57 -0600 | [diff] [blame] | 4305 | |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 4306 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 4307 | } |
| 4308 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4309 | // This is a positive test. No errors should be generated. |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 4310 | TEST_F(VkLayerTest, WaitEventThenSet) { |
| 4311 | TEST_DESCRIPTION( |
| 4312 | "Wait on a event then set it after the wait has been submitted."); |
| 4313 | |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 4314 | m_errorMonitor->ExpectSuccess(); |
| 4315 | |
| 4316 | VkEvent event; |
| 4317 | VkEventCreateInfo event_create_info{}; |
| 4318 | event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 4319 | vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event); |
| 4320 | |
| 4321 | VkCommandPool command_pool; |
| 4322 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4323 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4324 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4325 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4326 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4327 | &command_pool); |
| 4328 | |
| 4329 | VkCommandBuffer command_buffer; |
| 4330 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4331 | command_buffer_allocate_info.sType = |
| 4332 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4333 | command_buffer_allocate_info.commandPool = command_pool; |
| 4334 | command_buffer_allocate_info.commandBufferCount = 1; |
| 4335 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4336 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4337 | &command_buffer); |
| 4338 | |
| 4339 | VkQueue queue = VK_NULL_HANDLE; |
| 4340 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
Tony Barbour | fe302c0 | 2016-06-06 13:05:19 -0600 | [diff] [blame] | 4341 | 0, &queue); |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 4342 | |
| 4343 | { |
| 4344 | VkCommandBufferBeginInfo begin_info{}; |
| 4345 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4346 | vkBeginCommandBuffer(command_buffer, &begin_info); |
| 4347 | |
| 4348 | vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, |
| 4349 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, |
| 4350 | nullptr, 0, nullptr); |
| 4351 | vkCmdResetEvent(command_buffer, event, |
| 4352 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 4353 | vkEndCommandBuffer(command_buffer); |
| 4354 | } |
| 4355 | { |
| 4356 | VkSubmitInfo submit_info{}; |
| 4357 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4358 | submit_info.commandBufferCount = 1; |
| 4359 | submit_info.pCommandBuffers = &command_buffer; |
| 4360 | submit_info.signalSemaphoreCount = 0; |
| 4361 | submit_info.pSignalSemaphores = nullptr; |
| 4362 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4363 | } |
| 4364 | { vkSetEvent(m_device->device(), event); } |
| 4365 | |
| 4366 | vkQueueWaitIdle(queue); |
| 4367 | |
| 4368 | vkDestroyEvent(m_device->device(), event, nullptr); |
| 4369 | vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer); |
| 4370 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4371 | |
| 4372 | m_errorMonitor->VerifyNotFound(); |
| 4373 | } |
Michael Lentine | 5627e69 | 2016-05-20 17:45:02 -0500 | [diff] [blame] | 4374 | // This is a positive test. No errors should be generated. |
| 4375 | TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) { |
| 4376 | TEST_DESCRIPTION( |
| 4377 | "Issue a query and copy from it on a second command buffer."); |
| 4378 | |
| 4379 | if ((m_device->queue_props.empty()) || |
| 4380 | (m_device->queue_props[0].queueCount < 2)) |
| 4381 | return; |
| 4382 | |
| 4383 | m_errorMonitor->ExpectSuccess(); |
| 4384 | |
| 4385 | VkQueryPool query_pool; |
| 4386 | VkQueryPoolCreateInfo query_pool_create_info{}; |
| 4387 | query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; |
| 4388 | query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP; |
| 4389 | query_pool_create_info.queryCount = 1; |
| 4390 | vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, |
| 4391 | &query_pool); |
| 4392 | |
| 4393 | VkCommandPool command_pool; |
| 4394 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4395 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4396 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4397 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4398 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4399 | &command_pool); |
| 4400 | |
| 4401 | VkCommandBuffer command_buffer[2]; |
| 4402 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4403 | command_buffer_allocate_info.sType = |
| 4404 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4405 | command_buffer_allocate_info.commandPool = command_pool; |
| 4406 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4407 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4408 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4409 | command_buffer); |
| 4410 | |
| 4411 | VkQueue queue = VK_NULL_HANDLE; |
| 4412 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4413 | 1, &queue); |
| 4414 | |
| 4415 | uint32_t qfi = 0; |
| 4416 | VkBufferCreateInfo buff_create_info = {}; |
| 4417 | buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 4418 | buff_create_info.size = 1024; |
| 4419 | buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT; |
| 4420 | buff_create_info.queueFamilyIndexCount = 1; |
| 4421 | buff_create_info.pQueueFamilyIndices = &qfi; |
| 4422 | |
| 4423 | VkResult err; |
| 4424 | VkBuffer buffer; |
| 4425 | err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer); |
| 4426 | ASSERT_VK_SUCCESS(err); |
| 4427 | VkMemoryAllocateInfo mem_alloc = {}; |
| 4428 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 4429 | mem_alloc.pNext = NULL; |
| 4430 | mem_alloc.allocationSize = 1024; |
| 4431 | mem_alloc.memoryTypeIndex = 0; |
| 4432 | |
| 4433 | VkMemoryRequirements memReqs; |
| 4434 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs); |
| 4435 | bool pass = |
| 4436 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0); |
| 4437 | if (!pass) { |
| 4438 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 4439 | return; |
| 4440 | } |
| 4441 | |
| 4442 | VkDeviceMemory mem; |
| 4443 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 4444 | ASSERT_VK_SUCCESS(err); |
| 4445 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 4446 | ASSERT_VK_SUCCESS(err); |
| 4447 | |
| 4448 | { |
| 4449 | VkCommandBufferBeginInfo begin_info{}; |
| 4450 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4451 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4452 | |
| 4453 | vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1); |
| 4454 | vkCmdWriteTimestamp(command_buffer[0], |
| 4455 | VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0); |
| 4456 | |
| 4457 | vkEndCommandBuffer(command_buffer[0]); |
| 4458 | |
| 4459 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4460 | |
| 4461 | vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, |
| 4462 | 0, 0, 0); |
| 4463 | |
| 4464 | vkEndCommandBuffer(command_buffer[1]); |
| 4465 | } |
| 4466 | { |
| 4467 | VkSubmitInfo submit_info{}; |
| 4468 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4469 | submit_info.commandBufferCount = 2; |
| 4470 | submit_info.pCommandBuffers = command_buffer; |
| 4471 | submit_info.signalSemaphoreCount = 0; |
| 4472 | submit_info.pSignalSemaphores = nullptr; |
| 4473 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4474 | } |
| 4475 | |
| 4476 | vkQueueWaitIdle(queue); |
| 4477 | |
| 4478 | vkDestroyQueryPool(m_device->device(), query_pool, nullptr); |
| 4479 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer); |
| 4480 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 4481 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 4482 | vkFreeMemory(m_device->device(), mem, NULL); |
Michael Lentine | 5627e69 | 2016-05-20 17:45:02 -0500 | [diff] [blame] | 4483 | |
| 4484 | m_errorMonitor->VerifyNotFound(); |
| 4485 | } |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 4486 | |
| 4487 | TEST_F(VkLayerTest, ResetEventThenSet) { |
| 4488 | TEST_DESCRIPTION( |
| 4489 | "Reset an event then set it after the reset has been submitted."); |
| 4490 | |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 4491 | m_errorMonitor->ExpectSuccess(); |
| 4492 | |
| 4493 | VkEvent event; |
| 4494 | VkEventCreateInfo event_create_info{}; |
| 4495 | event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 4496 | vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event); |
| 4497 | |
| 4498 | VkCommandPool command_pool; |
| 4499 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4500 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4501 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4502 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4503 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4504 | &command_pool); |
| 4505 | |
| 4506 | VkCommandBuffer command_buffer; |
| 4507 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4508 | command_buffer_allocate_info.sType = |
| 4509 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4510 | command_buffer_allocate_info.commandPool = command_pool; |
| 4511 | command_buffer_allocate_info.commandBufferCount = 1; |
| 4512 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4513 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4514 | &command_buffer); |
| 4515 | |
| 4516 | VkQueue queue = VK_NULL_HANDLE; |
| 4517 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
Tony Barbour | fe302c0 | 2016-06-06 13:05:19 -0600 | [diff] [blame] | 4518 | 0, &queue); |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 4519 | |
| 4520 | { |
| 4521 | VkCommandBufferBeginInfo begin_info{}; |
| 4522 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4523 | vkBeginCommandBuffer(command_buffer, &begin_info); |
| 4524 | |
| 4525 | vkCmdResetEvent(command_buffer, event, |
| 4526 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 4527 | vkCmdWaitEvents(command_buffer, 1, &event, |
| 4528 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4529 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, |
| 4530 | nullptr, 0, nullptr); |
| 4531 | vkEndCommandBuffer(command_buffer); |
| 4532 | } |
| 4533 | { |
| 4534 | VkSubmitInfo submit_info{}; |
| 4535 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4536 | submit_info.commandBufferCount = 1; |
| 4537 | submit_info.pCommandBuffers = &command_buffer; |
| 4538 | submit_info.signalSemaphoreCount = 0; |
| 4539 | submit_info.pSignalSemaphores = nullptr; |
| 4540 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4541 | } |
| 4542 | { |
| 4543 | m_errorMonitor->SetDesiredFailureMsg( |
| 4544 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkSetEvent() on event " |
| 4545 | "0x1 that is already in use by a " |
| 4546 | "command buffer."); |
| 4547 | vkSetEvent(m_device->device(), event); |
| 4548 | m_errorMonitor->VerifyFound(); |
| 4549 | } |
| 4550 | |
| 4551 | vkQueueWaitIdle(queue); |
| 4552 | |
| 4553 | vkDestroyEvent(m_device->device(), event, nullptr); |
| 4554 | vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer); |
| 4555 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4556 | } |
| 4557 | |
| 4558 | // This is a positive test. No errors should be generated. |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 4559 | TEST_F(VkLayerTest, TwoFencesThreeFrames) { |
| 4560 | TEST_DESCRIPTION("Two command buffers with two separate fences are each " |
| 4561 | "run through a Submit & WaitForFences cycle 3 times. This " |
| 4562 | "previously revealed a bug so running this positive test " |
| 4563 | "to prevent a regression."); |
| 4564 | m_errorMonitor->ExpectSuccess(); |
| 4565 | |
| 4566 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4567 | VkQueue queue = VK_NULL_HANDLE; |
| 4568 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4569 | 0, &queue); |
| 4570 | |
| 4571 | static const uint32_t NUM_OBJECTS = 2; |
| 4572 | static const uint32_t NUM_FRAMES = 3; |
| 4573 | VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {}; |
| 4574 | VkFence fences[NUM_OBJECTS] = {}; |
| 4575 | |
| 4576 | VkCommandPool cmd_pool; |
| 4577 | VkCommandPoolCreateInfo cmd_pool_ci = {}; |
| 4578 | cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4579 | cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4580 | cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4581 | VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, |
| 4582 | nullptr, &cmd_pool); |
| 4583 | ASSERT_VK_SUCCESS(err); |
| 4584 | |
| 4585 | VkCommandBufferAllocateInfo cmd_buf_info = {}; |
| 4586 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4587 | cmd_buf_info.commandPool = cmd_pool; |
| 4588 | cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4589 | cmd_buf_info.commandBufferCount = 1; |
| 4590 | |
| 4591 | VkFenceCreateInfo fence_ci = {}; |
| 4592 | fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4593 | fence_ci.pNext = nullptr; |
| 4594 | fence_ci.flags = 0; |
| 4595 | |
| 4596 | for (uint32_t i = 0; i < NUM_OBJECTS; ++i) { |
| 4597 | err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, |
| 4598 | &cmd_buffers[i]); |
| 4599 | ASSERT_VK_SUCCESS(err); |
| 4600 | err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]); |
| 4601 | ASSERT_VK_SUCCESS(err); |
| 4602 | } |
| 4603 | |
| 4604 | for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) { |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 4605 | for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) { |
| 4606 | // Create empty cmd buffer |
| 4607 | VkCommandBufferBeginInfo cmdBufBeginDesc = {}; |
| 4608 | cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 4609 | |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 4610 | err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc); |
| 4611 | ASSERT_VK_SUCCESS(err); |
| 4612 | err = vkEndCommandBuffer(cmd_buffers[obj]); |
| 4613 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 4614 | |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 4615 | VkSubmitInfo submit_info = {}; |
| 4616 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4617 | submit_info.commandBufferCount = 1; |
| 4618 | submit_info.pCommandBuffers = &cmd_buffers[obj]; |
| 4619 | // Submit cmd buffer and wait for fence |
| 4620 | err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]); |
| 4621 | ASSERT_VK_SUCCESS(err); |
| 4622 | err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, |
| 4623 | UINT64_MAX); |
| 4624 | ASSERT_VK_SUCCESS(err); |
| 4625 | err = vkResetFences(m_device->device(), 1, &fences[obj]); |
| 4626 | ASSERT_VK_SUCCESS(err); |
| 4627 | } |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 4628 | } |
| 4629 | m_errorMonitor->VerifyNotFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 4630 | vkDestroyCommandPool(m_device->device(), cmd_pool, NULL); |
| 4631 | for (uint32_t i = 0; i < NUM_OBJECTS; ++i) { |
| 4632 | vkDestroyFence(m_device->device(), fences[i], nullptr); |
| 4633 | } |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 4634 | } |
| 4635 | // This is a positive test. No errors should be generated. |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4636 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) { |
| 4637 | |
| 4638 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4639 | "submitted on separate queues followed by a QueueWaitIdle."); |
| 4640 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 4641 | if ((m_device->queue_props.empty()) || |
| 4642 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 4643 | return; |
| 4644 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4645 | m_errorMonitor->ExpectSuccess(); |
| 4646 | |
| 4647 | VkSemaphore semaphore; |
| 4648 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4649 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4650 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4651 | &semaphore); |
| 4652 | |
| 4653 | VkCommandPool command_pool; |
| 4654 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4655 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4656 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4657 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4658 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4659 | &command_pool); |
| 4660 | |
| 4661 | VkCommandBuffer command_buffer[2]; |
| 4662 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4663 | command_buffer_allocate_info.sType = |
| 4664 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4665 | command_buffer_allocate_info.commandPool = command_pool; |
| 4666 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4667 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4668 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4669 | command_buffer); |
| 4670 | |
| 4671 | VkQueue queue = VK_NULL_HANDLE; |
| 4672 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4673 | 1, &queue); |
| 4674 | |
| 4675 | { |
| 4676 | VkCommandBufferBeginInfo begin_info{}; |
| 4677 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4678 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4679 | |
| 4680 | vkCmdPipelineBarrier(command_buffer[0], |
| 4681 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4682 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4683 | 0, nullptr, 0, nullptr); |
| 4684 | |
| 4685 | VkViewport viewport{}; |
| 4686 | viewport.maxDepth = 1.0f; |
| 4687 | viewport.minDepth = 0.0f; |
| 4688 | viewport.width = 512; |
| 4689 | viewport.height = 512; |
| 4690 | viewport.x = 0; |
| 4691 | viewport.y = 0; |
| 4692 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4693 | vkEndCommandBuffer(command_buffer[0]); |
| 4694 | } |
| 4695 | { |
| 4696 | VkCommandBufferBeginInfo begin_info{}; |
| 4697 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4698 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4699 | |
| 4700 | VkViewport viewport{}; |
| 4701 | viewport.maxDepth = 1.0f; |
| 4702 | viewport.minDepth = 0.0f; |
| 4703 | viewport.width = 512; |
| 4704 | viewport.height = 512; |
| 4705 | viewport.x = 0; |
| 4706 | viewport.y = 0; |
| 4707 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4708 | vkEndCommandBuffer(command_buffer[1]); |
| 4709 | } |
| 4710 | { |
| 4711 | VkSubmitInfo submit_info{}; |
| 4712 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4713 | submit_info.commandBufferCount = 1; |
| 4714 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4715 | submit_info.signalSemaphoreCount = 1; |
| 4716 | submit_info.pSignalSemaphores = &semaphore; |
| 4717 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4718 | } |
| 4719 | { |
| 4720 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4721 | VkSubmitInfo submit_info{}; |
| 4722 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4723 | submit_info.commandBufferCount = 1; |
| 4724 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4725 | submit_info.waitSemaphoreCount = 1; |
| 4726 | submit_info.pWaitSemaphores = &semaphore; |
| 4727 | submit_info.pWaitDstStageMask = flags; |
| 4728 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4729 | } |
| 4730 | |
| 4731 | vkQueueWaitIdle(m_device->m_queue); |
| 4732 | |
| 4733 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4734 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4735 | &command_buffer[0]); |
| 4736 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4737 | |
| 4738 | m_errorMonitor->VerifyNotFound(); |
| 4739 | } |
| 4740 | |
| 4741 | // This is a positive test. No errors should be generated. |
| 4742 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) { |
| 4743 | |
| 4744 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4745 | "submitted on separate queues, the second having a fence" |
| 4746 | "followed by a QueueWaitIdle."); |
| 4747 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 4748 | if ((m_device->queue_props.empty()) || |
| 4749 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 4750 | return; |
| 4751 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4752 | m_errorMonitor->ExpectSuccess(); |
| 4753 | |
| 4754 | VkFence fence; |
| 4755 | VkFenceCreateInfo fence_create_info{}; |
| 4756 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4757 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4758 | |
| 4759 | VkSemaphore semaphore; |
| 4760 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4761 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4762 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4763 | &semaphore); |
| 4764 | |
| 4765 | VkCommandPool command_pool; |
| 4766 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4767 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4768 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4769 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4770 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4771 | &command_pool); |
| 4772 | |
| 4773 | VkCommandBuffer command_buffer[2]; |
| 4774 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4775 | command_buffer_allocate_info.sType = |
| 4776 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4777 | command_buffer_allocate_info.commandPool = command_pool; |
| 4778 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4779 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4780 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4781 | command_buffer); |
| 4782 | |
| 4783 | VkQueue queue = VK_NULL_HANDLE; |
| 4784 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4785 | 1, &queue); |
| 4786 | |
| 4787 | { |
| 4788 | VkCommandBufferBeginInfo begin_info{}; |
| 4789 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4790 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4791 | |
| 4792 | vkCmdPipelineBarrier(command_buffer[0], |
| 4793 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4794 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4795 | 0, nullptr, 0, nullptr); |
| 4796 | |
| 4797 | VkViewport viewport{}; |
| 4798 | viewport.maxDepth = 1.0f; |
| 4799 | viewport.minDepth = 0.0f; |
| 4800 | viewport.width = 512; |
| 4801 | viewport.height = 512; |
| 4802 | viewport.x = 0; |
| 4803 | viewport.y = 0; |
| 4804 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4805 | vkEndCommandBuffer(command_buffer[0]); |
| 4806 | } |
| 4807 | { |
| 4808 | VkCommandBufferBeginInfo begin_info{}; |
| 4809 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4810 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4811 | |
| 4812 | VkViewport viewport{}; |
| 4813 | viewport.maxDepth = 1.0f; |
| 4814 | viewport.minDepth = 0.0f; |
| 4815 | viewport.width = 512; |
| 4816 | viewport.height = 512; |
| 4817 | viewport.x = 0; |
| 4818 | viewport.y = 0; |
| 4819 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4820 | vkEndCommandBuffer(command_buffer[1]); |
| 4821 | } |
| 4822 | { |
| 4823 | VkSubmitInfo submit_info{}; |
| 4824 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4825 | submit_info.commandBufferCount = 1; |
| 4826 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4827 | submit_info.signalSemaphoreCount = 1; |
| 4828 | submit_info.pSignalSemaphores = &semaphore; |
| 4829 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4830 | } |
| 4831 | { |
| 4832 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4833 | VkSubmitInfo submit_info{}; |
| 4834 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4835 | submit_info.commandBufferCount = 1; |
| 4836 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4837 | submit_info.waitSemaphoreCount = 1; |
| 4838 | submit_info.pWaitSemaphores = &semaphore; |
| 4839 | submit_info.pWaitDstStageMask = flags; |
| 4840 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4841 | } |
| 4842 | |
| 4843 | vkQueueWaitIdle(m_device->m_queue); |
| 4844 | |
| 4845 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4846 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4847 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4848 | &command_buffer[0]); |
| 4849 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4850 | |
| 4851 | m_errorMonitor->VerifyNotFound(); |
| 4852 | } |
| 4853 | |
| 4854 | // This is a positive test. No errors should be generated. |
| 4855 | TEST_F(VkLayerTest, |
| 4856 | TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) { |
| 4857 | |
| 4858 | TEST_DESCRIPTION( |
| 4859 | "Two command buffers, each in a separate QueueSubmit call " |
| 4860 | "submitted on separate queues, the second having a fence" |
| 4861 | "followed by two consecutive WaitForFences calls on the same fence."); |
| 4862 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 4863 | if ((m_device->queue_props.empty()) || |
| 4864 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 4865 | return; |
| 4866 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4867 | m_errorMonitor->ExpectSuccess(); |
| 4868 | |
| 4869 | VkFence fence; |
| 4870 | VkFenceCreateInfo fence_create_info{}; |
| 4871 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4872 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4873 | |
| 4874 | VkSemaphore semaphore; |
| 4875 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4876 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4877 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4878 | &semaphore); |
| 4879 | |
| 4880 | VkCommandPool command_pool; |
| 4881 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4882 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4883 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4884 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4885 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4886 | &command_pool); |
| 4887 | |
| 4888 | VkCommandBuffer command_buffer[2]; |
| 4889 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4890 | command_buffer_allocate_info.sType = |
| 4891 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4892 | command_buffer_allocate_info.commandPool = command_pool; |
| 4893 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4894 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4895 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4896 | command_buffer); |
| 4897 | |
| 4898 | VkQueue queue = VK_NULL_HANDLE; |
| 4899 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4900 | 1, &queue); |
| 4901 | |
| 4902 | { |
| 4903 | VkCommandBufferBeginInfo begin_info{}; |
| 4904 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4905 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4906 | |
| 4907 | vkCmdPipelineBarrier(command_buffer[0], |
| 4908 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4909 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4910 | 0, nullptr, 0, nullptr); |
| 4911 | |
| 4912 | VkViewport viewport{}; |
| 4913 | viewport.maxDepth = 1.0f; |
| 4914 | viewport.minDepth = 0.0f; |
| 4915 | viewport.width = 512; |
| 4916 | viewport.height = 512; |
| 4917 | viewport.x = 0; |
| 4918 | viewport.y = 0; |
| 4919 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4920 | vkEndCommandBuffer(command_buffer[0]); |
| 4921 | } |
| 4922 | { |
| 4923 | VkCommandBufferBeginInfo begin_info{}; |
| 4924 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4925 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4926 | |
| 4927 | VkViewport viewport{}; |
| 4928 | viewport.maxDepth = 1.0f; |
| 4929 | viewport.minDepth = 0.0f; |
| 4930 | viewport.width = 512; |
| 4931 | viewport.height = 512; |
| 4932 | viewport.x = 0; |
| 4933 | viewport.y = 0; |
| 4934 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4935 | vkEndCommandBuffer(command_buffer[1]); |
| 4936 | } |
| 4937 | { |
| 4938 | VkSubmitInfo submit_info{}; |
| 4939 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4940 | submit_info.commandBufferCount = 1; |
| 4941 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4942 | submit_info.signalSemaphoreCount = 1; |
| 4943 | submit_info.pSignalSemaphores = &semaphore; |
| 4944 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4945 | } |
| 4946 | { |
| 4947 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4948 | VkSubmitInfo submit_info{}; |
| 4949 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4950 | submit_info.commandBufferCount = 1; |
| 4951 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4952 | submit_info.waitSemaphoreCount = 1; |
| 4953 | submit_info.pWaitSemaphores = &semaphore; |
| 4954 | submit_info.pWaitDstStageMask = flags; |
| 4955 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4956 | } |
| 4957 | |
| 4958 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4959 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4960 | |
| 4961 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4962 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4963 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4964 | &command_buffer[0]); |
| 4965 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4966 | |
| 4967 | m_errorMonitor->VerifyNotFound(); |
| 4968 | } |
| 4969 | |
Chris Forbes | 0f8126b | 2016-06-20 17:48:22 +1200 | [diff] [blame] | 4970 | #if 0 |
| 4971 | TEST_F(VkLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) { |
| 4972 | if ((m_device->queue_props.empty()) || |
| 4973 | (m_device->queue_props[0].queueCount < 2)) { |
| 4974 | printf("Test requires two queues, skipping\n"); |
| 4975 | return; |
| 4976 | } |
| 4977 | |
| 4978 | VkResult err; |
| 4979 | |
| 4980 | m_errorMonitor->ExpectSuccess(); |
| 4981 | |
| 4982 | VkQueue q0 = m_device->m_queue; |
| 4983 | VkQueue q1 = nullptr; |
| 4984 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1); |
| 4985 | ASSERT_NE(q1, nullptr); |
| 4986 | |
| 4987 | // An (empty) command buffer. We must have work in the first submission -- |
| 4988 | // the layer treats unfenced work differently from fenced work. |
| 4989 | VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 }; |
| 4990 | VkCommandPool pool; |
| 4991 | err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool); |
| 4992 | ASSERT_VK_SUCCESS(err); |
| 4993 | VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, |
| 4994 | pool, VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 |
| 4995 | }; |
| 4996 | VkCommandBuffer cb; |
| 4997 | err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb); |
| 4998 | ASSERT_VK_SUCCESS(err); |
| 4999 | VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, |
| 5000 | 0, nullptr |
| 5001 | }; |
| 5002 | err = vkBeginCommandBuffer(cb, &cbbi); |
| 5003 | ASSERT_VK_SUCCESS(err); |
| 5004 | err = vkEndCommandBuffer(cb); |
| 5005 | ASSERT_VK_SUCCESS(err); |
| 5006 | |
| 5007 | // A semaphore |
| 5008 | VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 }; |
| 5009 | VkSemaphore s; |
| 5010 | err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s); |
| 5011 | ASSERT_VK_SUCCESS(err); |
| 5012 | |
| 5013 | // First submission, to q0 |
| 5014 | VkSubmitInfo s0 = { |
| 5015 | VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, |
| 5016 | 0, nullptr, nullptr, |
| 5017 | 1, &cb, |
| 5018 | 1, &s |
| 5019 | }; |
| 5020 | |
| 5021 | err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE); |
| 5022 | ASSERT_VK_SUCCESS(err); |
| 5023 | |
| 5024 | // Second submission, to q1, waiting on s |
| 5025 | VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is. |
| 5026 | VkSubmitInfo s1 = { |
| 5027 | VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, |
| 5028 | 1, &s, &waitmask, |
| 5029 | 0, nullptr, |
| 5030 | 0, nullptr |
| 5031 | }; |
| 5032 | |
| 5033 | err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE); |
| 5034 | ASSERT_VK_SUCCESS(err); |
| 5035 | |
| 5036 | // Wait for q0 idle |
| 5037 | err = vkQueueWaitIdle(q0); |
| 5038 | ASSERT_VK_SUCCESS(err); |
| 5039 | |
| 5040 | // Command buffer should have been completed (it was on q0); reset the pool. |
| 5041 | vkFreeCommandBuffers(m_device->device(), pool, 1, &cb); |
| 5042 | |
| 5043 | m_errorMonitor->VerifyNotFound(); |
| 5044 | |
| 5045 | // Force device completely idle and clean up resources |
| 5046 | vkDeviceWaitIdle(m_device->device()); |
| 5047 | vkDestroyCommandPool(m_device->device(), pool, nullptr); |
| 5048 | vkDestroySemaphore(m_device->device(), s, nullptr); |
| 5049 | } |
| 5050 | #endif |
| 5051 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 5052 | // This is a positive test. No errors should be generated. |
| 5053 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) { |
| 5054 | |
| 5055 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 5056 | "submitted on separate queues, the second having a fence, " |
| 5057 | "followed by a WaitForFences call."); |
| 5058 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 5059 | if ((m_device->queue_props.empty()) || |
| 5060 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 5061 | return; |
| 5062 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 5063 | m_errorMonitor->ExpectSuccess(); |
| 5064 | |
| 5065 | VkFence fence; |
| 5066 | VkFenceCreateInfo fence_create_info{}; |
| 5067 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 5068 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 5069 | |
| 5070 | VkSemaphore semaphore; |
| 5071 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 5072 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 5073 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 5074 | &semaphore); |
| 5075 | |
| 5076 | VkCommandPool command_pool; |
| 5077 | VkCommandPoolCreateInfo pool_create_info{}; |
| 5078 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 5079 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 5080 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 5081 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 5082 | &command_pool); |
| 5083 | |
| 5084 | VkCommandBuffer command_buffer[2]; |
| 5085 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 5086 | command_buffer_allocate_info.sType = |
| 5087 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 5088 | command_buffer_allocate_info.commandPool = command_pool; |
| 5089 | command_buffer_allocate_info.commandBufferCount = 2; |
| 5090 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 5091 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 5092 | command_buffer); |
| 5093 | |
| 5094 | VkQueue queue = VK_NULL_HANDLE; |
| 5095 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 5096 | 1, &queue); |
| 5097 | |
| 5098 | |
| 5099 | { |
| 5100 | VkCommandBufferBeginInfo begin_info{}; |
| 5101 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 5102 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 5103 | |
| 5104 | vkCmdPipelineBarrier(command_buffer[0], |
| 5105 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 5106 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 5107 | 0, nullptr, 0, nullptr); |
| 5108 | |
| 5109 | VkViewport viewport{}; |
| 5110 | viewport.maxDepth = 1.0f; |
| 5111 | viewport.minDepth = 0.0f; |
| 5112 | viewport.width = 512; |
| 5113 | viewport.height = 512; |
| 5114 | viewport.x = 0; |
| 5115 | viewport.y = 0; |
| 5116 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 5117 | vkEndCommandBuffer(command_buffer[0]); |
| 5118 | } |
| 5119 | { |
| 5120 | VkCommandBufferBeginInfo begin_info{}; |
| 5121 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 5122 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 5123 | |
| 5124 | VkViewport viewport{}; |
| 5125 | viewport.maxDepth = 1.0f; |
| 5126 | viewport.minDepth = 0.0f; |
| 5127 | viewport.width = 512; |
| 5128 | viewport.height = 512; |
| 5129 | viewport.x = 0; |
| 5130 | viewport.y = 0; |
| 5131 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 5132 | vkEndCommandBuffer(command_buffer[1]); |
| 5133 | } |
| 5134 | { |
| 5135 | VkSubmitInfo submit_info{}; |
| 5136 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5137 | submit_info.commandBufferCount = 1; |
| 5138 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 5139 | submit_info.signalSemaphoreCount = 1; |
| 5140 | submit_info.pSignalSemaphores = &semaphore; |
| 5141 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 5142 | } |
| 5143 | { |
| 5144 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 5145 | VkSubmitInfo submit_info{}; |
| 5146 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5147 | submit_info.commandBufferCount = 1; |
| 5148 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 5149 | submit_info.waitSemaphoreCount = 1; |
| 5150 | submit_info.pWaitSemaphores = &semaphore; |
| 5151 | submit_info.pWaitDstStageMask = flags; |
| 5152 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 5153 | } |
| 5154 | |
| 5155 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 5156 | |
| 5157 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 5158 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 5159 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 5160 | &command_buffer[0]); |
| 5161 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 5162 | |
| 5163 | m_errorMonitor->VerifyNotFound(); |
| 5164 | } |
| 5165 | |
| 5166 | // This is a positive test. No errors should be generated. |
| 5167 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) { |
| 5168 | |
| 5169 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 5170 | "on the same queue, sharing a signal/wait semaphore, the " |
| 5171 | "second having a fence, " |
| 5172 | "followed by a WaitForFences call."); |
| 5173 | |
| 5174 | m_errorMonitor->ExpectSuccess(); |
| 5175 | |
| 5176 | VkFence fence; |
| 5177 | VkFenceCreateInfo fence_create_info{}; |
| 5178 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 5179 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 5180 | |
| 5181 | VkSemaphore semaphore; |
| 5182 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 5183 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 5184 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 5185 | &semaphore); |
| 5186 | |
| 5187 | VkCommandPool command_pool; |
| 5188 | VkCommandPoolCreateInfo pool_create_info{}; |
| 5189 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 5190 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 5191 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 5192 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 5193 | &command_pool); |
| 5194 | |
| 5195 | VkCommandBuffer command_buffer[2]; |
| 5196 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 5197 | command_buffer_allocate_info.sType = |
| 5198 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 5199 | command_buffer_allocate_info.commandPool = command_pool; |
| 5200 | command_buffer_allocate_info.commandBufferCount = 2; |
| 5201 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 5202 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 5203 | command_buffer); |
| 5204 | |
| 5205 | { |
| 5206 | VkCommandBufferBeginInfo begin_info{}; |
| 5207 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 5208 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 5209 | |
| 5210 | vkCmdPipelineBarrier(command_buffer[0], |
| 5211 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 5212 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 5213 | 0, nullptr, 0, nullptr); |
| 5214 | |
| 5215 | VkViewport viewport{}; |
| 5216 | viewport.maxDepth = 1.0f; |
| 5217 | viewport.minDepth = 0.0f; |
| 5218 | viewport.width = 512; |
| 5219 | viewport.height = 512; |
| 5220 | viewport.x = 0; |
| 5221 | viewport.y = 0; |
| 5222 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 5223 | vkEndCommandBuffer(command_buffer[0]); |
| 5224 | } |
| 5225 | { |
| 5226 | VkCommandBufferBeginInfo begin_info{}; |
| 5227 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 5228 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 5229 | |
| 5230 | VkViewport viewport{}; |
| 5231 | viewport.maxDepth = 1.0f; |
| 5232 | viewport.minDepth = 0.0f; |
| 5233 | viewport.width = 512; |
| 5234 | viewport.height = 512; |
| 5235 | viewport.x = 0; |
| 5236 | viewport.y = 0; |
| 5237 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 5238 | vkEndCommandBuffer(command_buffer[1]); |
| 5239 | } |
| 5240 | { |
| 5241 | VkSubmitInfo submit_info{}; |
| 5242 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5243 | submit_info.commandBufferCount = 1; |
| 5244 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 5245 | submit_info.signalSemaphoreCount = 1; |
| 5246 | submit_info.pSignalSemaphores = &semaphore; |
| 5247 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 5248 | } |
| 5249 | { |
| 5250 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 5251 | VkSubmitInfo submit_info{}; |
| 5252 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5253 | submit_info.commandBufferCount = 1; |
| 5254 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 5255 | submit_info.waitSemaphoreCount = 1; |
| 5256 | submit_info.pWaitSemaphores = &semaphore; |
| 5257 | submit_info.pWaitDstStageMask = flags; |
| 5258 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 5259 | } |
| 5260 | |
| 5261 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 5262 | |
| 5263 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 5264 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 5265 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 5266 | &command_buffer[0]); |
| 5267 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 5268 | |
| 5269 | m_errorMonitor->VerifyNotFound(); |
| 5270 | } |
| 5271 | |
| 5272 | // This is a positive test. No errors should be generated. |
| 5273 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) { |
| 5274 | |
| 5275 | TEST_DESCRIPTION( |
| 5276 | "Two command buffers, each in a separate QueueSubmit call " |
| 5277 | "on the same queue, no fences, followed by a third QueueSubmit with NO " |
| 5278 | "SubmitInfos but with a fence, followed by a WaitForFences call."); |
| 5279 | |
| 5280 | m_errorMonitor->ExpectSuccess(); |
| 5281 | |
| 5282 | VkFence fence; |
| 5283 | VkFenceCreateInfo fence_create_info{}; |
| 5284 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 5285 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 5286 | |
| 5287 | VkCommandPool command_pool; |
| 5288 | VkCommandPoolCreateInfo pool_create_info{}; |
| 5289 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 5290 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 5291 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 5292 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 5293 | &command_pool); |
| 5294 | |
| 5295 | VkCommandBuffer command_buffer[2]; |
| 5296 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 5297 | command_buffer_allocate_info.sType = |
| 5298 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 5299 | command_buffer_allocate_info.commandPool = command_pool; |
| 5300 | command_buffer_allocate_info.commandBufferCount = 2; |
| 5301 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 5302 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 5303 | command_buffer); |
| 5304 | |
| 5305 | { |
| 5306 | VkCommandBufferBeginInfo begin_info{}; |
| 5307 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 5308 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 5309 | |
| 5310 | vkCmdPipelineBarrier(command_buffer[0], |
| 5311 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 5312 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 5313 | 0, nullptr, 0, nullptr); |
| 5314 | |
| 5315 | VkViewport viewport{}; |
| 5316 | viewport.maxDepth = 1.0f; |
| 5317 | viewport.minDepth = 0.0f; |
| 5318 | viewport.width = 512; |
| 5319 | viewport.height = 512; |
| 5320 | viewport.x = 0; |
| 5321 | viewport.y = 0; |
| 5322 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 5323 | vkEndCommandBuffer(command_buffer[0]); |
| 5324 | } |
| 5325 | { |
| 5326 | VkCommandBufferBeginInfo begin_info{}; |
| 5327 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 5328 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 5329 | |
| 5330 | VkViewport viewport{}; |
| 5331 | viewport.maxDepth = 1.0f; |
| 5332 | viewport.minDepth = 0.0f; |
| 5333 | viewport.width = 512; |
| 5334 | viewport.height = 512; |
| 5335 | viewport.x = 0; |
| 5336 | viewport.y = 0; |
| 5337 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 5338 | vkEndCommandBuffer(command_buffer[1]); |
| 5339 | } |
| 5340 | { |
| 5341 | VkSubmitInfo submit_info{}; |
| 5342 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5343 | submit_info.commandBufferCount = 1; |
| 5344 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 5345 | submit_info.signalSemaphoreCount = 0; |
| 5346 | submit_info.pSignalSemaphores = VK_NULL_HANDLE; |
| 5347 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 5348 | } |
| 5349 | { |
| 5350 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 5351 | VkSubmitInfo submit_info{}; |
| 5352 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5353 | submit_info.commandBufferCount = 1; |
| 5354 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 5355 | submit_info.waitSemaphoreCount = 0; |
| 5356 | submit_info.pWaitSemaphores = VK_NULL_HANDLE; |
| 5357 | submit_info.pWaitDstStageMask = flags; |
| 5358 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 5359 | } |
| 5360 | |
| 5361 | vkQueueSubmit(m_device->m_queue, 0, NULL, fence); |
| 5362 | |
Mike Stroyan | cd1c3e5 | 2016-06-21 09:20:01 -0600 | [diff] [blame] | 5363 | VkResult err = |
| 5364 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 5365 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 5366 | |
| 5367 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 5368 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 5369 | &command_buffer[0]); |
| 5370 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 5371 | |
| 5372 | m_errorMonitor->VerifyNotFound(); |
| 5373 | } |
| 5374 | |
| 5375 | // This is a positive test. No errors should be generated. |
| 5376 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) { |
| 5377 | |
| 5378 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 5379 | "on the same queue, the second having a fence, followed " |
| 5380 | "by a WaitForFences call."); |
| 5381 | |
| 5382 | m_errorMonitor->ExpectSuccess(); |
| 5383 | |
| 5384 | VkFence fence; |
| 5385 | VkFenceCreateInfo fence_create_info{}; |
| 5386 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 5387 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 5388 | |
| 5389 | VkCommandPool command_pool; |
| 5390 | VkCommandPoolCreateInfo pool_create_info{}; |
| 5391 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 5392 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 5393 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 5394 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 5395 | &command_pool); |
| 5396 | |
| 5397 | VkCommandBuffer command_buffer[2]; |
| 5398 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 5399 | command_buffer_allocate_info.sType = |
| 5400 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 5401 | command_buffer_allocate_info.commandPool = command_pool; |
| 5402 | command_buffer_allocate_info.commandBufferCount = 2; |
| 5403 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 5404 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 5405 | command_buffer); |
| 5406 | |
| 5407 | { |
| 5408 | VkCommandBufferBeginInfo begin_info{}; |
| 5409 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 5410 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 5411 | |
| 5412 | vkCmdPipelineBarrier(command_buffer[0], |
| 5413 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 5414 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 5415 | 0, nullptr, 0, nullptr); |
| 5416 | |
| 5417 | VkViewport viewport{}; |
| 5418 | viewport.maxDepth = 1.0f; |
| 5419 | viewport.minDepth = 0.0f; |
| 5420 | viewport.width = 512; |
| 5421 | viewport.height = 512; |
| 5422 | viewport.x = 0; |
| 5423 | viewport.y = 0; |
| 5424 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 5425 | vkEndCommandBuffer(command_buffer[0]); |
| 5426 | } |
| 5427 | { |
| 5428 | VkCommandBufferBeginInfo begin_info{}; |
| 5429 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 5430 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 5431 | |
| 5432 | VkViewport viewport{}; |
| 5433 | viewport.maxDepth = 1.0f; |
| 5434 | viewport.minDepth = 0.0f; |
| 5435 | viewport.width = 512; |
| 5436 | viewport.height = 512; |
| 5437 | viewport.x = 0; |
| 5438 | viewport.y = 0; |
| 5439 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 5440 | vkEndCommandBuffer(command_buffer[1]); |
| 5441 | } |
| 5442 | { |
| 5443 | VkSubmitInfo submit_info{}; |
| 5444 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5445 | submit_info.commandBufferCount = 1; |
| 5446 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 5447 | submit_info.signalSemaphoreCount = 0; |
| 5448 | submit_info.pSignalSemaphores = VK_NULL_HANDLE; |
| 5449 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 5450 | } |
| 5451 | { |
| 5452 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 5453 | VkSubmitInfo submit_info{}; |
| 5454 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5455 | submit_info.commandBufferCount = 1; |
| 5456 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 5457 | submit_info.waitSemaphoreCount = 0; |
| 5458 | submit_info.pWaitSemaphores = VK_NULL_HANDLE; |
| 5459 | submit_info.pWaitDstStageMask = flags; |
| 5460 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 5461 | } |
| 5462 | |
| 5463 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 5464 | |
| 5465 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 5466 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 5467 | &command_buffer[0]); |
| 5468 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 5469 | |
| 5470 | m_errorMonitor->VerifyNotFound(); |
| 5471 | } |
| 5472 | |
| 5473 | // This is a positive test. No errors should be generated. |
| 5474 | TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) { |
| 5475 | |
| 5476 | TEST_DESCRIPTION( |
| 5477 | "Two command buffers each in a separate SubmitInfo sent in a single " |
| 5478 | "QueueSubmit call followed by a WaitForFences call."); |
| 5479 | |
| 5480 | m_errorMonitor->ExpectSuccess(); |
| 5481 | |
| 5482 | VkFence fence; |
| 5483 | VkFenceCreateInfo fence_create_info{}; |
| 5484 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 5485 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 5486 | |
| 5487 | VkSemaphore semaphore; |
| 5488 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 5489 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 5490 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 5491 | &semaphore); |
| 5492 | |
| 5493 | VkCommandPool command_pool; |
| 5494 | VkCommandPoolCreateInfo pool_create_info{}; |
| 5495 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 5496 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 5497 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 5498 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 5499 | &command_pool); |
| 5500 | |
| 5501 | VkCommandBuffer command_buffer[2]; |
| 5502 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 5503 | command_buffer_allocate_info.sType = |
| 5504 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 5505 | command_buffer_allocate_info.commandPool = command_pool; |
| 5506 | command_buffer_allocate_info.commandBufferCount = 2; |
| 5507 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 5508 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 5509 | command_buffer); |
| 5510 | |
| 5511 | { |
| 5512 | VkCommandBufferBeginInfo begin_info{}; |
| 5513 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 5514 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 5515 | |
| 5516 | vkCmdPipelineBarrier(command_buffer[0], |
| 5517 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 5518 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 5519 | 0, nullptr, 0, nullptr); |
| 5520 | |
| 5521 | VkViewport viewport{}; |
| 5522 | viewport.maxDepth = 1.0f; |
| 5523 | viewport.minDepth = 0.0f; |
| 5524 | viewport.width = 512; |
| 5525 | viewport.height = 512; |
| 5526 | viewport.x = 0; |
| 5527 | viewport.y = 0; |
| 5528 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 5529 | vkEndCommandBuffer(command_buffer[0]); |
| 5530 | } |
| 5531 | { |
| 5532 | VkCommandBufferBeginInfo begin_info{}; |
| 5533 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 5534 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 5535 | |
| 5536 | VkViewport viewport{}; |
| 5537 | viewport.maxDepth = 1.0f; |
| 5538 | viewport.minDepth = 0.0f; |
| 5539 | viewport.width = 512; |
| 5540 | viewport.height = 512; |
| 5541 | viewport.x = 0; |
| 5542 | viewport.y = 0; |
| 5543 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 5544 | vkEndCommandBuffer(command_buffer[1]); |
| 5545 | } |
| 5546 | { |
| 5547 | VkSubmitInfo submit_info[2]; |
| 5548 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 5549 | |
| 5550 | submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5551 | submit_info[0].pNext = NULL; |
| 5552 | submit_info[0].commandBufferCount = 1; |
| 5553 | submit_info[0].pCommandBuffers = &command_buffer[0]; |
| 5554 | submit_info[0].signalSemaphoreCount = 1; |
| 5555 | submit_info[0].pSignalSemaphores = &semaphore; |
| 5556 | submit_info[0].waitSemaphoreCount = 0; |
| 5557 | submit_info[0].pWaitSemaphores = NULL; |
| 5558 | submit_info[0].pWaitDstStageMask = 0; |
| 5559 | |
| 5560 | submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5561 | submit_info[1].pNext = NULL; |
| 5562 | submit_info[1].commandBufferCount = 1; |
| 5563 | submit_info[1].pCommandBuffers = &command_buffer[1]; |
| 5564 | submit_info[1].waitSemaphoreCount = 1; |
| 5565 | submit_info[1].pWaitSemaphores = &semaphore; |
| 5566 | submit_info[1].pWaitDstStageMask = flags; |
| 5567 | submit_info[1].signalSemaphoreCount = 0; |
| 5568 | submit_info[1].pSignalSemaphores = NULL; |
| 5569 | vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence); |
| 5570 | } |
| 5571 | |
| 5572 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 5573 | |
| 5574 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 5575 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 5576 | &command_buffer[0]); |
| 5577 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 5578 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 5579 | |
| 5580 | m_errorMonitor->VerifyNotFound(); |
| 5581 | } |
| 5582 | |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5583 | TEST_F(VkLayerTest, DynamicDepthBiasNotBound) { |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5584 | TEST_DESCRIPTION( |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5585 | "Run a simple draw calls to validate failure when Depth Bias dynamic " |
| 5586 | "state is required but not correctly bound."); |
| 5587 | |
| 5588 | // Dynamic depth bias |
| 5589 | m_errorMonitor->SetDesiredFailureMsg( |
| 5590 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5591 | "Dynamic depth bias state not set for this command buffer"); |
| 5592 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5593 | BsoFailDepthBias); |
| 5594 | m_errorMonitor->VerifyFound(); |
| 5595 | } |
| 5596 | |
| 5597 | TEST_F(VkLayerTest, DynamicLineWidthNotBound) { |
| 5598 | TEST_DESCRIPTION( |
| 5599 | "Run a simple draw calls to validate failure when Line Width dynamic " |
| 5600 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5601 | |
| 5602 | // Dynamic line width |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5603 | m_errorMonitor->SetDesiredFailureMsg( |
| 5604 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5605 | "Dynamic line width state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5606 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5607 | BsoFailLineWidth); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5608 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5609 | } |
| 5610 | |
| 5611 | TEST_F(VkLayerTest, DynamicViewportNotBound) { |
| 5612 | TEST_DESCRIPTION( |
| 5613 | "Run a simple draw calls to validate failure when Viewport dynamic " |
| 5614 | "state is required but not correctly bound."); |
| 5615 | |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5616 | // Dynamic viewport state |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5617 | m_errorMonitor->SetDesiredFailureMsg( |
| 5618 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5619 | "Dynamic viewport state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5620 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5621 | BsoFailViewport); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5622 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5623 | } |
| 5624 | |
| 5625 | TEST_F(VkLayerTest, DynamicScissorNotBound) { |
| 5626 | TEST_DESCRIPTION( |
| 5627 | "Run a simple draw calls to validate failure when Scissor dynamic " |
| 5628 | "state is required but not correctly bound."); |
| 5629 | |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5630 | // Dynamic scissor state |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5631 | m_errorMonitor->SetDesiredFailureMsg( |
| 5632 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5633 | "Dynamic scissor state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5634 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5635 | BsoFailScissor); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5636 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5637 | } |
| 5638 | |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 5639 | TEST_F(VkLayerTest, DynamiBlendConstantsNotBound) { |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5640 | TEST_DESCRIPTION( |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 5641 | "Run a simple draw calls to validate failure when Blend Constants " |
| 5642 | "dynamic state is required but not correctly bound."); |
| 5643 | // Dynamic blend constant state |
| 5644 | m_errorMonitor->SetDesiredFailureMsg( |
| 5645 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5646 | "Dynamic blend constants state not set for this command buffer"); |
| 5647 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5648 | BsoFailBlend); |
| 5649 | m_errorMonitor->VerifyFound(); |
| 5650 | } |
| 5651 | |
| 5652 | TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) { |
| 5653 | TEST_DESCRIPTION( |
| 5654 | "Run a simple draw calls to validate failure when Depth Bounds dynamic " |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5655 | "state is required but not correctly bound."); |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 5656 | if (!m_device->phy().features().depthBounds) { |
| 5657 | printf("Device does not support depthBounds test; skipped.\n"); |
| 5658 | return; |
| 5659 | } |
| 5660 | // Dynamic depth bounds |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5661 | m_errorMonitor->SetDesiredFailureMsg( |
| 5662 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5663 | "Dynamic depth bounds state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5664 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5665 | BsoFailDepthBounds); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5666 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5667 | } |
| 5668 | |
| 5669 | TEST_F(VkLayerTest, DynamicStencilReadNotBound) { |
| 5670 | TEST_DESCRIPTION( |
| 5671 | "Run a simple draw calls to validate failure when Stencil Read dynamic " |
| 5672 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5673 | // Dynamic stencil read mask |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5674 | m_errorMonitor->SetDesiredFailureMsg( |
| 5675 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5676 | "Dynamic stencil read mask state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5677 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5678 | BsoFailStencilReadMask); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5679 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5680 | } |
| 5681 | |
| 5682 | TEST_F(VkLayerTest, DynamicStencilWriteNotBound) { |
| 5683 | TEST_DESCRIPTION( |
| 5684 | "Run a simple draw calls to validate failure when Stencil Write dynamic" |
| 5685 | " state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5686 | // Dynamic stencil write mask |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5687 | m_errorMonitor->SetDesiredFailureMsg( |
| 5688 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5689 | "Dynamic stencil write mask state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5690 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5691 | BsoFailStencilWriteMask); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5692 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5693 | } |
| 5694 | |
| 5695 | TEST_F(VkLayerTest, DynamicStencilRefNotBound) { |
| 5696 | TEST_DESCRIPTION( |
| 5697 | "Run a simple draw calls to validate failure when Stencil Ref dynamic " |
| 5698 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5699 | // Dynamic stencil reference |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5700 | m_errorMonitor->SetDesiredFailureMsg( |
| 5701 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5702 | "Dynamic stencil reference state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5703 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5704 | BsoFailStencilReference); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5705 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 963a404 | 2015-09-29 08:18:34 -0600 | [diff] [blame] | 5706 | } |
| 5707 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5708 | TEST_F(VkLayerTest, CommandBufferTwoSubmits) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5709 | m_errorMonitor->SetDesiredFailureMsg( |
| 5710 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5711 | "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has " |
| 5712 | "been submitted"); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5713 | |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5714 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5715 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5716 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5717 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5718 | // We luck out b/c by default the framework creates CB w/ the |
| 5719 | // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5720 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5721 | m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 5722 | m_stencil_clear_color, NULL); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5723 | EndCommandBuffer(); |
| 5724 | |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5725 | // Bypass framework since it does the waits automatically |
| 5726 | VkResult err = VK_SUCCESS; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 5727 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 5728 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5729 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 5730 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 5731 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 5732 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 5733 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5734 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 5735 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 5736 | submit_info.pSignalSemaphores = NULL; |
| 5737 | |
Chris Forbes | 40028e2 | 2016-06-13 09:59:34 +1200 | [diff] [blame] | 5738 | err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5739 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5740 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5741 | // Cause validation error by re-submitting cmd buffer that should only be |
| 5742 | // submitted once |
Chris Forbes | 40028e2 | 2016-06-13 09:59:34 +1200 | [diff] [blame] | 5743 | err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5744 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5745 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5746 | } |
| 5747 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5748 | TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) { |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5749 | // Initiate Draw w/o a PSO bound |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5750 | VkResult err; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5751 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 5752 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5753 | "Unable to allocate 1 descriptors of " |
| 5754 | "type " |
| 5755 | "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5756 | |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5757 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5758 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5759 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5760 | // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer |
| 5761 | // descriptor from it |
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_SAMPLER; |
| 5764 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -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.flags = 0; |
| 5770 | ds_pool_ci.maxSets = 1; |
| 5771 | ds_pool_ci.poolSizeCount = 1; |
| 5772 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5773 | |
| 5774 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5775 | err = |
| 5776 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5777 | ASSERT_VK_SUCCESS(err); |
| 5778 | |
| 5779 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5780 | dsl_binding.binding = 0; |
| 5781 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5782 | dsl_binding.descriptorCount = 1; |
| 5783 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5784 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5785 | |
| 5786 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5787 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5788 | ds_layout_ci.pNext = NULL; |
| 5789 | ds_layout_ci.bindingCount = 1; |
| 5790 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5791 | |
| 5792 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5793 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5794 | &ds_layout); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5795 | ASSERT_VK_SUCCESS(err); |
| 5796 | |
| 5797 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5798 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5799 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5800 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 5801 | alloc_info.descriptorPool = ds_pool; |
| 5802 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5803 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5804 | &descriptorSet); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5805 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5806 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5807 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 5808 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5809 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5810 | } |
| 5811 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5812 | TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) { |
| 5813 | VkResult err; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5814 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5815 | m_errorMonitor->SetDesiredFailureMsg( |
| 5816 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5817 | "It is invalid to call vkFreeDescriptorSets() with a pool created " |
| 5818 | "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5819 | |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5820 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5821 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5822 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 5823 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5824 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5825 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5826 | |
| 5827 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5828 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5829 | ds_pool_ci.pNext = NULL; |
| 5830 | ds_pool_ci.maxSets = 1; |
| 5831 | ds_pool_ci.poolSizeCount = 1; |
| 5832 | ds_pool_ci.flags = 0; |
| 5833 | // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means |
| 5834 | // app can only call vkResetDescriptorPool on this pool.; |
| 5835 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5836 | |
| 5837 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5838 | err = |
| 5839 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5840 | ASSERT_VK_SUCCESS(err); |
| 5841 | |
| 5842 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5843 | dsl_binding.binding = 0; |
| 5844 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5845 | dsl_binding.descriptorCount = 1; |
| 5846 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5847 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5848 | |
| 5849 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5850 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5851 | ds_layout_ci.pNext = NULL; |
| 5852 | ds_layout_ci.bindingCount = 1; |
| 5853 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5854 | |
| 5855 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5856 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5857 | &ds_layout); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5858 | ASSERT_VK_SUCCESS(err); |
| 5859 | |
| 5860 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5861 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5862 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5863 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 5864 | alloc_info.descriptorPool = ds_pool; |
| 5865 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5866 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5867 | &descriptorSet); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5868 | ASSERT_VK_SUCCESS(err); |
| 5869 | |
| 5870 | err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5871 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5872 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 5873 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5874 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5875 | } |
| 5876 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5877 | TEST_F(VkLayerTest, InvalidDescriptorPool) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5878 | // Attempt to clear Descriptor Pool with bad object. |
| 5879 | // ObjectTracker should catch this. |
| 5880 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5881 | "Invalid VkDescriptorPool Object 0xbaad6001"); |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5882 | uint64_t fake_pool_handle = 0xbaad6001; |
| 5883 | VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle); |
| 5884 | vkResetDescriptorPool(device(), bad_pool, 0); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5885 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5886 | } |
| 5887 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5888 | TEST_F(VkLayerTest, InvalidDescriptorSet) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5889 | // Attempt to bind an invalid Descriptor Set to a valid Command Buffer |
| 5890 | // ObjectTracker should catch this. |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5891 | // Create a valid cmd buffer |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5892 | // call vkCmdBindDescriptorSets w/ false Descriptor Set |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5893 | |
| 5894 | uint64_t fake_set_handle = 0xbaad6001; |
| 5895 | VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5896 | VkResult err; |
| 5897 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5898 | "Invalid VkDescriptorSet Object 0xbaad6001"); |
| 5899 | |
| 5900 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5901 | |
| 5902 | VkDescriptorSetLayoutBinding layout_bindings[1] = {}; |
| 5903 | layout_bindings[0].binding = 0; |
| 5904 | layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5905 | layout_bindings[0].descriptorCount = 1; |
| 5906 | layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; |
| 5907 | layout_bindings[0].pImmutableSamplers = NULL; |
| 5908 | |
| 5909 | VkDescriptorSetLayout descriptor_set_layout; |
| 5910 | VkDescriptorSetLayoutCreateInfo dslci = {}; |
| 5911 | dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5912 | dslci.pNext = NULL; |
| 5913 | dslci.bindingCount = 1; |
| 5914 | dslci.pBindings = layout_bindings; |
| 5915 | err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout); |
Karl Schultz | 5cb2111 | 2016-04-21 17:17:40 -0600 | [diff] [blame] | 5916 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5917 | |
| 5918 | VkPipelineLayout pipeline_layout; |
| 5919 | VkPipelineLayoutCreateInfo plci = {}; |
| 5920 | plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5921 | plci.pNext = NULL; |
| 5922 | plci.setLayoutCount = 1; |
| 5923 | plci.pSetLayouts = &descriptor_set_layout; |
| 5924 | err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout); |
Karl Schultz | 5cb2111 | 2016-04-21 17:17:40 -0600 | [diff] [blame] | 5925 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5926 | |
| 5927 | BeginCommandBuffer(); |
| 5928 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5929 | pipeline_layout, 0, 1, &bad_set, 0, NULL); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5930 | m_errorMonitor->VerifyFound(); |
| 5931 | EndCommandBuffer(); |
| 5932 | vkDestroyPipelineLayout(device(), pipeline_layout, NULL); |
| 5933 | vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5934 | } |
| 5935 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5936 | TEST_F(VkLayerTest, InvalidDescriptorSetLayout) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5937 | // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout. |
| 5938 | // ObjectTracker should catch this. |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5939 | uint64_t fake_layout_handle = 0xbaad6001; |
| 5940 | VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5941 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5942 | "Invalid VkDescriptorSetLayout Object 0xbaad6001"); |
| 5943 | |
| 5944 | VkPipelineLayout pipeline_layout; |
| 5945 | VkPipelineLayoutCreateInfo plci = {}; |
| 5946 | plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5947 | plci.pNext = NULL; |
| 5948 | plci.setLayoutCount = 1; |
| 5949 | plci.pSetLayouts = &bad_layout; |
| 5950 | vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout); |
| 5951 | |
| 5952 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5953 | } |
| 5954 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5955 | TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) { |
| 5956 | TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec " |
| 5957 | "1) A uniform buffer update must have a valid buffer index." |
| 5958 | "2) When using an array of descriptors in a single WriteDescriptor," |
| 5959 | " the descriptor types and stageflags must all be the same." |
| 5960 | "3) Immutable Sampler state must match across descriptors"); |
| 5961 | |
| 5962 | const char *invalid_BufferInfo_ErrorMessage = |
| 5963 | "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, " |
| 5964 | "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or " |
| 5965 | "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL"; |
| 5966 | const char *stateFlag_ErrorMessage = |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5967 | "Attempting write update to descriptor set "; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5968 | const char *immutable_ErrorMessage = |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5969 | "Attempting write update to descriptor set "; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5970 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5971 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage); |
| 5972 | |
| 5973 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5974 | VkDescriptorPoolSize ds_type_count[4] = {}; |
| 5975 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5976 | ds_type_count[0].descriptorCount = 1; |
| 5977 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 5978 | ds_type_count[1].descriptorCount = 1; |
| 5979 | ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 5980 | ds_type_count[2].descriptorCount = 1; |
| 5981 | ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 5982 | ds_type_count[3].descriptorCount = 1; |
| 5983 | |
| 5984 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 5985 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5986 | ds_pool_ci.maxSets = 1; |
| 5987 | ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize); |
| 5988 | ds_pool_ci.pPoolSizes = ds_type_count; |
| 5989 | |
| 5990 | VkDescriptorPool ds_pool; |
| 5991 | VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 5992 | ASSERT_VK_SUCCESS(err); |
| 5993 | |
Mark Mueller | b989672 | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5994 | VkDescriptorSetLayoutBinding layout_binding[3] = {}; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5995 | layout_binding[0].binding = 0; |
| 5996 | layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5997 | layout_binding[0].descriptorCount = 1; |
| 5998 | layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 5999 | layout_binding[0].pImmutableSamplers = NULL; |
| 6000 | |
| 6001 | layout_binding[1].binding = 1; |
| 6002 | layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 6003 | layout_binding[1].descriptorCount = 1; |
| 6004 | layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; |
| 6005 | layout_binding[1].pImmutableSamplers = NULL; |
| 6006 | |
| 6007 | VkSamplerCreateInfo sampler_ci = {}; |
| 6008 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 6009 | sampler_ci.pNext = NULL; |
| 6010 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 6011 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 6012 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 6013 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 6014 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 6015 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 6016 | sampler_ci.mipLodBias = 1.0; |
| 6017 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 6018 | sampler_ci.maxAnisotropy = 1; |
| 6019 | sampler_ci.compareEnable = VK_FALSE; |
| 6020 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 6021 | sampler_ci.minLod = 1.0; |
| 6022 | sampler_ci.maxLod = 1.0; |
| 6023 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 6024 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
| 6025 | VkSampler sampler; |
| 6026 | |
| 6027 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
| 6028 | ASSERT_VK_SUCCESS(err); |
| 6029 | |
| 6030 | layout_binding[2].binding = 2; |
| 6031 | layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 6032 | layout_binding[2].descriptorCount = 1; |
| 6033 | layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; |
| 6034 | layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler); |
| 6035 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 6036 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 6037 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6038 | ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding); |
| 6039 | ds_layout_ci.pBindings = layout_binding; |
| 6040 | VkDescriptorSetLayout ds_layout; |
| 6041 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout); |
| 6042 | ASSERT_VK_SUCCESS(err); |
| 6043 | |
| 6044 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 6045 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 6046 | alloc_info.descriptorSetCount = 1; |
| 6047 | alloc_info.descriptorPool = ds_pool; |
| 6048 | alloc_info.pSetLayouts = &ds_layout; |
| 6049 | VkDescriptorSet descriptorSet; |
| 6050 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet); |
| 6051 | ASSERT_VK_SUCCESS(err); |
| 6052 | |
| 6053 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 6054 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6055 | pipeline_layout_ci.pNext = NULL; |
| 6056 | pipeline_layout_ci.setLayoutCount = 1; |
| 6057 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 6058 | |
| 6059 | VkPipelineLayout pipeline_layout; |
| 6060 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout); |
| 6061 | ASSERT_VK_SUCCESS(err); |
| 6062 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 6063 | VkWriteDescriptorSet descriptor_write = {}; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 6064 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 6065 | descriptor_write.dstSet = descriptorSet; |
| 6066 | descriptor_write.dstBinding = 0; |
| 6067 | descriptor_write.descriptorCount = 1; |
| 6068 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6069 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 6070 | // 1) The uniform buffer is intentionally invalid here |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 6071 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 6072 | m_errorMonitor->VerifyFound(); |
| 6073 | |
| 6074 | // Create a buffer to update the descriptor with |
| 6075 | uint32_t qfi = 0; |
| 6076 | VkBufferCreateInfo buffCI = {}; |
| 6077 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 6078 | buffCI.size = 1024; |
| 6079 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 6080 | buffCI.queueFamilyIndexCount = 1; |
| 6081 | buffCI.pQueueFamilyIndices = &qfi; |
| 6082 | |
| 6083 | VkBuffer dyub; |
| 6084 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 6085 | ASSERT_VK_SUCCESS(err); |
| 6086 | VkDescriptorBufferInfo buffInfo = {}; |
| 6087 | buffInfo.buffer = dyub; |
| 6088 | buffInfo.offset = 0; |
| 6089 | buffInfo.range = 1024; |
| 6090 | |
| 6091 | descriptor_write.pBufferInfo = &buffInfo; |
| 6092 | descriptor_write.descriptorCount = 2; |
| 6093 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 6094 | // 2) The stateFlags don't match between the first and second descriptor |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 6095 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage); |
| 6096 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 6097 | m_errorMonitor->VerifyFound(); |
| 6098 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 6099 | // 3) The second descriptor has a null_ptr pImmutableSamplers and |
| 6100 | // the third descriptor contains an immutable sampler |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 6101 | descriptor_write.dstBinding = 1; |
| 6102 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 6103 | |
| 6104 | |
| 6105 | // Make pImageInfo index non-null to avoid complaints of it missing |
| 6106 | VkDescriptorImageInfo imageInfo = {}; |
| 6107 | imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 6108 | descriptor_write.pImageInfo = &imageInfo; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 6109 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage); |
| 6110 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 6111 | m_errorMonitor->VerifyFound(); |
| 6112 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 6113 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
| 6114 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 6115 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6116 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6117 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 6118 | } |
| 6119 | |
Tobin Ehlis | 0283c4d | 2016-06-28 17:57:07 -0600 | [diff] [blame] | 6120 | TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) { |
| 6121 | TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid " |
| 6122 | "due to a buffer dependency being destroyed."); |
| 6123 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6124 | |
| 6125 | VkImageObj image(m_device); |
| 6126 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 6127 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 6128 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 6129 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 6130 | ASSERT_TRUE(image.initialized()); |
| 6131 | |
| 6132 | VkBuffer buffer; |
| 6133 | VkDeviceMemory mem; |
| 6134 | VkMemoryRequirements mem_reqs; |
| 6135 | |
| 6136 | VkBufferCreateInfo buf_info = {}; |
| 6137 | buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 6138 | buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 6139 | buf_info.size = 256; |
| 6140 | buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 6141 | VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer); |
| 6142 | ASSERT_VK_SUCCESS(err); |
| 6143 | |
| 6144 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs); |
| 6145 | |
| 6146 | VkMemoryAllocateInfo alloc_info = {}; |
| 6147 | alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 6148 | alloc_info.allocationSize = 256; |
| 6149 | bool pass = false; |
| 6150 | pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, |
| 6151 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 6152 | if (!pass) { |
| 6153 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 6154 | return; |
| 6155 | } |
| 6156 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem); |
| 6157 | ASSERT_VK_SUCCESS(err); |
| 6158 | |
| 6159 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 6160 | ASSERT_VK_SUCCESS(err); |
| 6161 | |
| 6162 | VkBufferImageCopy region = {}; |
| 6163 | region.bufferRowLength = 128; |
| 6164 | region.bufferImageHeight = 128; |
| 6165 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 6166 | |
| 6167 | region.imageSubresource.layerCount = 1; |
| 6168 | region.imageExtent.height = 4; |
| 6169 | region.imageExtent.width = 4; |
| 6170 | region.imageExtent.depth = 1; |
| 6171 | m_commandBuffer->BeginCommandBuffer(); |
| 6172 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, |
| 6173 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 6174 | 1, ®ion); |
| 6175 | m_commandBuffer->EndCommandBuffer(); |
| 6176 | |
| 6177 | m_errorMonitor->SetDesiredFailureMsg( |
| 6178 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6179 | " that is invalid because bound buffer "); |
| 6180 | // Destroy buffer dependency prior to submit to cause ERROR |
| 6181 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 6182 | |
| 6183 | VkSubmitInfo submit_info = {}; |
| 6184 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 6185 | submit_info.commandBufferCount = 1; |
| 6186 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
| 6187 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 6188 | |
| 6189 | m_errorMonitor->VerifyFound(); |
| 6190 | vkFreeMemory(m_device->handle(), mem, NULL); |
| 6191 | } |
| 6192 | |
Tobin Ehlis | 11c8cea | 2016-06-28 17:44:21 -0600 | [diff] [blame] | 6193 | TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) { |
| 6194 | TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid " |
| 6195 | "due to an image dependency being destroyed."); |
| 6196 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6197 | |
| 6198 | VkImage image; |
| 6199 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 6200 | VkImageCreateInfo image_create_info = {}; |
| 6201 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 6202 | image_create_info.pNext = NULL; |
| 6203 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 6204 | image_create_info.format = tex_format; |
| 6205 | image_create_info.extent.width = 32; |
| 6206 | image_create_info.extent.height = 32; |
| 6207 | image_create_info.extent.depth = 1; |
| 6208 | image_create_info.mipLevels = 1; |
| 6209 | image_create_info.arrayLayers = 1; |
| 6210 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 6211 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 6212 | image_create_info.usage = |
| 6213 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 6214 | image_create_info.flags = 0; |
| 6215 | VkResult err = |
| 6216 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 6217 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3d09fd5 | 2016-07-06 08:12:56 -0600 | [diff] [blame] | 6218 | // Have to bind memory to image before recording cmd in cmd buffer using it |
| 6219 | VkMemoryRequirements mem_reqs; |
| 6220 | VkDeviceMemory image_mem; |
| 6221 | bool pass; |
| 6222 | VkMemoryAllocateInfo mem_alloc = {}; |
| 6223 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 6224 | mem_alloc.pNext = NULL; |
| 6225 | mem_alloc.memoryTypeIndex = 0; |
| 6226 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 6227 | mem_alloc.allocationSize = mem_reqs.size; |
| 6228 | pass = |
| 6229 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 6230 | ASSERT_TRUE(pass); |
| 6231 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem); |
| 6232 | ASSERT_VK_SUCCESS(err); |
| 6233 | err = vkBindImageMemory(m_device->device(), image, image_mem, 0); |
| 6234 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 11c8cea | 2016-06-28 17:44:21 -0600 | [diff] [blame] | 6235 | |
Tobin Ehlis | 11c8cea | 2016-06-28 17:44:21 -0600 | [diff] [blame] | 6236 | m_commandBuffer->BeginCommandBuffer(); |
Tobin Ehlis | 764d707 | 2016-07-01 12:54:29 -0600 | [diff] [blame] | 6237 | VkClearColorValue ccv; |
| 6238 | ccv.float32[0] = 1.0f; |
| 6239 | ccv.float32[1] = 1.0f; |
| 6240 | ccv.float32[2] = 1.0f; |
| 6241 | ccv.float32[3] = 1.0f; |
| 6242 | VkImageSubresourceRange isr = {}; |
| 6243 | isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | 3d09fd5 | 2016-07-06 08:12:56 -0600 | [diff] [blame] | 6244 | isr.baseArrayLayer = 0; |
| 6245 | isr.baseMipLevel = 0; |
Tobin Ehlis | 764d707 | 2016-07-01 12:54:29 -0600 | [diff] [blame] | 6246 | isr.layerCount = 1; |
| 6247 | isr.levelCount = 1; |
| 6248 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, |
| 6249 | VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr); |
Tobin Ehlis | 11c8cea | 2016-06-28 17:44:21 -0600 | [diff] [blame] | 6250 | m_commandBuffer->EndCommandBuffer(); |
| 6251 | |
| 6252 | m_errorMonitor->SetDesiredFailureMsg( |
| 6253 | VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image "); |
| 6254 | // Destroy image dependency prior to submit to cause ERROR |
| 6255 | vkDestroyImage(m_device->device(), image, NULL); |
| 6256 | |
| 6257 | VkSubmitInfo submit_info = {}; |
| 6258 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 6259 | submit_info.commandBufferCount = 1; |
| 6260 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
| 6261 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 6262 | |
| 6263 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 3d09fd5 | 2016-07-06 08:12:56 -0600 | [diff] [blame] | 6264 | vkFreeMemory(m_device->device(), image_mem, nullptr); |
Tobin Ehlis | 11c8cea | 2016-06-28 17:44:21 -0600 | [diff] [blame] | 6265 | } |
| 6266 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6267 | TEST_F(VkLayerTest, InvalidPipeline) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6268 | // Attempt to bind an invalid Pipeline to a valid Command Buffer |
| 6269 | // ObjectTracker should catch this. |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 6270 | // Create a valid cmd buffer |
| 6271 | // call vkCmdBindPipeline w/ false Pipeline |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 6272 | uint64_t fake_pipeline_handle = 0xbaad6001; |
| 6273 | VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6274 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6275 | "Invalid VkPipeline Object 0xbaad6001"); |
| 6276 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6277 | BeginCommandBuffer(); |
| 6278 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 6279 | VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline); |
| 6280 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 6281 | // Now issue a draw call with no pipeline bound |
| 6282 | m_errorMonitor->SetDesiredFailureMsg( |
| 6283 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6284 | "At Draw/Dispatch time no valid VkPipeline is bound!"); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 6285 | |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 6286 | BeginCommandBuffer(); |
| 6287 | Draw(1, 0, 0, 0); |
| 6288 | m_errorMonitor->VerifyFound(); |
| 6289 | // Finally same check once more but with Dispatch/Compute |
| 6290 | m_errorMonitor->SetDesiredFailureMsg( |
| 6291 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6292 | "At Draw/Dispatch time no valid VkPipeline is bound!"); |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 6293 | BeginCommandBuffer(); |
| 6294 | vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0); |
| 6295 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 6296 | } |
| 6297 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6298 | TEST_F(VkLayerTest, DescriptorSetNotUpdated) { |
| 6299 | // Create and update CommandBuffer then call QueueSubmit w/o calling End on |
| 6300 | // CommandBuffer |
| 6301 | VkResult err; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6302 | |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 6303 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6304 | " bound but it was never updated. "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6305 | |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6306 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 6307 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 6308 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6309 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6310 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6311 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6312 | |
| 6313 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6314 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6315 | ds_pool_ci.pNext = NULL; |
| 6316 | ds_pool_ci.maxSets = 1; |
| 6317 | ds_pool_ci.poolSizeCount = 1; |
| 6318 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 6319 | |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6320 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6321 | err = |
| 6322 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6323 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6324 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6325 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6326 | dsl_binding.binding = 0; |
| 6327 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6328 | dsl_binding.descriptorCount = 1; |
| 6329 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 6330 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6331 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6332 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6333 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6334 | ds_layout_ci.pNext = NULL; |
| 6335 | ds_layout_ci.bindingCount = 1; |
| 6336 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6337 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6338 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6339 | &ds_layout); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6340 | ASSERT_VK_SUCCESS(err); |
| 6341 | |
| 6342 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6343 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6344 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6345 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6346 | alloc_info.descriptorPool = ds_pool; |
| 6347 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6348 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6349 | &descriptorSet); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6350 | ASSERT_VK_SUCCESS(err); |
| 6351 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6352 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6353 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6354 | pipeline_layout_ci.pNext = NULL; |
| 6355 | pipeline_layout_ci.setLayoutCount = 1; |
| 6356 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6357 | |
| 6358 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6359 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6360 | &pipeline_layout); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6361 | ASSERT_VK_SUCCESS(err); |
| 6362 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6363 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 6364 | VK_SHADER_STAGE_VERTEX_BIT, this); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6365 | // 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] | 6366 | // on more devices |
| 6367 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 6368 | VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6369 | |
Tony Barbour | c95e4ac | 2015-08-04 17:05:26 -0600 | [diff] [blame] | 6370 | VkPipelineObj pipe(m_device); |
| 6371 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 6372 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 6373 | pipe.AddColorAttachment(); |
Tony Barbour | c95e4ac | 2015-08-04 17:05:26 -0600 | [diff] [blame] | 6374 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 6375 | |
| 6376 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6377 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 6378 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 6379 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6380 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6381 | 1, &descriptorSet, 0, NULL); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6382 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6383 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 6384 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6385 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6386 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6387 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6388 | } |
| 6389 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6390 | TEST_F(VkLayerTest, InvalidBufferViewObject) { |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 6391 | // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6392 | VkResult err; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 6393 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6394 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 6395 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer " |
| 6396 | "descriptor with invalid buffer view"); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 6397 | |
| 6398 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6399 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6400 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 6401 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 6402 | |
| 6403 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6404 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6405 | ds_pool_ci.pNext = NULL; |
| 6406 | ds_pool_ci.maxSets = 1; |
| 6407 | ds_pool_ci.poolSizeCount = 1; |
| 6408 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 6409 | |
| 6410 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6411 | err = |
| 6412 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 6413 | ASSERT_VK_SUCCESS(err); |
| 6414 | |
| 6415 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6416 | dsl_binding.binding = 0; |
| 6417 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 6418 | dsl_binding.descriptorCount = 1; |
| 6419 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 6420 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 6421 | |
| 6422 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6423 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6424 | ds_layout_ci.pNext = NULL; |
| 6425 | ds_layout_ci.bindingCount = 1; |
| 6426 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 6427 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6428 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6429 | &ds_layout); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 6430 | ASSERT_VK_SUCCESS(err); |
| 6431 | |
| 6432 | VkDescriptorSet descriptorSet; |
| 6433 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6434 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6435 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 6436 | alloc_info.descriptorPool = ds_pool; |
| 6437 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6438 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6439 | &descriptorSet); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 6440 | ASSERT_VK_SUCCESS(err); |
| 6441 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6442 | VkBufferView view = |
| 6443 | (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 6444 | VkWriteDescriptorSet descriptor_write; |
| 6445 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 6446 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 6447 | descriptor_write.dstSet = descriptorSet; |
| 6448 | descriptor_write.dstBinding = 0; |
| 6449 | descriptor_write.descriptorCount = 1; |
| 6450 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 6451 | descriptor_write.pTexelBufferView = &view; |
| 6452 | |
| 6453 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 6454 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6455 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 6456 | |
| 6457 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6458 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 6459 | } |
| 6460 | |
Mark Young | d339ba3 | 2016-05-30 13:28:35 -0600 | [diff] [blame] | 6461 | TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) { |
| 6462 | TEST_DESCRIPTION("Attempt to create a buffer view with a buffer that has" |
| 6463 | " no memory bound to it."); |
| 6464 | |
| 6465 | VkResult err; |
| 6466 | m_errorMonitor->SetDesiredFailureMsg( |
| 6467 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6468 | "vkCreateBufferView called with invalid memory "); |
| 6469 | |
| 6470 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6471 | |
| 6472 | // Create a buffer with no bound memory and then attempt to create |
| 6473 | // a buffer view. |
| 6474 | VkBufferCreateInfo buff_ci = {}; |
| 6475 | buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 6476 | buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 6477 | buff_ci.size = 256; |
| 6478 | buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 6479 | VkBuffer buffer; |
| 6480 | err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer); |
| 6481 | ASSERT_VK_SUCCESS(err); |
| 6482 | |
| 6483 | VkBufferViewCreateInfo buff_view_ci = {}; |
| 6484 | buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; |
| 6485 | buff_view_ci.buffer = buffer; |
| 6486 | buff_view_ci.format = VK_FORMAT_R8_UNORM; |
| 6487 | buff_view_ci.range = VK_WHOLE_SIZE; |
| 6488 | VkBufferView buff_view; |
| 6489 | err = |
| 6490 | vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view); |
| 6491 | |
| 6492 | m_errorMonitor->VerifyFound(); |
| 6493 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 6494 | // If last error is success, it still created the view, so delete it. |
| 6495 | if (err == VK_SUCCESS) { |
| 6496 | vkDestroyBufferView(m_device->device(), buff_view, NULL); |
| 6497 | } |
| 6498 | } |
| 6499 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6500 | TEST_F(VkLayerTest, InvalidDynamicOffsetCases) { |
| 6501 | // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error |
| 6502 | // cases: |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6503 | // 1. No dynamicOffset supplied |
| 6504 | // 2. Too many dynamicOffsets supplied |
| 6505 | // 3. Dynamic offset oversteps buffer being updated |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6506 | VkResult err; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 6507 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6508 | " requires 1 dynamicOffsets, but only " |
| 6509 | "0 dynamicOffsets are left in " |
| 6510 | "pDynamicOffsets "); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6511 | |
| 6512 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6513 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 6514 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 6515 | |
| 6516 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6517 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 6518 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6519 | |
| 6520 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6521 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6522 | ds_pool_ci.pNext = NULL; |
| 6523 | ds_pool_ci.maxSets = 1; |
| 6524 | ds_pool_ci.poolSizeCount = 1; |
| 6525 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6526 | |
| 6527 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6528 | err = |
| 6529 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6530 | ASSERT_VK_SUCCESS(err); |
| 6531 | |
| 6532 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6533 | dsl_binding.binding = 0; |
| 6534 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 6535 | dsl_binding.descriptorCount = 1; |
| 6536 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 6537 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6538 | |
| 6539 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6540 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6541 | ds_layout_ci.pNext = NULL; |
| 6542 | ds_layout_ci.bindingCount = 1; |
| 6543 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6544 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6545 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6546 | &ds_layout); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6547 | ASSERT_VK_SUCCESS(err); |
| 6548 | |
| 6549 | VkDescriptorSet descriptorSet; |
| 6550 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6551 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6552 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6553 | alloc_info.descriptorPool = ds_pool; |
| 6554 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6555 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6556 | &descriptorSet); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6557 | ASSERT_VK_SUCCESS(err); |
| 6558 | |
| 6559 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6560 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6561 | pipeline_layout_ci.pNext = NULL; |
| 6562 | pipeline_layout_ci.setLayoutCount = 1; |
| 6563 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6564 | |
| 6565 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6566 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6567 | &pipeline_layout); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6568 | ASSERT_VK_SUCCESS(err); |
| 6569 | |
| 6570 | // Create a buffer to update the descriptor with |
| 6571 | uint32_t qfi = 0; |
| 6572 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6573 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 6574 | buffCI.size = 1024; |
| 6575 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 6576 | buffCI.queueFamilyIndexCount = 1; |
| 6577 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6578 | |
| 6579 | VkBuffer dyub; |
| 6580 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 6581 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 6582 | // Allocate memory and bind to buffer so we can make it to the appropriate |
| 6583 | // error |
| 6584 | VkMemoryAllocateInfo mem_alloc = {}; |
| 6585 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 6586 | mem_alloc.pNext = NULL; |
| 6587 | mem_alloc.allocationSize = 1024; |
Chris Forbes | b6116cc | 2016-05-08 11:39:59 +1200 | [diff] [blame] | 6588 | mem_alloc.memoryTypeIndex = 0; |
| 6589 | |
| 6590 | VkMemoryRequirements memReqs; |
| 6591 | vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs); |
| 6592 | bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, |
| 6593 | 0); |
| 6594 | if (!pass) { |
| 6595 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
| 6596 | return; |
| 6597 | } |
| 6598 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 6599 | VkDeviceMemory mem; |
| 6600 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 6601 | ASSERT_VK_SUCCESS(err); |
| 6602 | err = vkBindBufferMemory(m_device->device(), dyub, mem, 0); |
| 6603 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6604 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 6605 | VkDescriptorBufferInfo buffInfo = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6606 | buffInfo.buffer = dyub; |
| 6607 | buffInfo.offset = 0; |
| 6608 | buffInfo.range = 1024; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6609 | |
| 6610 | VkWriteDescriptorSet descriptor_write; |
| 6611 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 6612 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 6613 | descriptor_write.dstSet = descriptorSet; |
| 6614 | descriptor_write.dstBinding = 0; |
| 6615 | descriptor_write.descriptorCount = 1; |
| 6616 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 6617 | descriptor_write.pBufferInfo = &buffInfo; |
| 6618 | |
| 6619 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 6620 | |
| 6621 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6622 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6623 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6624 | 1, &descriptorSet, 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6625 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6626 | uint32_t pDynOff[2] = {512, 756}; |
| 6627 | // 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] | 6628 | m_errorMonitor->SetDesiredFailureMsg( |
| 6629 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6630 | "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6631 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6632 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6633 | 1, &descriptorSet, 2, pDynOff); |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 6634 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6635 | // Finally cause error due to dynamicOffset being too big |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 6636 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6637 | " dynamic offset 512 combined with " |
| 6638 | "offset 0 and range 1024 that " |
| 6639 | "oversteps the buffer size of 1024"); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6640 | // Create PSO to be used for draw-time errors below |
| 6641 | char const *vsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 6642 | "#version 450\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6643 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 6644 | "out gl_PerVertex { \n" |
| 6645 | " vec4 gl_Position;\n" |
| 6646 | "};\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6647 | "void main(){\n" |
| 6648 | " gl_Position = vec4(1);\n" |
| 6649 | "}\n"; |
| 6650 | char const *fsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 6651 | "#version 450\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6652 | "\n" |
| 6653 | "layout(location=0) out vec4 x;\n" |
| 6654 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 6655 | "void main(){\n" |
| 6656 | " x = vec4(bar.y);\n" |
| 6657 | "}\n"; |
| 6658 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6659 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 6660 | VkPipelineObj pipe(m_device); |
| 6661 | pipe.AddShader(&vs); |
| 6662 | pipe.AddShader(&fs); |
| 6663 | pipe.AddColorAttachment(); |
| 6664 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 6665 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6666 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 6667 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 6668 | // This update should succeed, but offset size of 512 will overstep buffer |
| 6669 | // /w range 1024 & size 1024 |
| 6670 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6671 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6672 | 1, &descriptorSet, 1, pDynOff); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 6673 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6674 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6675 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 6676 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
Tobin Ehlis | 512098e | 2016-05-05 09:06:12 -0600 | [diff] [blame] | 6677 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 6678 | |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6679 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 6680 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 6681 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 6682 | } |
| 6683 | |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6684 | TEST_F(VkLayerTest, InvalidPushConstants) { |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6685 | VkResult err; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6686 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6687 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 6688 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 6689 | |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6690 | VkPipelineLayout pipeline_layout; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6691 | VkPushConstantRange pc_range = {}; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6692 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 6693 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6694 | pipeline_layout_ci.pushConstantRangeCount = 1; |
| 6695 | pipeline_layout_ci.pPushConstantRanges = &pc_range; |
| 6696 | |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6697 | // |
| 6698 | // Check for invalid push constant ranges in pipeline layouts. |
| 6699 | // |
| 6700 | struct PipelineLayoutTestCase { |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6701 | VkPushConstantRange const range; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6702 | char const *msg; |
| 6703 | }; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6704 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6705 | const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4; |
| 6706 | const std::array<PipelineLayoutTestCase, 10> range_tests = {{ |
| 6707 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, |
| 6708 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 6709 | "size 0."}, |
| 6710 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1}, |
| 6711 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 6712 | "size 1."}, |
| 6713 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1}, |
| 6714 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 6715 | "size 1."}, |
| 6716 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0}, |
| 6717 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 6718 | "size 0."}, |
| 6719 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4}, |
| 6720 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 6721 | "offset 1. Offset must"}, |
| 6722 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big}, |
| 6723 | "vkCreatePipelineLayout() call has push constants index 0 " |
| 6724 | "with offset "}, |
| 6725 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big}, |
| 6726 | "vkCreatePipelineLayout() call has push constants " |
| 6727 | "index 0 with offset "}, |
| 6728 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0}, |
| 6729 | "vkCreatePipelineLayout() call has push constants index 0 " |
| 6730 | "with offset "}, |
| 6731 | {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020}, |
| 6732 | "vkCreatePipelineLayout() call has push " |
| 6733 | "constants index 0 with offset "}, |
| 6734 | {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0}, |
| 6735 | "vkCreatePipelineLayout() call has push " |
| 6736 | "constants index 0 with offset "}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6737 | }}; |
| 6738 | |
| 6739 | // Check for invalid offset and size |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6740 | for (const auto &iter : range_tests) { |
| 6741 | pc_range = iter.range; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6742 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6743 | iter.msg); |
| 6744 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 6745 | NULL, &pipeline_layout); |
| 6746 | m_errorMonitor->VerifyFound(); |
| 6747 | if (VK_SUCCESS == err) { |
| 6748 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6749 | } |
| 6750 | } |
| 6751 | |
| 6752 | // Check for invalid stage flag |
| 6753 | pc_range.offset = 0; |
| 6754 | pc_range.size = 16; |
| 6755 | pc_range.stageFlags = 0; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6756 | m_errorMonitor->SetDesiredFailureMsg( |
| 6757 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6758 | "vkCreatePipelineLayout() call has no stageFlags set."); |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6759 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6760 | &pipeline_layout); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6761 | m_errorMonitor->VerifyFound(); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6762 | if (VK_SUCCESS == err) { |
| 6763 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6764 | } |
| 6765 | |
| 6766 | // Check for overlapping ranges |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6767 | const uint32_t ranges_per_test = 5; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6768 | struct OverlappingRangeTestCase { |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6769 | VkPushConstantRange const ranges[ranges_per_test]; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6770 | char const *msg; |
| 6771 | }; |
| 6772 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6773 | const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6774 | {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6775 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6776 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6777 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6778 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 6779 | "vkCreatePipelineLayout() call has push constants with overlapping " |
| 6780 | "ranges: 0:[0, 4), 1:[0, 4)"}, |
| 6781 | { |
| 6782 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6783 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 6784 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 6785 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 6786 | {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}}, |
| 6787 | "vkCreatePipelineLayout() call has push constants with " |
| 6788 | "overlapping " |
| 6789 | "ranges: 3:[12, 20), 4:[16, 20)", |
| 6790 | }, |
| 6791 | { |
| 6792 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 6793 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 6794 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 6795 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 6796 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 6797 | "vkCreatePipelineLayout() call has push constants with " |
| 6798 | "overlapping " |
| 6799 | "ranges: 0:[16, 20), 1:[12, 20)", |
| 6800 | }, |
| 6801 | { |
| 6802 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 6803 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 6804 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 6805 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 6806 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 6807 | "vkCreatePipelineLayout() call has push constants with " |
| 6808 | "overlapping " |
| 6809 | "ranges: 0:[16, 20), 3:[12, 20)", |
| 6810 | }, |
| 6811 | { |
| 6812 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 6813 | {VK_SHADER_STAGE_VERTEX_BIT, 32, 4}, |
| 6814 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 96}, |
| 6815 | {VK_SHADER_STAGE_VERTEX_BIT, 40, 8}, |
| 6816 | {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}}, |
| 6817 | "vkCreatePipelineLayout() call has push constants with " |
| 6818 | "overlapping " |
| 6819 | "ranges: 0:[16, 20), 2:[4, 100)", |
| 6820 | }}}; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6821 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6822 | for (const auto &iter : overlapping_range_tests) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6823 | pipeline_layout_ci.pPushConstantRanges = iter.ranges; |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6824 | pipeline_layout_ci.pushConstantRangeCount = ranges_per_test; |
| 6825 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6826 | iter.msg); |
| 6827 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 6828 | NULL, &pipeline_layout); |
| 6829 | m_errorMonitor->VerifyFound(); |
| 6830 | if (VK_SUCCESS == err) { |
| 6831 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6832 | } |
| 6833 | } |
| 6834 | |
| 6835 | // 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] | 6836 | const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = |
| 6837 | {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6838 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 6839 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 6840 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 4}, |
| 6841 | {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}}, |
| 6842 | ""}, |
| 6843 | {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24}, |
| 6844 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 4}, |
| 6845 | {VK_SHADER_STAGE_VERTEX_BIT, 64, 8}, |
| 6846 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 16}, |
| 6847 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 6848 | ""}}}; |
| 6849 | for (const auto &iter : overlapping_range_tests_pos) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6850 | pipeline_layout_ci.pPushConstantRanges = iter.ranges; |
| 6851 | m_errorMonitor->ExpectSuccess(); |
| 6852 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 6853 | NULL, &pipeline_layout); |
| 6854 | m_errorMonitor->VerifyNotFound(); |
| 6855 | if (VK_SUCCESS == err) { |
| 6856 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6857 | } |
| 6858 | } |
| 6859 | |
| 6860 | // |
| 6861 | // CmdPushConstants tests |
| 6862 | // |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6863 | const uint8_t dummy_values[100] = {}; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6864 | |
| 6865 | // 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] | 6866 | const std::array<PipelineLayoutTestCase, 16> cmd_range_tests = {{ |
| 6867 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, |
| 6868 | "vkCmdPushConstants() call has push constants with size 0. Size " |
| 6869 | "must be greater than zero and a multiple of 4."}, |
| 6870 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1}, |
| 6871 | "vkCmdPushConstants() call has push constants with size 1. Size " |
| 6872 | "must be greater than zero and a multiple of 4."}, |
| 6873 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1}, |
| 6874 | "vkCmdPushConstants() call has push constants with size 1. Size " |
| 6875 | "must be greater than zero and a multiple of 4."}, |
| 6876 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0}, |
| 6877 | "vkCmdPushConstants() call has push constants with offset 1. " |
| 6878 | "Offset must be a multiple of 4."}, |
| 6879 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4}, |
| 6880 | "vkCmdPushConstants() call has push constants with offset 1. " |
| 6881 | "Offset must be a multiple of 4."}, |
| 6882 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20}, |
| 6883 | "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = " |
| 6884 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6885 | {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8}, |
| 6886 | "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = " |
| 6887 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6888 | {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8}, |
| 6889 | "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = " |
| 6890 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6891 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80}, |
| 6892 | "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = " |
| 6893 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6894 | {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4}, |
| 6895 | "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in " |
| 6896 | "any of the ranges in pipeline layout"}, |
| 6897 | {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, |
| 6898 | 0, 16}, |
| 6899 | "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in " |
| 6900 | "any of the ranges in pipeline layout"}, |
| 6901 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6902 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6903 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6904 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6905 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6906 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6907 | {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6908 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6909 | {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6910 | "vkCmdPushConstants() call has push constants with offset "}, |
| 6911 | }}; |
| 6912 | |
| 6913 | // Two ranges for testing robustness |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6914 | const VkPushConstantRange pc_range2[] = { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6915 | {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6916 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6917 | }; |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6918 | pipeline_layout_ci.pushConstantRangeCount = |
| 6919 | sizeof(pc_range2) / sizeof(VkPushConstantRange); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6920 | pipeline_layout_ci.pPushConstantRanges = pc_range2; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6921 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6922 | &pipeline_layout); |
| 6923 | ASSERT_VK_SUCCESS(err); |
| 6924 | BeginCommandBuffer(); |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6925 | for (const auto &iter : cmd_range_tests) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6926 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6927 | iter.msg); |
| 6928 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6929 | iter.range.stageFlags, iter.range.offset, |
| 6930 | iter.range.size, dummy_values); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6931 | m_errorMonitor->VerifyFound(); |
| 6932 | } |
| 6933 | |
| 6934 | // Check for invalid stage flag |
| 6935 | m_errorMonitor->SetDesiredFailureMsg( |
| 6936 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6937 | "vkCmdPushConstants() call has no stageFlags set."); |
| 6938 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6939 | 0, 16, dummy_values); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6940 | m_errorMonitor->VerifyFound(); |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6941 | EndCommandBuffer(); |
| 6942 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
| 6943 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6944 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6945 | // overlapping range tests with cmd |
| 6946 | const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{ |
| 6947 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20}, |
| 6948 | "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = " |
| 6949 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6950 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 6951 | "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = " |
| 6952 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6953 | {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16}, |
| 6954 | "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = " |
| 6955 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6956 | }}; |
| 6957 | const VkPushConstantRange pc_range3[] = { |
| 6958 | {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, |
| 6959 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
| 6960 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6961 | {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, |
| 6962 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, |
| 6963 | {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, |
| 6964 | {VK_SHADER_STAGE_VERTEX_BIT, 56, 28}, |
| 6965 | }; |
| 6966 | pipeline_layout_ci.pushConstantRangeCount = |
| 6967 | sizeof(pc_range3) / sizeof(VkPushConstantRange); |
| 6968 | pipeline_layout_ci.pPushConstantRanges = pc_range3; |
| 6969 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6970 | &pipeline_layout); |
| 6971 | ASSERT_VK_SUCCESS(err); |
| 6972 | BeginCommandBuffer(); |
| 6973 | for (const auto &iter : cmd_overlap_tests) { |
| 6974 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6975 | iter.msg); |
| 6976 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
| 6977 | iter.range.stageFlags, iter.range.offset, |
| 6978 | iter.range.size, dummy_values); |
| 6979 | m_errorMonitor->VerifyFound(); |
| 6980 | } |
| 6981 | EndCommandBuffer(); |
| 6982 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
| 6983 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6984 | |
| 6985 | // positive overlapping range tests with cmd |
| 6986 | const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{ |
| 6987 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""}, |
| 6988 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""}, |
| 6989 | {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""}, |
| 6990 | {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""}, |
| 6991 | }}; |
| 6992 | const VkPushConstantRange pc_range4[] = { |
| 6993 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 64}, |
| 6994 | {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, |
| 6995 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
| 6996 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6997 | {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, |
| 6998 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, |
| 6999 | {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, |
| 7000 | {VK_SHADER_STAGE_VERTEX_BIT, 56, 28}, |
| 7001 | }; |
| 7002 | pipeline_layout_ci.pushConstantRangeCount = |
| 7003 | sizeof(pc_range4) / sizeof(VkPushConstantRange); |
| 7004 | pipeline_layout_ci.pPushConstantRanges = pc_range4; |
| 7005 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7006 | &pipeline_layout); |
| 7007 | ASSERT_VK_SUCCESS(err); |
| 7008 | BeginCommandBuffer(); |
| 7009 | for (const auto &iter : cmd_overlap_tests_pos) { |
| 7010 | m_errorMonitor->ExpectSuccess(); |
| 7011 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
| 7012 | iter.range.stageFlags, iter.range.offset, |
| 7013 | iter.range.size, dummy_values); |
| 7014 | m_errorMonitor->VerifyNotFound(); |
| 7015 | } |
| 7016 | EndCommandBuffer(); |
| 7017 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 7018 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7019 | } |
| 7020 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7021 | TEST_F(VkLayerTest, DescriptorSetCompatibility) { |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7022 | // Test various desriptorSet errors with bad binding combinations |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7023 | VkResult err; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7024 | |
| 7025 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7026 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 7027 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7028 | |
Mike Stroyan | b8a6100 | 2016-06-20 16:00:28 -0600 | [diff] [blame] | 7029 | const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM; |
| 7030 | VkImageTiling tiling; |
| 7031 | VkFormatProperties format_properties; |
| 7032 | vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties); |
| 7033 | if (format_properties.linearTilingFeatures & |
| 7034 | VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) { |
| 7035 | tiling = VK_IMAGE_TILING_LINEAR; |
| 7036 | } else if (format_properties.optimalTilingFeatures & |
| 7037 | VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) { |
| 7038 | tiling = VK_IMAGE_TILING_OPTIMAL; |
| 7039 | } else { |
| 7040 | printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; " |
| 7041 | "skipped.\n"); |
| 7042 | return; |
| 7043 | } |
| 7044 | |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7045 | static const uint32_t NUM_DESCRIPTOR_TYPES = 5; |
| 7046 | VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7047 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7048 | ds_type_count[0].descriptorCount = 10; |
| 7049 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 7050 | ds_type_count[1].descriptorCount = 2; |
| 7051 | ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
| 7052 | ds_type_count[2].descriptorCount = 2; |
| 7053 | ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 7054 | ds_type_count[3].descriptorCount = 5; |
| 7055 | // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT |
| 7056 | // type |
| 7057 | // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 7058 | ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
| 7059 | ds_type_count[4].descriptorCount = 2; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7060 | |
| 7061 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7062 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7063 | ds_pool_ci.pNext = NULL; |
| 7064 | ds_pool_ci.maxSets = 5; |
| 7065 | ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES; |
| 7066 | ds_pool_ci.pPoolSizes = ds_type_count; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7067 | |
| 7068 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7069 | err = |
| 7070 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7071 | ASSERT_VK_SUCCESS(err); |
| 7072 | |
| 7073 | static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2; |
| 7074 | VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7075 | dsl_binding[0].binding = 0; |
| 7076 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7077 | dsl_binding[0].descriptorCount = 5; |
| 7078 | dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 7079 | dsl_binding[0].pImmutableSamplers = NULL; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7080 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7081 | // Create layout identical to set0 layout but w/ different stageFlags |
| 7082 | VkDescriptorSetLayoutBinding dsl_fs_stage_only = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7083 | dsl_fs_stage_only.binding = 0; |
| 7084 | dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7085 | dsl_fs_stage_only.descriptorCount = 5; |
| 7086 | dsl_fs_stage_only.stageFlags = |
| 7087 | VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at |
| 7088 | // bind time |
| 7089 | dsl_fs_stage_only.pImmutableSamplers = NULL; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7090 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7091 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7092 | ds_layout_ci.pNext = NULL; |
| 7093 | ds_layout_ci.bindingCount = 1; |
| 7094 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7095 | static const uint32_t NUM_LAYOUTS = 4; |
| 7096 | VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7097 | VkDescriptorSetLayout ds_layout_fs_only = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7098 | // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only |
| 7099 | // layout for error case |
| 7100 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7101 | &ds_layout[0]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7102 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 7103 | ds_layout_ci.pBindings = &dsl_fs_stage_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7104 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7105 | &ds_layout_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7106 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7107 | dsl_binding[0].binding = 0; |
| 7108 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7109 | dsl_binding[0].descriptorCount = 2; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 7110 | dsl_binding[1].binding = 1; |
| 7111 | dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
| 7112 | dsl_binding[1].descriptorCount = 2; |
| 7113 | dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL; |
| 7114 | dsl_binding[1].pImmutableSamplers = NULL; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 7115 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7116 | ds_layout_ci.bindingCount = 2; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7117 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7118 | &ds_layout[1]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7119 | ASSERT_VK_SUCCESS(err); |
| 7120 | dsl_binding[0].binding = 0; |
| 7121 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7122 | dsl_binding[0].descriptorCount = 5; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7123 | ds_layout_ci.bindingCount = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7124 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7125 | &ds_layout[2]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7126 | ASSERT_VK_SUCCESS(err); |
| 7127 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7128 | dsl_binding[0].descriptorCount = 2; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7129 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7130 | &ds_layout[3]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7131 | ASSERT_VK_SUCCESS(err); |
| 7132 | |
| 7133 | static const uint32_t NUM_SETS = 4; |
| 7134 | VkDescriptorSet descriptorSet[NUM_SETS] = {}; |
| 7135 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7136 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7137 | alloc_info.descriptorSetCount = NUM_LAYOUTS; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7138 | alloc_info.descriptorPool = ds_pool; |
| 7139 | alloc_info.pSetLayouts = ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7140 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7141 | descriptorSet); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7142 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7143 | VkDescriptorSet ds0_fs_only = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7144 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7145 | alloc_info.pSetLayouts = &ds_layout_fs_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7146 | err = |
| 7147 | vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7148 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7149 | |
| 7150 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7151 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7152 | pipeline_layout_ci.pNext = NULL; |
| 7153 | pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS; |
| 7154 | pipeline_layout_ci.pSetLayouts = ds_layout; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7155 | |
| 7156 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7157 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7158 | &pipeline_layout); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7159 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7160 | // Create pipelineLayout with only one setLayout |
| 7161 | pipeline_layout_ci.setLayoutCount = 1; |
| 7162 | VkPipelineLayout single_pipe_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7163 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7164 | &single_pipe_layout); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7165 | ASSERT_VK_SUCCESS(err); |
| 7166 | // Create pipelineLayout with 2 descriptor setLayout at index 0 |
| 7167 | pipeline_layout_ci.pSetLayouts = &ds_layout[3]; |
| 7168 | VkPipelineLayout pipe_layout_one_desc; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7169 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7170 | &pipe_layout_one_desc); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7171 | ASSERT_VK_SUCCESS(err); |
| 7172 | // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0 |
| 7173 | pipeline_layout_ci.pSetLayouts = &ds_layout[2]; |
| 7174 | VkPipelineLayout pipe_layout_five_samp; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7175 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7176 | &pipe_layout_five_samp); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7177 | ASSERT_VK_SUCCESS(err); |
| 7178 | // Create pipelineLayout with UB type, but stageFlags for FS only |
| 7179 | pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only; |
| 7180 | VkPipelineLayout pipe_layout_fs_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7181 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7182 | &pipe_layout_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7183 | ASSERT_VK_SUCCESS(err); |
| 7184 | // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine |
| 7185 | VkDescriptorSetLayout pl_bad_s0[2] = {}; |
| 7186 | pl_bad_s0[0] = ds_layout_fs_only; |
| 7187 | pl_bad_s0[1] = ds_layout[1]; |
| 7188 | pipeline_layout_ci.setLayoutCount = 2; |
| 7189 | pipeline_layout_ci.pSetLayouts = pl_bad_s0; |
| 7190 | VkPipelineLayout pipe_layout_bad_set0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7191 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7192 | &pipe_layout_bad_set0); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7193 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7194 | |
| 7195 | // Create a buffer to update the descriptor with |
| 7196 | uint32_t qfi = 0; |
| 7197 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7198 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 7199 | buffCI.size = 1024; |
| 7200 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 7201 | buffCI.queueFamilyIndexCount = 1; |
| 7202 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7203 | |
| 7204 | VkBuffer dyub; |
| 7205 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 7206 | ASSERT_VK_SUCCESS(err); |
| 7207 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 7208 | static const uint32_t NUM_BUFFS = 5; |
| 7209 | VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7210 | for (uint32_t i = 0; i < NUM_BUFFS; ++i) { |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7211 | buffInfo[i].buffer = dyub; |
| 7212 | buffInfo[i].offset = 0; |
| 7213 | buffInfo[i].range = 1024; |
| 7214 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7215 | VkImage image; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7216 | const int32_t tex_width = 32; |
| 7217 | const int32_t tex_height = 32; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7218 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7219 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 7220 | image_create_info.pNext = NULL; |
| 7221 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 7222 | image_create_info.format = tex_format; |
| 7223 | image_create_info.extent.width = tex_width; |
| 7224 | image_create_info.extent.height = tex_height; |
| 7225 | image_create_info.extent.depth = 1; |
| 7226 | image_create_info.mipLevels = 1; |
| 7227 | image_create_info.arrayLayers = 1; |
| 7228 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | b8a6100 | 2016-06-20 16:00:28 -0600 | [diff] [blame] | 7229 | image_create_info.tiling = tiling; |
| 7230 | image_create_info.usage = |
| 7231 | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7232 | image_create_info.flags = 0; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7233 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 7234 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7235 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7236 | VkMemoryRequirements memReqs; |
| 7237 | VkDeviceMemory imageMem; |
| 7238 | bool pass; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 7239 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7240 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 7241 | memAlloc.pNext = NULL; |
| 7242 | memAlloc.allocationSize = 0; |
| 7243 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 7244 | vkGetImageMemoryRequirements(m_device->device(), image, &memReqs); |
| 7245 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7246 | pass = |
| 7247 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 7248 | ASSERT_TRUE(pass); |
| 7249 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem); |
| 7250 | ASSERT_VK_SUCCESS(err); |
| 7251 | err = vkBindImageMemory(m_device->device(), image, imageMem, 0); |
| 7252 | ASSERT_VK_SUCCESS(err); |
| 7253 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7254 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7255 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 7256 | image_view_create_info.image = image; |
| 7257 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 7258 | image_view_create_info.format = tex_format; |
| 7259 | image_view_create_info.subresourceRange.layerCount = 1; |
| 7260 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 7261 | image_view_create_info.subresourceRange.levelCount = 1; |
| 7262 | image_view_create_info.subresourceRange.aspectMask = |
| 7263 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7264 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7265 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7266 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 7267 | &view); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7268 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 7269 | VkDescriptorImageInfo imageInfo[4] = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7270 | imageInfo[0].imageView = view; |
| 7271 | imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 7272 | imageInfo[1].imageView = view; |
| 7273 | imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 7274 | imageInfo[2].imageView = view; |
| 7275 | imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 7276 | imageInfo[3].imageView = view; |
| 7277 | imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7278 | |
| 7279 | static const uint32_t NUM_SET_UPDATES = 3; |
| 7280 | VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {}; |
| 7281 | descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 7282 | descriptor_write[0].dstSet = descriptorSet[0]; |
| 7283 | descriptor_write[0].dstBinding = 0; |
| 7284 | descriptor_write[0].descriptorCount = 5; |
| 7285 | descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7286 | descriptor_write[0].pBufferInfo = buffInfo; |
| 7287 | descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 7288 | descriptor_write[1].dstSet = descriptorSet[1]; |
| 7289 | descriptor_write[1].dstBinding = 0; |
| 7290 | descriptor_write[1].descriptorCount = 2; |
| 7291 | descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 7292 | descriptor_write[1].pImageInfo = imageInfo; |
| 7293 | descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 7294 | descriptor_write[2].dstSet = descriptorSet[1]; |
| 7295 | descriptor_write[2].dstBinding = 1; |
| 7296 | descriptor_write[2].descriptorCount = 2; |
| 7297 | descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 7298 | descriptor_write[2].pImageInfo = &imageInfo[2]; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7299 | |
| 7300 | vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7301 | |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 7302 | // Create PSO to be used for draw-time errors below |
| 7303 | char const *vsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 7304 | "#version 450\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 7305 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 7306 | "out gl_PerVertex {\n" |
| 7307 | " vec4 gl_Position;\n" |
| 7308 | "};\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 7309 | "void main(){\n" |
| 7310 | " gl_Position = vec4(1);\n" |
| 7311 | "}\n"; |
| 7312 | char const *fsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 7313 | "#version 450\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 7314 | "\n" |
| 7315 | "layout(location=0) out vec4 x;\n" |
| 7316 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 7317 | "void main(){\n" |
| 7318 | " x = vec4(bar.y);\n" |
| 7319 | "}\n"; |
| 7320 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7321 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7322 | VkPipelineObj pipe(m_device); |
| 7323 | pipe.AddShader(&vs); |
| 7324 | pipe.AddShader(&fs); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 7325 | pipe.AddColorAttachment(); |
| 7326 | pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass()); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7327 | |
| 7328 | BeginCommandBuffer(); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 7329 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7330 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7331 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 7332 | // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding |
| 7333 | // of PSO |
| 7334 | // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of |
| 7335 | // cmd_pipeline.c |
| 7336 | // due to the fact that cmd_alloc_dset_data() has not been called in |
| 7337 | // cmd_bind_graphics_pipeline() |
| 7338 | // TODO : Want to cause various binding incompatibility issues here to test |
| 7339 | // DrawState |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7340 | // First cause various verify_layout_compatibility() fails |
| 7341 | // Second disturb early and late sets and verify INFO msgs |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7342 | // verify_set_layout_compatibility fail cases: |
| 7343 | // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7344 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 10fad69 | 2016-07-07 12:00:36 -0600 | [diff] [blame] | 7345 | "Invalid VkPipelineLayout Object "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7346 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 7347 | VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 7348 | (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, |
| 7349 | &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7350 | m_errorMonitor->VerifyFound(); |
| 7351 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7352 | // 2. layoutIndex exceeds # of layouts in layout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7353 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7354 | " attempting to bind set to index 1"); |
| 7355 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 7356 | VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, |
| 7357 | 0, 2, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7358 | m_errorMonitor->VerifyFound(); |
| 7359 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7360 | vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7361 | // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5 |
| 7362 | // descriptors |
| 7363 | m_errorMonitor->SetDesiredFailureMsg( |
| 7364 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 7365 | " has 2 descriptors, but DescriptorSetLayout "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7366 | vkCmdBindDescriptorSets( |
| 7367 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 7368 | pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7369 | m_errorMonitor->VerifyFound(); |
| 7370 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7371 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL); |
| 7372 | // 4. same # of descriptors but mismatch in type |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7373 | m_errorMonitor->SetDesiredFailureMsg( |
| 7374 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 7375 | " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7376 | vkCmdBindDescriptorSets( |
| 7377 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 7378 | pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7379 | m_errorMonitor->VerifyFound(); |
| 7380 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7381 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL); |
| 7382 | // 5. same # of descriptors but mismatch in stageFlags |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7383 | m_errorMonitor->SetDesiredFailureMsg( |
| 7384 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 7385 | " has stageFlags 16 but binding 0 for DescriptorSetLayout "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7386 | vkCmdBindDescriptorSets( |
| 7387 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 7388 | pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7389 | m_errorMonitor->VerifyFound(); |
| 7390 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7391 | // Cause INFO messages due to disturbing previously bound Sets |
| 7392 | // First bind sets 0 & 1 |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7393 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 7394 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 7395 | 2, &descriptorSet[0], 0, NULL); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7396 | // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7397 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 7398 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7399 | " previously bound as set #0 was disturbed "); |
| 7400 | vkCmdBindDescriptorSets( |
| 7401 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 7402 | pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7403 | m_errorMonitor->VerifyFound(); |
| 7404 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7405 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 7406 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 7407 | 2, &descriptorSet[0], 0, NULL); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7408 | // 2. Disturb set after last bound set |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 7409 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7410 | " newly bound as set #0 so set #1 and " |
| 7411 | "any subsequent sets were disturbed "); |
| 7412 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 7413 | VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 7414 | pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7415 | m_errorMonitor->VerifyFound(); |
| 7416 | |
Tobin Ehlis | 10fad69 | 2016-07-07 12:00:36 -0600 | [diff] [blame] | 7417 | // Now that we're done actively using the pipelineLayout that gfx pipeline |
| 7418 | // was created with, we should be able to delete it. Do that now to verify |
| 7419 | // that validation obeys pipelineLayout lifetime |
| 7420 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL); |
| 7421 | |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 7422 | // Cause draw-time errors due to PSO incompatibilities |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7423 | // 1. Error due to not binding required set (we actually use same code as |
| 7424 | // above to disturb set0) |
| 7425 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 7426 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 7427 | 2, &descriptorSet[0], 0, NULL); |
| 7428 | vkCmdBindDescriptorSets( |
| 7429 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 7430 | pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL); |
| 7431 | m_errorMonitor->SetDesiredFailureMsg( |
| 7432 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7433 | " uses set #0 but that set is not bound."); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 7434 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7435 | m_errorMonitor->VerifyFound(); |
| 7436 | |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 7437 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7438 | // 2. Error due to bound set not being compatible with PSO's |
| 7439 | // VkPipelineLayout (diff stageFlags in this case) |
| 7440 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 7441 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 7442 | 2, &descriptorSet[0], 0, NULL); |
| 7443 | m_errorMonitor->SetDesiredFailureMsg( |
| 7444 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7445 | " bound as set #0 is not compatible with "); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 7446 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7447 | m_errorMonitor->VerifyFound(); |
| 7448 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7449 | // Remaining clean-up |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7450 | for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) { |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7451 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL); |
| 7452 | } |
| 7453 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL); |
Tobin Ehlis | 9bfd449 | 2016-05-05 15:09:11 -0600 | [diff] [blame] | 7454 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only); |
| 7455 | vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 7456 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7457 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7458 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7459 | vkFreeMemory(m_device->device(), imageMem, NULL); |
| 7460 | vkDestroyImage(m_device->device(), image, NULL); |
| 7461 | vkDestroyImageView(m_device->device(), view, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7462 | } |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 7463 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7464 | TEST_F(VkLayerTest, NoBeginCommandBuffer) { |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7465 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7466 | m_errorMonitor->SetDesiredFailureMsg( |
| 7467 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7468 | "You must call vkBeginCommandBuffer() before this call to "); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7469 | |
| 7470 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7471 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7472 | // Call EndCommandBuffer() w/o calling BeginCommandBuffer() |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7473 | vkEndCommandBuffer(commandBuffer.GetBufferHandle()); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7474 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7475 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7476 | } |
| 7477 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7478 | TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) { |
| 7479 | VkResult err; |
| 7480 | VkCommandBuffer draw_cmd; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7481 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7482 | m_errorMonitor->SetDesiredFailureMsg( |
| 7483 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 61b36f3 | 2015-12-16 08:19:42 -0700 | [diff] [blame] | 7484 | " must specify a valid renderpass parameter."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7485 | |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 7486 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 7487 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7488 | VkCommandBufferAllocateInfo cmd = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 7489 | cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 7490 | cmd.pNext = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7491 | cmd.commandPool = m_commandPool; |
| 7492 | cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7493 | cmd.commandBufferCount = 1; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 7494 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7495 | err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 7496 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 7497 | |
| 7498 | // Force the failure by not setting the Renderpass and Framebuffer fields |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7499 | VkCommandBufferBeginInfo cmd_buf_info = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7500 | VkCommandBufferInheritanceInfo cmd_buf_hinfo = {}; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7501 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 7502 | cmd_buf_info.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7503 | cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | |
| 7504 | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7505 | cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo; |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 7506 | |
| 7507 | // The error should be caught by validation of the BeginCommandBuffer call |
| 7508 | vkBeginCommandBuffer(draw_cmd, &cmd_buf_info); |
| 7509 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7510 | m_errorMonitor->VerifyFound(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7511 | vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 7512 | } |
| 7513 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7514 | TEST_F(VkLayerTest, CommandBufferResetErrors) { |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 7515 | // Cause error due to Begin while recording CB |
| 7516 | // Then cause 2 errors for attempting to reset CB w/o having |
| 7517 | // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from |
| 7518 | // which CBs were allocated. Note that this bit is off by default. |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 7519 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7520 | "Cannot call Begin on CB"); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 7521 | |
| 7522 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7523 | |
| 7524 | // Calls AllocateCommandBuffers |
| 7525 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
| 7526 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7527 | // Force the failure by setting the Renderpass and Framebuffer fields with |
| 7528 | // (fake) data |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 7529 | VkCommandBufferBeginInfo cmd_buf_info = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7530 | VkCommandBufferInheritanceInfo cmd_buf_hinfo = {}; |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 7531 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 7532 | cmd_buf_info.pNext = NULL; |
| 7533 | cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7534 | cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo; |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 7535 | |
| 7536 | // Begin CB to transition to recording state |
| 7537 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
| 7538 | // Can't re-begin. This should trigger error |
| 7539 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7540 | m_errorMonitor->VerifyFound(); |
| 7541 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7542 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7543 | "Attempt to reset command buffer "); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 7544 | VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test |
| 7545 | // Reset attempt will trigger error due to incorrect CommandPool state |
| 7546 | vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7547 | m_errorMonitor->VerifyFound(); |
| 7548 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7549 | m_errorMonitor->SetDesiredFailureMsg( |
| 7550 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7551 | " attempts to implicitly reset cmdBuffer created from "); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 7552 | // Transition CB to RECORDED state |
| 7553 | vkEndCommandBuffer(commandBuffer.GetBufferHandle()); |
| 7554 | // Now attempting to Begin will implicitly reset, which triggers error |
| 7555 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7556 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 7557 | } |
| 7558 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7559 | TEST_F(VkLayerTest, InvalidPipelineCreateState) { |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7560 | // Attempt to Create Gfx Pipeline w/o a VS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7561 | VkResult err; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7562 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7563 | m_errorMonitor->SetDesiredFailureMsg( |
| 7564 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7565 | "Invalid Pipeline CreateInfo State: Vtx Shader required"); |
| 7566 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7567 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 7568 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 7569 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7570 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7571 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7572 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7573 | |
| 7574 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7575 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7576 | ds_pool_ci.pNext = NULL; |
| 7577 | ds_pool_ci.maxSets = 1; |
| 7578 | ds_pool_ci.poolSizeCount = 1; |
| 7579 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 7580 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7581 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7582 | err = |
| 7583 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7584 | ASSERT_VK_SUCCESS(err); |
| 7585 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7586 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7587 | dsl_binding.binding = 0; |
| 7588 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7589 | dsl_binding.descriptorCount = 1; |
| 7590 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7591 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7592 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7593 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7594 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7595 | ds_layout_ci.pNext = NULL; |
| 7596 | ds_layout_ci.bindingCount = 1; |
| 7597 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7598 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7599 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7600 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7601 | &ds_layout); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7602 | ASSERT_VK_SUCCESS(err); |
| 7603 | |
| 7604 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7605 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 7606 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7607 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 7608 | alloc_info.descriptorPool = ds_pool; |
| 7609 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7610 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7611 | &descriptorSet); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7612 | ASSERT_VK_SUCCESS(err); |
| 7613 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7614 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7615 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7616 | pipeline_layout_ci.setLayoutCount = 1; |
| 7617 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7618 | |
| 7619 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7620 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7621 | &pipeline_layout); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7622 | ASSERT_VK_SUCCESS(err); |
| 7623 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7624 | VkViewport vp = {}; // Just need dummy vp to point to |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7625 | VkRect2D sc = {}; // dummy scissor to point to |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7626 | |
| 7627 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7628 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7629 | vp_state_ci.scissorCount = 1; |
| 7630 | vp_state_ci.pScissors = ≻ |
| 7631 | vp_state_ci.viewportCount = 1; |
| 7632 | vp_state_ci.pViewports = &vp; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7633 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 7634 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 7635 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7636 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 7637 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 7638 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 7639 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 7640 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 7641 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 7642 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7643 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7644 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7645 | gp_ci.pViewportState = &vp_state_ci; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 7646 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7647 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7648 | gp_ci.layout = pipeline_layout; |
| 7649 | gp_ci.renderPass = renderPass(); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7650 | |
| 7651 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7652 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 7653 | pc_ci.initialDataSize = 0; |
| 7654 | pc_ci.pInitialData = 0; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7655 | |
| 7656 | VkPipeline pipeline; |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 7657 | VkPipelineCache pipelineCache; |
| 7658 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7659 | err = |
| 7660 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 7661 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7662 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7663 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 7664 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7665 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 7666 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7667 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7668 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7669 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7670 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7671 | } |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7672 | /*// TODO : This test should be good, but needs Tess support in compiler to run |
| 7673 | TEST_F(VkLayerTest, InvalidPatchControlPoints) |
| 7674 | { |
| 7675 | // Attempt to Create Gfx Pipeline w/o a VS |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7676 | VkResult err; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7677 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 7678 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7679 | "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH |
| 7680 | primitive "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7681 | |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7682 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7683 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7684 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7685 | VkDescriptorPoolSize ds_type_count = {}; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7686 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7687 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7688 | |
| 7689 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 7690 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7691 | ds_pool_ci.pNext = NULL; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7692 | ds_pool_ci.poolSizeCount = 1; |
| 7693 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7694 | |
| 7695 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7696 | err = vkCreateDescriptorPool(m_device->device(), |
| 7697 | 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] | 7698 | ASSERT_VK_SUCCESS(err); |
| 7699 | |
| 7700 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 7701 | dsl_binding.binding = 0; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7702 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | 0212448 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 7703 | dsl_binding.descriptorCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7704 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7705 | dsl_binding.pImmutableSamplers = NULL; |
| 7706 | |
| 7707 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7708 | ds_layout_ci.sType = |
| 7709 | VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7710 | ds_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7711 | ds_layout_ci.bindingCount = 1; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 7712 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7713 | |
| 7714 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7715 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7716 | &ds_layout); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7717 | ASSERT_VK_SUCCESS(err); |
| 7718 | |
| 7719 | VkDescriptorSet descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7720 | err = vkAllocateDescriptorSets(m_device->device(), ds_pool, |
| 7721 | VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7722 | ASSERT_VK_SUCCESS(err); |
| 7723 | |
| 7724 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7725 | pipeline_layout_ci.sType = |
| 7726 | VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7727 | pipeline_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7728 | pipeline_layout_ci.setLayoutCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7729 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 7730 | |
| 7731 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7732 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7733 | &pipeline_layout); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7734 | ASSERT_VK_SUCCESS(err); |
| 7735 | |
| 7736 | VkPipelineShaderStageCreateInfo shaderStages[3]; |
| 7737 | memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 7738 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7739 | VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, |
| 7740 | this); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7741 | // 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] | 7742 | VkShaderObj |
| 7743 | tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, |
| 7744 | this); |
| 7745 | VkShaderObj |
| 7746 | te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, |
| 7747 | this); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7748 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7749 | shaderStages[0].sType = |
| 7750 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 7751 | shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7752 | shaderStages[0].shader = vs.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7753 | shaderStages[1].sType = |
| 7754 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 7755 | shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7756 | shaderStages[1].shader = tc.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7757 | shaderStages[2].sType = |
| 7758 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 7759 | shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7760 | shaderStages[2].shader = te.handle(); |
| 7761 | |
| 7762 | VkPipelineInputAssemblyStateCreateInfo iaCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7763 | iaCI.sType = |
| 7764 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
Chia-I Wu | 515eb8f | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 7765 | iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7766 | |
| 7767 | VkPipelineTessellationStateCreateInfo tsCI = {}; |
| 7768 | tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO; |
| 7769 | tsCI.patchControlPoints = 0; // This will cause an error |
| 7770 | |
| 7771 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 7772 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7773 | gp_ci.pNext = NULL; |
| 7774 | gp_ci.stageCount = 3; |
| 7775 | gp_ci.pStages = shaderStages; |
| 7776 | gp_ci.pVertexInputState = NULL; |
| 7777 | gp_ci.pInputAssemblyState = &iaCI; |
| 7778 | gp_ci.pTessellationState = &tsCI; |
| 7779 | gp_ci.pViewportState = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7780 | gp_ci.pRasterizationState = NULL; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7781 | gp_ci.pMultisampleState = NULL; |
| 7782 | gp_ci.pDepthStencilState = NULL; |
| 7783 | gp_ci.pColorBlendState = NULL; |
| 7784 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7785 | gp_ci.layout = pipeline_layout; |
| 7786 | gp_ci.renderPass = renderPass(); |
| 7787 | |
| 7788 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 7789 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 7790 | pc_ci.pNext = NULL; |
| 7791 | pc_ci.initialSize = 0; |
| 7792 | pc_ci.initialData = 0; |
| 7793 | pc_ci.maxSize = 0; |
| 7794 | |
| 7795 | VkPipeline pipeline; |
| 7796 | VkPipelineCache pipelineCache; |
| 7797 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7798 | err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, |
| 7799 | &pipelineCache); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7800 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7801 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7802 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7803 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7804 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 7805 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7806 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7807 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7808 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7809 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 7810 | } |
| 7811 | */ |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7812 | // Set scissor and viewport counts to different numbers |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7813 | TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7814 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7815 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7816 | m_errorMonitor->SetDesiredFailureMsg( |
| 7817 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7818 | "Gfx Pipeline viewport count (1) must match scissor count (0)."); |
| 7819 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7820 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7821 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7822 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7823 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7824 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7825 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7826 | |
| 7827 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7828 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7829 | ds_pool_ci.maxSets = 1; |
| 7830 | ds_pool_ci.poolSizeCount = 1; |
| 7831 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7832 | |
| 7833 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7834 | err = |
| 7835 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7836 | ASSERT_VK_SUCCESS(err); |
| 7837 | |
| 7838 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7839 | dsl_binding.binding = 0; |
| 7840 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7841 | dsl_binding.descriptorCount = 1; |
| 7842 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7843 | |
| 7844 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7845 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7846 | ds_layout_ci.bindingCount = 1; |
| 7847 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7848 | |
| 7849 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7850 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7851 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7852 | ASSERT_VK_SUCCESS(err); |
| 7853 | |
| 7854 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7855 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 7856 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7857 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 7858 | alloc_info.descriptorPool = ds_pool; |
| 7859 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7860 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7861 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7862 | ASSERT_VK_SUCCESS(err); |
| 7863 | |
| 7864 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7865 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7866 | pipeline_layout_ci.setLayoutCount = 1; |
| 7867 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7868 | |
| 7869 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7870 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7871 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7872 | ASSERT_VK_SUCCESS(err); |
| 7873 | |
| 7874 | VkViewport vp = {}; // Just need dummy vp to point to |
| 7875 | |
| 7876 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7877 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7878 | vp_state_ci.scissorCount = 0; |
| 7879 | vp_state_ci.viewportCount = 1; // Count mismatch should cause error |
| 7880 | vp_state_ci.pViewports = &vp; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7881 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 7882 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 7883 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7884 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 7885 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 7886 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 7887 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 7888 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 7889 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 7890 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 7891 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7892 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7893 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7894 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7895 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7896 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7897 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 7898 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7899 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 7900 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 7901 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7902 | |
| 7903 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7904 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7905 | gp_ci.stageCount = 2; |
| 7906 | gp_ci.pStages = shaderStages; |
| 7907 | gp_ci.pViewportState = &vp_state_ci; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 7908 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7909 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7910 | gp_ci.layout = pipeline_layout; |
| 7911 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7912 | |
| 7913 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7914 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7915 | |
| 7916 | VkPipeline pipeline; |
| 7917 | VkPipelineCache pipelineCache; |
| 7918 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7919 | err = |
| 7920 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7921 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7922 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7923 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7924 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7925 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7926 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7927 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7928 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7929 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7930 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7931 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7932 | // Don't set viewport state in PSO. This is an error b/c we always need this |
| 7933 | // state |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7934 | // 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] | 7935 | TEST_F(VkLayerTest, PSOViewportStateNotSet) { |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7936 | // Attempt to Create Gfx Pipeline w/o a VS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7937 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7938 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7939 | m_errorMonitor->SetDesiredFailureMsg( |
| 7940 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7941 | "Gfx Pipeline pViewportState is null. Even if "); |
| 7942 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7943 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7944 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7945 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7946 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7947 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7948 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7949 | |
| 7950 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7951 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7952 | ds_pool_ci.maxSets = 1; |
| 7953 | ds_pool_ci.poolSizeCount = 1; |
| 7954 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7955 | |
| 7956 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7957 | err = |
| 7958 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7959 | ASSERT_VK_SUCCESS(err); |
| 7960 | |
| 7961 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7962 | dsl_binding.binding = 0; |
| 7963 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7964 | dsl_binding.descriptorCount = 1; |
| 7965 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7966 | |
| 7967 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7968 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7969 | ds_layout_ci.bindingCount = 1; |
| 7970 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7971 | |
| 7972 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7973 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7974 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7975 | ASSERT_VK_SUCCESS(err); |
| 7976 | |
| 7977 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7978 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 7979 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7980 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 7981 | alloc_info.descriptorPool = ds_pool; |
| 7982 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7983 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7984 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7985 | ASSERT_VK_SUCCESS(err); |
| 7986 | |
| 7987 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7988 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7989 | pipeline_layout_ci.setLayoutCount = 1; |
| 7990 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7991 | |
| 7992 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7993 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7994 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7995 | ASSERT_VK_SUCCESS(err); |
| 7996 | |
| 7997 | VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR; |
| 7998 | // Set scissor as dynamic to avoid second error |
| 7999 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8000 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 8001 | dyn_state_ci.dynamicStateCount = 1; |
| 8002 | dyn_state_ci.pDynamicStates = &sc_state; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8003 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 8004 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8005 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8006 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8007 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 8008 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 8009 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 8010 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 8011 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8012 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 8013 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 8014 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8015 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 8016 | |
| 8017 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 8018 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 8019 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 8020 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 8021 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 8022 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 8023 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 8024 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 8025 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8026 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8027 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 8028 | gp_ci.stageCount = 2; |
| 8029 | gp_ci.pStages = shaderStages; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 8030 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8031 | gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state |
| 8032 | // should cause validation error |
| 8033 | gp_ci.pDynamicState = &dyn_state_ci; |
| 8034 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 8035 | gp_ci.layout = pipeline_layout; |
| 8036 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8037 | |
| 8038 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8039 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8040 | |
| 8041 | VkPipeline pipeline; |
| 8042 | VkPipelineCache pipelineCache; |
| 8043 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8044 | err = |
| 8045 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8046 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8047 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 8048 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8049 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8050 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8051 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8052 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 8053 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 8054 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8055 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8056 | } |
| 8057 | // Create PSO w/o non-zero viewportCount but no viewport data |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8058 | // Then run second test where dynamic scissor count doesn't match PSO scissor |
| 8059 | // count |
| 8060 | TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) { |
| 8061 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8062 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8063 | m_errorMonitor->SetDesiredFailureMsg( |
| 8064 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8065 | "Gfx Pipeline viewportCount is 1, but pViewports is NULL. "); |
| 8066 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8067 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8068 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8069 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8070 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8071 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8072 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8073 | |
| 8074 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8075 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8076 | ds_pool_ci.maxSets = 1; |
| 8077 | ds_pool_ci.poolSizeCount = 1; |
| 8078 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8079 | |
| 8080 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8081 | err = |
| 8082 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8083 | ASSERT_VK_SUCCESS(err); |
| 8084 | |
| 8085 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8086 | dsl_binding.binding = 0; |
| 8087 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8088 | dsl_binding.descriptorCount = 1; |
| 8089 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8090 | |
| 8091 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8092 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8093 | ds_layout_ci.bindingCount = 1; |
| 8094 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8095 | |
| 8096 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8097 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8098 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8099 | ASSERT_VK_SUCCESS(err); |
| 8100 | |
| 8101 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8102 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8103 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8104 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8105 | alloc_info.descriptorPool = ds_pool; |
| 8106 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8107 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8108 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8109 | ASSERT_VK_SUCCESS(err); |
| 8110 | |
| 8111 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8112 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 8113 | pipeline_layout_ci.setLayoutCount = 1; |
| 8114 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8115 | |
| 8116 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8117 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 8118 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8119 | ASSERT_VK_SUCCESS(err); |
| 8120 | |
| 8121 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8122 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 8123 | vp_state_ci.viewportCount = 1; |
| 8124 | vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error |
| 8125 | vp_state_ci.scissorCount = 1; |
| 8126 | vp_state_ci.pScissors = |
| 8127 | NULL; // Scissor is dynamic (below) so this won't cause error |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8128 | |
| 8129 | VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR; |
| 8130 | // Set scissor as dynamic to avoid that error |
| 8131 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8132 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 8133 | dyn_state_ci.dynamicStateCount = 1; |
| 8134 | dyn_state_ci.pDynamicStates = &sc_state; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8135 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 8136 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8137 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8138 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8139 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 8140 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 8141 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 8142 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 8143 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8144 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 8145 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 8146 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8147 | |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 8148 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 8149 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 8150 | vi_ci.pNext = nullptr; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8151 | vi_ci.vertexBindingDescriptionCount = 0; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 8152 | vi_ci.pVertexBindingDescriptions = nullptr; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8153 | vi_ci.vertexAttributeDescriptionCount = 0; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 8154 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 8155 | |
| 8156 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 8157 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 8158 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 8159 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8160 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8161 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 8162 | rs_ci.pNext = nullptr; |
| 8163 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 8164 | VkPipelineColorBlendAttachmentState att = {}; |
| 8165 | att.blendEnable = VK_FALSE; |
| 8166 | att.colorWriteMask = 0xf; |
| 8167 | |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 8168 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 8169 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 8170 | cb_ci.pNext = nullptr; |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 8171 | cb_ci.attachmentCount = 1; |
| 8172 | cb_ci.pAttachments = &att; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 8173 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8174 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8175 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 8176 | gp_ci.stageCount = 2; |
| 8177 | gp_ci.pStages = shaderStages; |
| 8178 | gp_ci.pVertexInputState = &vi_ci; |
| 8179 | gp_ci.pInputAssemblyState = &ia_ci; |
| 8180 | gp_ci.pViewportState = &vp_state_ci; |
| 8181 | gp_ci.pRasterizationState = &rs_ci; |
| 8182 | gp_ci.pColorBlendState = &cb_ci; |
| 8183 | gp_ci.pDynamicState = &dyn_state_ci; |
| 8184 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 8185 | gp_ci.layout = pipeline_layout; |
| 8186 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8187 | |
| 8188 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8189 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8190 | |
| 8191 | VkPipeline pipeline; |
| 8192 | VkPipelineCache pipelineCache; |
| 8193 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8194 | err = |
| 8195 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8196 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8197 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 8198 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8199 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8200 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8201 | |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 8202 | // 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] | 8203 | // First need to successfully create the PSO from above by setting |
| 8204 | // pViewports |
| 8205 | m_errorMonitor->SetDesiredFailureMsg( |
| 8206 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8207 | "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO " |
| 8208 | "scissorCount is 1. These counts must match."); |
| 8209 | |
| 8210 | VkViewport vp = {}; // Just need dummy vp to point to |
| 8211 | vp_state_ci.pViewports = &vp; |
| 8212 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 8213 | &gp_ci, NULL, &pipeline); |
| 8214 | ASSERT_VK_SUCCESS(err); |
| 8215 | BeginCommandBuffer(); |
| 8216 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 8217 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 8218 | VkRect2D scissors[2] = {}; // don't care about data |
| 8219 | // Count of 2 doesn't match PSO count of 1 |
| 8220 | vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors); |
| 8221 | Draw(1, 0, 0, 0); |
| 8222 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8223 | m_errorMonitor->VerifyFound(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8224 | |
| 8225 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 8226 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 8227 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8228 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 8229 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8230 | } |
| 8231 | // Create PSO w/o non-zero scissorCount but no scissor data |
| 8232 | // Then run second test where dynamic viewportCount doesn't match PSO |
| 8233 | // viewportCount |
| 8234 | TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) { |
| 8235 | VkResult err; |
| 8236 | |
| 8237 | m_errorMonitor->SetDesiredFailureMsg( |
| 8238 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8239 | "Gfx Pipeline scissorCount is 1, but pScissors is NULL. "); |
| 8240 | |
| 8241 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8242 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8243 | |
| 8244 | VkDescriptorPoolSize ds_type_count = {}; |
| 8245 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8246 | ds_type_count.descriptorCount = 1; |
| 8247 | |
| 8248 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 8249 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8250 | ds_pool_ci.maxSets = 1; |
| 8251 | ds_pool_ci.poolSizeCount = 1; |
| 8252 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 8253 | |
| 8254 | VkDescriptorPool ds_pool; |
| 8255 | err = |
| 8256 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 8257 | ASSERT_VK_SUCCESS(err); |
| 8258 | |
| 8259 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 8260 | dsl_binding.binding = 0; |
| 8261 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8262 | dsl_binding.descriptorCount = 1; |
| 8263 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8264 | |
| 8265 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 8266 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8267 | ds_layout_ci.bindingCount = 1; |
| 8268 | ds_layout_ci.pBindings = &dsl_binding; |
| 8269 | |
| 8270 | VkDescriptorSetLayout ds_layout; |
| 8271 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8272 | &ds_layout); |
| 8273 | ASSERT_VK_SUCCESS(err); |
| 8274 | |
| 8275 | VkDescriptorSet descriptorSet; |
| 8276 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 8277 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 8278 | alloc_info.descriptorSetCount = 1; |
| 8279 | alloc_info.descriptorPool = ds_pool; |
| 8280 | alloc_info.pSetLayouts = &ds_layout; |
| 8281 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8282 | &descriptorSet); |
| 8283 | ASSERT_VK_SUCCESS(err); |
| 8284 | |
| 8285 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 8286 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 8287 | pipeline_layout_ci.setLayoutCount = 1; |
| 8288 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 8289 | |
| 8290 | VkPipelineLayout pipeline_layout; |
| 8291 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 8292 | &pipeline_layout); |
| 8293 | ASSERT_VK_SUCCESS(err); |
| 8294 | |
| 8295 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 8296 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 8297 | vp_state_ci.scissorCount = 1; |
| 8298 | vp_state_ci.pScissors = |
| 8299 | NULL; // Null scissor w/ count of 1 should cause error |
| 8300 | vp_state_ci.viewportCount = 1; |
| 8301 | vp_state_ci.pViewports = |
| 8302 | NULL; // vp is dynamic (below) so this won't cause error |
| 8303 | |
| 8304 | VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT; |
| 8305 | // Set scissor as dynamic to avoid that error |
| 8306 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
| 8307 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 8308 | dyn_state_ci.dynamicStateCount = 1; |
| 8309 | dyn_state_ci.pDynamicStates = &vp_state; |
| 8310 | |
| 8311 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
| 8312 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 8313 | |
| 8314 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 8315 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 8316 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 8317 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 8318 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8319 | // but add it to be able to run on more devices |
| 8320 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 8321 | shaderStages[1] = fs.GetStageCreateInfo(); |
| 8322 | |
| 8323 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 8324 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 8325 | vi_ci.pNext = nullptr; |
| 8326 | vi_ci.vertexBindingDescriptionCount = 0; |
| 8327 | vi_ci.pVertexBindingDescriptions = nullptr; |
| 8328 | vi_ci.vertexAttributeDescriptionCount = 0; |
| 8329 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 8330 | |
| 8331 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 8332 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 8333 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 8334 | |
| 8335 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
| 8336 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 8337 | rs_ci.pNext = nullptr; |
| 8338 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 8339 | VkPipelineColorBlendAttachmentState att = {}; |
| 8340 | att.blendEnable = VK_FALSE; |
| 8341 | att.colorWriteMask = 0xf; |
| 8342 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8343 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 8344 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 8345 | cb_ci.pNext = nullptr; |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 8346 | cb_ci.attachmentCount = 1; |
| 8347 | cb_ci.pAttachments = &att; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8348 | |
| 8349 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 8350 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 8351 | gp_ci.stageCount = 2; |
| 8352 | gp_ci.pStages = shaderStages; |
| 8353 | gp_ci.pVertexInputState = &vi_ci; |
| 8354 | gp_ci.pInputAssemblyState = &ia_ci; |
| 8355 | gp_ci.pViewportState = &vp_state_ci; |
| 8356 | gp_ci.pRasterizationState = &rs_ci; |
| 8357 | gp_ci.pColorBlendState = &cb_ci; |
| 8358 | gp_ci.pDynamicState = &dyn_state_ci; |
| 8359 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 8360 | gp_ci.layout = pipeline_layout; |
| 8361 | gp_ci.renderPass = renderPass(); |
| 8362 | |
| 8363 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 8364 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 8365 | |
| 8366 | VkPipeline pipeline; |
| 8367 | VkPipelineCache pipelineCache; |
| 8368 | |
| 8369 | err = |
| 8370 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 8371 | ASSERT_VK_SUCCESS(err); |
| 8372 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 8373 | &gp_ci, NULL, &pipeline); |
| 8374 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8375 | m_errorMonitor->VerifyFound(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8376 | |
| 8377 | // Now hit second fail case where we set scissor w/ different count than PSO |
| 8378 | // First need to successfully create the PSO from above by setting |
| 8379 | // pViewports |
| 8380 | m_errorMonitor->SetDesiredFailureMsg( |
| 8381 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8382 | "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO " |
| 8383 | "viewportCount is 1. These counts must match."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8384 | |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 8385 | VkRect2D sc = {}; // Just need dummy vp to point to |
| 8386 | vp_state_ci.pScissors = ≻ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8387 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 8388 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 8389 | ASSERT_VK_SUCCESS(err); |
| 8390 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8391 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 8392 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 8393 | VkViewport viewports[2] = {}; // don't care about data |
| 8394 | // Count of 2 doesn't match PSO count of 1 |
Jon Ashburn | 19d3bf1 | 2015-12-30 14:06:55 -0700 | [diff] [blame] | 8395 | vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 8396 | Draw(1, 0, 0, 0); |
| 8397 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8398 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8399 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8400 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 8401 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 8402 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8403 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 8404 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 8405 | } |
| 8406 | |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 8407 | TEST_F(VkLayerTest, PSOLineWidthInvalid) { |
| 8408 | VkResult err; |
| 8409 | |
| 8410 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 8411 | "Attempt to set lineWidth to -1"); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 8412 | |
| 8413 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8414 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8415 | |
| 8416 | VkDescriptorPoolSize ds_type_count = {}; |
| 8417 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8418 | ds_type_count.descriptorCount = 1; |
| 8419 | |
| 8420 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 8421 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8422 | ds_pool_ci.maxSets = 1; |
| 8423 | ds_pool_ci.poolSizeCount = 1; |
| 8424 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 8425 | |
| 8426 | VkDescriptorPool ds_pool; |
| 8427 | err = |
| 8428 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 8429 | ASSERT_VK_SUCCESS(err); |
| 8430 | |
| 8431 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 8432 | dsl_binding.binding = 0; |
| 8433 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8434 | dsl_binding.descriptorCount = 1; |
| 8435 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8436 | |
| 8437 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 8438 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8439 | ds_layout_ci.bindingCount = 1; |
| 8440 | ds_layout_ci.pBindings = &dsl_binding; |
| 8441 | |
| 8442 | VkDescriptorSetLayout ds_layout; |
| 8443 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8444 | &ds_layout); |
| 8445 | ASSERT_VK_SUCCESS(err); |
| 8446 | |
| 8447 | VkDescriptorSet descriptorSet; |
| 8448 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 8449 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 8450 | alloc_info.descriptorSetCount = 1; |
| 8451 | alloc_info.descriptorPool = ds_pool; |
| 8452 | alloc_info.pSetLayouts = &ds_layout; |
| 8453 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8454 | &descriptorSet); |
| 8455 | ASSERT_VK_SUCCESS(err); |
| 8456 | |
| 8457 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 8458 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 8459 | pipeline_layout_ci.setLayoutCount = 1; |
| 8460 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 8461 | |
| 8462 | VkPipelineLayout pipeline_layout; |
| 8463 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 8464 | &pipeline_layout); |
| 8465 | ASSERT_VK_SUCCESS(err); |
| 8466 | |
| 8467 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 8468 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 8469 | vp_state_ci.scissorCount = 1; |
| 8470 | vp_state_ci.pScissors = NULL; |
| 8471 | vp_state_ci.viewportCount = 1; |
| 8472 | vp_state_ci.pViewports = NULL; |
| 8473 | |
| 8474 | VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, |
| 8475 | VK_DYNAMIC_STATE_SCISSOR, |
| 8476 | VK_DYNAMIC_STATE_LINE_WIDTH}; |
| 8477 | // Set scissor as dynamic to avoid that error |
| 8478 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
| 8479 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 8480 | dyn_state_ci.dynamicStateCount = 2; |
| 8481 | dyn_state_ci.pDynamicStates = dynamic_states; |
| 8482 | |
| 8483 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
| 8484 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 8485 | |
| 8486 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 8487 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 8488 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 8489 | VK_SHADER_STAGE_FRAGMENT_BIT, |
| 8490 | this); // TODO - We shouldn't need a fragment shader |
| 8491 | // but add it to be able to run on more devices |
| 8492 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 8493 | shaderStages[1] = fs.GetStageCreateInfo(); |
| 8494 | |
| 8495 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 8496 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 8497 | vi_ci.pNext = nullptr; |
| 8498 | vi_ci.vertexBindingDescriptionCount = 0; |
| 8499 | vi_ci.pVertexBindingDescriptions = nullptr; |
| 8500 | vi_ci.vertexAttributeDescriptionCount = 0; |
| 8501 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 8502 | |
| 8503 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 8504 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 8505 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 8506 | |
| 8507 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
| 8508 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 8509 | rs_ci.pNext = nullptr; |
| 8510 | |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 8511 | // Check too low (line width of -1.0f). |
| 8512 | rs_ci.lineWidth = -1.0f; |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 8513 | |
| 8514 | VkPipelineColorBlendAttachmentState att = {}; |
| 8515 | att.blendEnable = VK_FALSE; |
| 8516 | att.colorWriteMask = 0xf; |
| 8517 | |
| 8518 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 8519 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 8520 | cb_ci.pNext = nullptr; |
| 8521 | cb_ci.attachmentCount = 1; |
| 8522 | cb_ci.pAttachments = &att; |
| 8523 | |
| 8524 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 8525 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 8526 | gp_ci.stageCount = 2; |
| 8527 | gp_ci.pStages = shaderStages; |
| 8528 | gp_ci.pVertexInputState = &vi_ci; |
| 8529 | gp_ci.pInputAssemblyState = &ia_ci; |
| 8530 | gp_ci.pViewportState = &vp_state_ci; |
| 8531 | gp_ci.pRasterizationState = &rs_ci; |
| 8532 | gp_ci.pColorBlendState = &cb_ci; |
| 8533 | gp_ci.pDynamicState = &dyn_state_ci; |
| 8534 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 8535 | gp_ci.layout = pipeline_layout; |
| 8536 | gp_ci.renderPass = renderPass(); |
| 8537 | |
| 8538 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 8539 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 8540 | |
| 8541 | VkPipeline pipeline; |
| 8542 | VkPipelineCache pipelineCache; |
| 8543 | |
| 8544 | err = |
| 8545 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 8546 | ASSERT_VK_SUCCESS(err); |
| 8547 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 8548 | &gp_ci, NULL, &pipeline); |
| 8549 | |
| 8550 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 8551 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 8552 | |
| 8553 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8554 | "Attempt to set lineWidth to 65536"); |
| 8555 | |
| 8556 | // Check too high (line width of 65536.0f). |
| 8557 | rs_ci.lineWidth = 65536.0f; |
| 8558 | |
| 8559 | err = |
| 8560 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 8561 | ASSERT_VK_SUCCESS(err); |
| 8562 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 8563 | &gp_ci, NULL, &pipeline); |
| 8564 | |
| 8565 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 8566 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 8567 | |
| 8568 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 8569 | "Attempt to set lineWidth to -1"); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 8570 | |
| 8571 | dyn_state_ci.dynamicStateCount = 3; |
| 8572 | |
| 8573 | rs_ci.lineWidth = 1.0f; |
| 8574 | |
| 8575 | err = |
| 8576 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 8577 | ASSERT_VK_SUCCESS(err); |
| 8578 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 8579 | &gp_ci, NULL, &pipeline); |
| 8580 | BeginCommandBuffer(); |
| 8581 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 8582 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 8583 | |
| 8584 | // Check too low with dynamic setting. |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 8585 | vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 8586 | m_errorMonitor->VerifyFound(); |
| 8587 | |
| 8588 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8589 | "Attempt to set lineWidth to 65536"); |
| 8590 | |
| 8591 | // Check too high with dynamic setting. |
| 8592 | vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f); |
| 8593 | m_errorMonitor->VerifyFound(); |
| 8594 | EndCommandBuffer(); |
| 8595 | |
| 8596 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 8597 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 8598 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8599 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 8600 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 8601 | } |
| 8602 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8603 | TEST_F(VkLayerTest, NullRenderPass) { |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 8604 | // Bind a NULL RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8605 | m_errorMonitor->SetDesiredFailureMsg( |
| 8606 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8607 | "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()"); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 8608 | |
| 8609 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8610 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 8611 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 8612 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8613 | // Don't care about RenderPass handle b/c error should be flagged before |
| 8614 | // that |
| 8615 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, |
| 8616 | VK_SUBPASS_CONTENTS_INLINE); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 8617 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8618 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 8619 | } |
| 8620 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8621 | TEST_F(VkLayerTest, RenderPassWithinRenderPass) { |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 8622 | // Bind a BeginRenderPass within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8623 | m_errorMonitor->SetDesiredFailureMsg( |
| 8624 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8625 | "It is invalid to issue this call inside an active render pass"); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 8626 | |
| 8627 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8628 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 8629 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 8630 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8631 | // Just create a dummy Renderpass that's non-NULL so we can get to the |
| 8632 | // proper error |
Chris Forbes | 38ae7c4 | 2016-06-21 20:51:44 +1200 | [diff] [blame] | 8633 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8634 | VK_SUBPASS_CONTENTS_INLINE); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 8635 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8636 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8637 | } |
| 8638 | |
Chris Forbes | 2eeabe3 | 2016-06-21 20:52:34 +1200 | [diff] [blame] | 8639 | TEST_F(VkLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) { |
| 8640 | m_errorMonitor->ExpectSuccess(); |
| 8641 | |
| 8642 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8643 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8644 | |
| 8645 | BeginCommandBuffer(); // framework implicitly begins the renderpass. |
| 8646 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // end implicit. |
| 8647 | |
| 8648 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, |
| 8649 | VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS); |
| 8650 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 8651 | m_errorMonitor->VerifyNotFound(); |
| 8652 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, |
| 8653 | VK_SUBPASS_CONTENTS_INLINE); |
| 8654 | m_errorMonitor->VerifyNotFound(); |
| 8655 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 8656 | m_errorMonitor->VerifyNotFound(); |
| 8657 | |
| 8658 | m_commandBuffer->EndCommandBuffer(); |
| 8659 | m_errorMonitor->VerifyNotFound(); |
| 8660 | } |
| 8661 | |
Tobin Ehlis | 5a1c033 | 2016-05-31 13:59:26 -0600 | [diff] [blame] | 8662 | TEST_F(VkLayerTest, RenderPassClearOpMismatch) { |
| 8663 | TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than" |
| 8664 | "the number of renderPass attachments that use loadOp" |
| 8665 | "VK_ATTACHMENT_LOAD_OP_CLEAR."); |
| 8666 | |
| 8667 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8668 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8669 | |
| 8670 | // Create a renderPass with a single attachment that uses loadOp CLEAR |
| 8671 | VkAttachmentReference attach = {}; |
| 8672 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 8673 | VkSubpassDescription subpass = {}; |
| 8674 | subpass.inputAttachmentCount = 1; |
| 8675 | subpass.pInputAttachments = &attach; |
| 8676 | VkRenderPassCreateInfo rpci = {}; |
| 8677 | rpci.subpassCount = 1; |
| 8678 | rpci.pSubpasses = &subpass; |
| 8679 | rpci.attachmentCount = 1; |
| 8680 | VkAttachmentDescription attach_desc = {}; |
| 8681 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 8682 | // Set loadOp to CLEAR |
| 8683 | attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 8684 | rpci.pAttachments = &attach_desc; |
| 8685 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 8686 | VkRenderPass rp; |
| 8687 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 8688 | |
| 8689 | VkCommandBufferInheritanceInfo hinfo = {}; |
| 8690 | hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; |
| 8691 | hinfo.renderPass = VK_NULL_HANDLE; |
| 8692 | hinfo.subpass = 0; |
| 8693 | hinfo.framebuffer = VK_NULL_HANDLE; |
| 8694 | hinfo.occlusionQueryEnable = VK_FALSE; |
| 8695 | hinfo.queryFlags = 0; |
| 8696 | hinfo.pipelineStatistics = 0; |
| 8697 | VkCommandBufferBeginInfo info = {}; |
| 8698 | info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
| 8699 | info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 8700 | info.pInheritanceInfo = &hinfo; |
| 8701 | |
| 8702 | vkBeginCommandBuffer(m_commandBuffer->handle(), &info); |
| 8703 | VkRenderPassBeginInfo rp_begin = {}; |
| 8704 | rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 8705 | rp_begin.pNext = NULL; |
| 8706 | rp_begin.renderPass = renderPass(); |
| 8707 | rp_begin.framebuffer = framebuffer(); |
| 8708 | rp_begin.clearValueCount = 0; // Should be 1 |
| 8709 | |
| 8710 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8711 | " has a clearValueCount of 0 but the " |
| 8712 | "actual number of attachments in " |
| 8713 | "renderPass "); |
| 8714 | |
| 8715 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, |
| 8716 | VK_SUBPASS_CONTENTS_INLINE); |
| 8717 | |
| 8718 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 5c70ebd | 2016-06-09 13:45:00 -0600 | [diff] [blame] | 8719 | |
| 8720 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 5a1c033 | 2016-05-31 13:59:26 -0600 | [diff] [blame] | 8721 | } |
| 8722 | |
Cody Northrop | 3bb4d96 | 2016-05-09 16:15:57 -0600 | [diff] [blame] | 8723 | TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) { |
| 8724 | |
| 8725 | TEST_DESCRIPTION("End a command buffer with an active render pass"); |
| 8726 | |
| 8727 | m_errorMonitor->SetDesiredFailureMsg( |
| 8728 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8729 | "It is invalid to issue this call inside an active render pass"); |
| 8730 | |
| 8731 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8732 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8733 | |
| 8734 | // The framework's BeginCommandBuffer calls CreateRenderPass |
| 8735 | BeginCommandBuffer(); |
| 8736 | |
| 8737 | // Call directly into vkEndCommandBuffer instead of the |
| 8738 | // the framework's EndCommandBuffer, which inserts a |
| 8739 | // vkEndRenderPass |
| 8740 | vkEndCommandBuffer(m_commandBuffer->GetBufferHandle()); |
| 8741 | |
| 8742 | m_errorMonitor->VerifyFound(); |
| 8743 | |
| 8744 | // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY |
| 8745 | // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT |
| 8746 | } |
| 8747 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8748 | TEST_F(VkLayerTest, FillBufferWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8749 | // Call CmdFillBuffer within an active renderpass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8750 | m_errorMonitor->SetDesiredFailureMsg( |
| 8751 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8752 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8753 | |
| 8754 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8755 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8756 | |
| 8757 | // Renderpass is started here |
| 8758 | BeginCommandBuffer(); |
| 8759 | |
| 8760 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8761 | vk_testing::Buffer dstBuffer; |
| 8762 | dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8763 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8764 | m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8765 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8766 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8767 | } |
| 8768 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8769 | TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8770 | // Call CmdUpdateBuffer within an active renderpass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8771 | m_errorMonitor->SetDesiredFailureMsg( |
| 8772 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8773 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8774 | |
| 8775 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8776 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8777 | |
| 8778 | // Renderpass is started here |
| 8779 | BeginCommandBuffer(); |
| 8780 | |
| 8781 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8782 | vk_testing::Buffer dstBuffer; |
| 8783 | dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8784 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8785 | VkDeviceSize dstOffset = 0; |
| 8786 | VkDeviceSize dataSize = 1024; |
| 8787 | const uint32_t *pData = NULL; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8788 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8789 | vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), |
| 8790 | dstOffset, dataSize, pData); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8791 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8792 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8793 | } |
| 8794 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8795 | TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8796 | // Call CmdClearColorImage within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8797 | m_errorMonitor->SetDesiredFailureMsg( |
| 8798 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8799 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8800 | |
| 8801 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8802 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8803 | |
| 8804 | // Renderpass is started here |
| 8805 | BeginCommandBuffer(); |
| 8806 | |
Michael Lentine | 0a369f6 | 2016-02-03 16:51:46 -0600 | [diff] [blame] | 8807 | VkClearColorValue clear_color; |
| 8808 | memset(clear_color.uint32, 0, sizeof(uint32_t) * 4); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8809 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 8810 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 8811 | const int32_t tex_width = 32; |
| 8812 | const int32_t tex_height = 32; |
| 8813 | VkImageCreateInfo image_create_info = {}; |
| 8814 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 8815 | image_create_info.pNext = NULL; |
| 8816 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 8817 | image_create_info.format = tex_format; |
| 8818 | image_create_info.extent.width = tex_width; |
| 8819 | image_create_info.extent.height = tex_height; |
| 8820 | image_create_info.extent.depth = 1; |
| 8821 | image_create_info.mipLevels = 1; |
| 8822 | image_create_info.arrayLayers = 1; |
| 8823 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 8824 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 8825 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8826 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8827 | vk_testing::Image dstImage; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8828 | dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 8829 | reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8830 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8831 | const VkImageSubresourceRange range = vk_testing::Image::subresource_range( |
| 8832 | image_create_info, VK_IMAGE_ASPECT_COLOR_BIT); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8833 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8834 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), |
| 8835 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8836 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8837 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8838 | } |
| 8839 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8840 | TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8841 | // Call CmdClearDepthStencilImage within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8842 | m_errorMonitor->SetDesiredFailureMsg( |
| 8843 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8844 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8845 | |
| 8846 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8847 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8848 | |
| 8849 | // Renderpass is started here |
| 8850 | BeginCommandBuffer(); |
| 8851 | |
| 8852 | VkClearDepthStencilValue clear_value = {0}; |
Dustin Graves | a2e5c94 | 2016-02-11 18:28:06 -0700 | [diff] [blame] | 8853 | VkMemoryPropertyFlags reqs = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8854 | VkImageCreateInfo image_create_info = vk_testing::Image::create_info(); |
| 8855 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 8856 | image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 8857 | image_create_info.extent.width = 64; |
| 8858 | image_create_info.extent.height = 64; |
| 8859 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 8860 | image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8861 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8862 | vk_testing::Image dstImage; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8863 | dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 8864 | reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8865 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8866 | const VkImageSubresourceRange range = vk_testing::Image::subresource_range( |
| 8867 | image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8868 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8869 | vkCmdClearDepthStencilImage( |
| 8870 | m_commandBuffer->GetBufferHandle(), dstImage.handle(), |
| 8871 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, |
| 8872 | &range); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8873 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8874 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8875 | } |
| 8876 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8877 | TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) { |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 8878 | // Call CmdClearAttachmentss outside of an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8879 | VkResult err; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8880 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 8881 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8882 | "vkCmdClearAttachments: This call " |
| 8883 | "must be issued inside an active " |
| 8884 | "render pass"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8885 | |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8886 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8887 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8888 | |
| 8889 | // Start no RenderPass |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8890 | err = m_commandBuffer->BeginCommandBuffer(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8891 | ASSERT_VK_SUCCESS(err); |
| 8892 | |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 8893 | VkClearAttachment color_attachment; |
| 8894 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 8895 | color_attachment.clearValue.color.float32[0] = 0; |
| 8896 | color_attachment.clearValue.color.float32[1] = 0; |
| 8897 | color_attachment.clearValue.color.float32[2] = 0; |
| 8898 | color_attachment.clearValue.color.float32[3] = 0; |
| 8899 | color_attachment.colorAttachment = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8900 | VkClearRect clear_rect = {{{0, 0}, {32, 32}}}; |
| 8901 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 8902 | &color_attachment, 1, &clear_rect); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8903 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8904 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8905 | } |
| 8906 | |
Karl Schultz | 9e66a29 | 2016-04-21 15:57:51 -0600 | [diff] [blame] | 8907 | TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) { |
| 8908 | // Try to add a buffer memory barrier with no buffer. |
| 8909 | m_errorMonitor->SetDesiredFailureMsg( |
| 8910 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8911 | "required parameter pBufferMemoryBarriers[i].buffer specified as VK_NULL_HANDLE"); |
| 8912 | |
| 8913 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8914 | BeginCommandBuffer(); |
| 8915 | |
| 8916 | VkBufferMemoryBarrier buf_barrier = {}; |
| 8917 | buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; |
| 8918 | buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 8919 | buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 8920 | buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 8921 | buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 8922 | buf_barrier.buffer = VK_NULL_HANDLE; |
| 8923 | buf_barrier.offset = 0; |
| 8924 | buf_barrier.size = VK_WHOLE_SIZE; |
| 8925 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8926 | VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, |
| 8927 | 0, 0, nullptr, 1, &buf_barrier, 0, nullptr); |
| 8928 | |
| 8929 | m_errorMonitor->VerifyFound(); |
| 8930 | } |
| 8931 | |
Tony Barbour | 7fd5c0f | 2016-05-03 16:11:53 -0600 | [diff] [blame] | 8932 | TEST_F(VkLayerTest, InvalidBarriers) { |
| 8933 | TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER "); |
| 8934 | |
| 8935 | m_errorMonitor->SetDesiredFailureMsg( |
| 8936 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass"); |
| 8937 | |
| 8938 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8939 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8940 | |
| 8941 | VkMemoryBarrier mem_barrier = {}; |
| 8942 | mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER; |
| 8943 | mem_barrier.pNext = NULL; |
| 8944 | mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 8945 | mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 8946 | BeginCommandBuffer(); |
| 8947 | // BeginCommandBuffer() starts a render pass |
| 8948 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8949 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8950 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1, |
| 8951 | &mem_barrier, 0, nullptr, 0, nullptr); |
| 8952 | m_errorMonitor->VerifyFound(); |
| 8953 | |
| 8954 | m_errorMonitor->SetDesiredFailureMsg( |
| 8955 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8956 | "Image Layout cannot be transitioned to UNDEFINED"); |
| 8957 | VkImageObj image(m_device); |
| 8958 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 8959 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 8960 | ASSERT_TRUE(image.initialized()); |
| 8961 | VkImageMemoryBarrier img_barrier = {}; |
| 8962 | img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 8963 | img_barrier.pNext = NULL; |
| 8964 | img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 8965 | img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 8966 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 8967 | // New layout can't be UNDEFINED |
| 8968 | img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 8969 | img_barrier.image = image.handle(); |
| 8970 | img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 8971 | img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 8972 | img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 8973 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 8974 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 8975 | img_barrier.subresourceRange.layerCount = 1; |
| 8976 | img_barrier.subresourceRange.levelCount = 1; |
| 8977 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8978 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8979 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 8980 | nullptr, 1, &img_barrier); |
| 8981 | m_errorMonitor->VerifyFound(); |
| 8982 | img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 8983 | |
| 8984 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8985 | "Subresource must have the sum of the " |
| 8986 | "baseArrayLayer"); |
| 8987 | // baseArrayLayer + layerCount must be <= image's arrayLayers |
| 8988 | img_barrier.subresourceRange.baseArrayLayer = 1; |
| 8989 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8990 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8991 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 8992 | nullptr, 1, &img_barrier); |
| 8993 | m_errorMonitor->VerifyFound(); |
| 8994 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 8995 | |
| 8996 | m_errorMonitor->SetDesiredFailureMsg( |
| 8997 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8998 | "Subresource must have the sum of the baseMipLevel"); |
| 8999 | // baseMipLevel + levelCount must be <= image's mipLevels |
| 9000 | img_barrier.subresourceRange.baseMipLevel = 1; |
| 9001 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 9002 | VK_PIPELINE_STAGE_HOST_BIT, |
| 9003 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 9004 | nullptr, 1, &img_barrier); |
| 9005 | m_errorMonitor->VerifyFound(); |
| 9006 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 9007 | |
| 9008 | m_errorMonitor->SetDesiredFailureMsg( |
| 9009 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9010 | "Buffer Barriers cannot be used during a render pass"); |
| 9011 | vk_testing::Buffer buffer; |
| 9012 | buffer.init(*m_device, 256); |
| 9013 | VkBufferMemoryBarrier buf_barrier = {}; |
| 9014 | buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; |
| 9015 | buf_barrier.pNext = NULL; |
| 9016 | buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 9017 | buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 9018 | buf_barrier.buffer = buffer.handle(); |
| 9019 | buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 9020 | buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 9021 | buf_barrier.offset = 0; |
| 9022 | buf_barrier.size = VK_WHOLE_SIZE; |
| 9023 | // Can't send buffer barrier during a render pass |
| 9024 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 9025 | VK_PIPELINE_STAGE_HOST_BIT, |
| 9026 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 9027 | &buf_barrier, 0, nullptr); |
| 9028 | m_errorMonitor->VerifyFound(); |
| 9029 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 9030 | |
| 9031 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9032 | "which is not less than total size"); |
| 9033 | buf_barrier.offset = 257; |
| 9034 | // Offset greater than total size |
| 9035 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 9036 | VK_PIPELINE_STAGE_HOST_BIT, |
| 9037 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 9038 | &buf_barrier, 0, nullptr); |
| 9039 | m_errorMonitor->VerifyFound(); |
| 9040 | buf_barrier.offset = 0; |
| 9041 | |
| 9042 | m_errorMonitor->SetDesiredFailureMsg( |
| 9043 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size"); |
| 9044 | buf_barrier.size = 257; |
| 9045 | // Size greater than total size |
| 9046 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 9047 | VK_PIPELINE_STAGE_HOST_BIT, |
| 9048 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 9049 | &buf_barrier, 0, nullptr); |
| 9050 | m_errorMonitor->VerifyFound(); |
| 9051 | buf_barrier.size = VK_WHOLE_SIZE; |
| 9052 | |
| 9053 | m_errorMonitor->SetDesiredFailureMsg( |
| 9054 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9055 | "Image is a depth and stencil format and thus must " |
| 9056 | "have both VK_IMAGE_ASPECT_DEPTH_BIT and " |
| 9057 | "VK_IMAGE_ASPECT_STENCIL_BIT set."); |
| 9058 | VkDepthStencilObj ds_image(m_device); |
| 9059 | ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT); |
| 9060 | ASSERT_TRUE(ds_image.initialized()); |
| 9061 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 9062 | img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 9063 | img_barrier.image = ds_image.handle(); |
| 9064 | // Leave aspectMask at COLOR on purpose |
| 9065 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 9066 | VK_PIPELINE_STAGE_HOST_BIT, |
| 9067 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 9068 | nullptr, 1, &img_barrier); |
| 9069 | m_errorMonitor->VerifyFound(); |
| 9070 | } |
| 9071 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9072 | TEST_F(VkLayerTest, IdxBufferAlignmentError) { |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 9073 | // Bind a BeginRenderPass within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9074 | VkResult err; |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 9075 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9076 | m_errorMonitor->SetDesiredFailureMsg( |
| 9077 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9078 | "vkCmdBindIndexBuffer() offset (0x7) does not fall on "); |
| 9079 | |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 9080 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9081 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 9082 | uint32_t qfi = 0; |
| 9083 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9084 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 9085 | buffCI.size = 1024; |
| 9086 | buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; |
| 9087 | buffCI.queueFamilyIndexCount = 1; |
| 9088 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 9089 | |
| 9090 | VkBuffer ib; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9091 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 9092 | ASSERT_VK_SUCCESS(err); |
| 9093 | |
| 9094 | BeginCommandBuffer(); |
| 9095 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9096 | // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9097 | // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 9098 | // 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] | 9099 | vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, |
| 9100 | VK_INDEX_TYPE_UINT16); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 9101 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9102 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9103 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9104 | vkDestroyBuffer(m_device->device(), ib, NULL); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 9105 | } |
| 9106 | |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 9107 | TEST_F(VkLayerTest, InvalidQueueFamilyIndex) { |
| 9108 | // Create an out-of-range queueFamilyIndex |
| 9109 | m_errorMonitor->SetDesiredFailureMsg( |
| 9110 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Dustin Graves | de62853 | 2016-04-21 16:30:17 -0600 | [diff] [blame] | 9111 | "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one " |
| 9112 | "of the indices specified when the device was created, via the " |
| 9113 | "VkDeviceQueueCreateInfo structure."); |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 9114 | |
| 9115 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9116 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9117 | VkBufferCreateInfo buffCI = {}; |
| 9118 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 9119 | buffCI.size = 1024; |
| 9120 | buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; |
| 9121 | buffCI.queueFamilyIndexCount = 1; |
| 9122 | // Introduce failure by specifying invalid queue_family_index |
| 9123 | uint32_t qfi = 777; |
| 9124 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 24aab04 | 2016-03-24 10:54:18 -0600 | [diff] [blame] | 9125 | buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 9126 | |
| 9127 | VkBuffer ib; |
| 9128 | vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib); |
| 9129 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9130 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 9131 | vkDestroyBuffer(m_device->device(), ib, NULL); |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 9132 | } |
| 9133 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9134 | TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) { |
| 9135 | // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be |
| 9136 | // secondary) |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9137 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9138 | m_errorMonitor->SetDesiredFailureMsg( |
| 9139 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9140 | "vkCmdExecuteCommands() called w/ Primary Cmd Buffer "); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 9141 | |
| 9142 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9143 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 9144 | |
| 9145 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9146 | // ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9147 | VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle(); |
| 9148 | vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 9149 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9150 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 9151 | } |
| 9152 | |
Tobin Ehlis | 17826bd | 2016-05-25 11:12:50 -0600 | [diff] [blame] | 9153 | TEST_F(VkLayerTest, DSUsageBitsErrors) { |
| 9154 | TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers " |
| 9155 | "that do not have correct usage bits sets."); |
| 9156 | VkResult err; |
| 9157 | |
| 9158 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9159 | VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {}; |
| 9160 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 9161 | ds_type_count[i].type = VkDescriptorType(i); |
| 9162 | ds_type_count[i].descriptorCount = 1; |
| 9163 | } |
| 9164 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 9165 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9166 | ds_pool_ci.pNext = NULL; |
| 9167 | ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 9168 | ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 9169 | ds_pool_ci.pPoolSizes = ds_type_count; |
| 9170 | |
| 9171 | VkDescriptorPool ds_pool; |
| 9172 | err = |
| 9173 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 9174 | ASSERT_VK_SUCCESS(err); |
| 9175 | |
| 9176 | // Create 10 layouts where each has a single descriptor of different type |
| 9177 | VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = |
| 9178 | {}; |
| 9179 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 9180 | dsl_binding[i].binding = 0; |
| 9181 | dsl_binding[i].descriptorType = VkDescriptorType(i); |
| 9182 | dsl_binding[i].descriptorCount = 1; |
| 9183 | dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL; |
| 9184 | dsl_binding[i].pImmutableSamplers = NULL; |
| 9185 | } |
| 9186 | |
| 9187 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9188 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9189 | ds_layout_ci.pNext = NULL; |
| 9190 | ds_layout_ci.bindingCount = 1; |
| 9191 | VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE]; |
| 9192 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 9193 | ds_layout_ci.pBindings = dsl_binding + i; |
| 9194 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, |
| 9195 | NULL, ds_layouts + i); |
| 9196 | ASSERT_VK_SUCCESS(err); |
| 9197 | } |
| 9198 | VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {}; |
| 9199 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 9200 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 9201 | alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 9202 | alloc_info.descriptorPool = ds_pool; |
| 9203 | alloc_info.pSetLayouts = ds_layouts; |
| 9204 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9205 | descriptor_sets); |
| 9206 | ASSERT_VK_SUCCESS(err); |
| 9207 | |
| 9208 | // Create a buffer & bufferView to be used for invalid updates |
| 9209 | VkBufferCreateInfo buff_ci = {}; |
| 9210 | buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 9211 | // This usage is not valid for any descriptor type |
| 9212 | buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; |
| 9213 | buff_ci.size = 256; |
| 9214 | buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 9215 | VkBuffer buffer; |
| 9216 | err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer); |
| 9217 | ASSERT_VK_SUCCESS(err); |
| 9218 | |
| 9219 | VkBufferViewCreateInfo buff_view_ci = {}; |
| 9220 | buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; |
| 9221 | buff_view_ci.buffer = buffer; |
| 9222 | buff_view_ci.format = VK_FORMAT_R8_UNORM; |
| 9223 | buff_view_ci.range = VK_WHOLE_SIZE; |
| 9224 | VkBufferView buff_view; |
| 9225 | err = |
| 9226 | vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view); |
| 9227 | ASSERT_VK_SUCCESS(err); |
| 9228 | |
| 9229 | // Create an image to be used for invalid updates |
| 9230 | VkImageCreateInfo image_ci = {}; |
| 9231 | image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 9232 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 9233 | image_ci.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 9234 | image_ci.extent.width = 64; |
| 9235 | image_ci.extent.height = 64; |
| 9236 | image_ci.extent.depth = 1; |
| 9237 | image_ci.mipLevels = 1; |
| 9238 | image_ci.arrayLayers = 1; |
| 9239 | image_ci.samples = VK_SAMPLE_COUNT_1_BIT; |
| 9240 | image_ci.tiling = VK_IMAGE_TILING_LINEAR; |
| 9241 | image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 9242 | // This usage is not valid for any descriptor type |
| 9243 | image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 9244 | image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 9245 | VkImage image; |
| 9246 | err = vkCreateImage(m_device->device(), &image_ci, NULL, &image); |
| 9247 | ASSERT_VK_SUCCESS(err); |
| 9248 | // Bind memory to image |
| 9249 | VkMemoryRequirements mem_reqs; |
| 9250 | VkDeviceMemory image_mem; |
| 9251 | bool pass; |
| 9252 | VkMemoryAllocateInfo mem_alloc = {}; |
| 9253 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 9254 | mem_alloc.pNext = NULL; |
| 9255 | mem_alloc.allocationSize = 0; |
| 9256 | mem_alloc.memoryTypeIndex = 0; |
| 9257 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 9258 | mem_alloc.allocationSize = mem_reqs.size; |
| 9259 | pass = |
| 9260 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 9261 | ASSERT_TRUE(pass); |
| 9262 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem); |
| 9263 | ASSERT_VK_SUCCESS(err); |
| 9264 | err = vkBindImageMemory(m_device->device(), image, image_mem, 0); |
| 9265 | ASSERT_VK_SUCCESS(err); |
| 9266 | // Now create view for image |
| 9267 | VkImageViewCreateInfo image_view_ci = {}; |
| 9268 | image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 9269 | image_view_ci.image = image; |
| 9270 | image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 9271 | image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 9272 | image_view_ci.subresourceRange.layerCount = 1; |
| 9273 | image_view_ci.subresourceRange.baseArrayLayer = 0; |
| 9274 | image_view_ci.subresourceRange.levelCount = 1; |
| 9275 | image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9276 | VkImageView image_view; |
| 9277 | err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, |
| 9278 | &image_view); |
| 9279 | ASSERT_VK_SUCCESS(err); |
| 9280 | |
| 9281 | VkDescriptorBufferInfo buff_info = {}; |
| 9282 | buff_info.buffer = buffer; |
| 9283 | VkDescriptorImageInfo img_info = {}; |
| 9284 | img_info.imageView = image_view; |
| 9285 | VkWriteDescriptorSet descriptor_write = {}; |
| 9286 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 9287 | descriptor_write.dstBinding = 0; |
| 9288 | descriptor_write.descriptorCount = 1; |
| 9289 | descriptor_write.pTexelBufferView = &buff_view; |
| 9290 | descriptor_write.pBufferInfo = &buff_info; |
| 9291 | descriptor_write.pImageInfo = &img_info; |
| 9292 | |
| 9293 | // These error messages align with VkDescriptorType struct |
| 9294 | const char *error_msgs[] = { |
| 9295 | "", // placeholder, no error for SAMPLER descriptor |
| 9296 | " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.", |
| 9297 | " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.", |
| 9298 | " does not have VK_IMAGE_USAGE_STORAGE_BIT set.", |
| 9299 | " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.", |
| 9300 | " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.", |
| 9301 | " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.", |
| 9302 | " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.", |
| 9303 | " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.", |
| 9304 | " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.", |
| 9305 | " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."}; |
| 9306 | // Start loop at 1 as SAMPLER desc type has no usage bit error |
| 9307 | for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 9308 | descriptor_write.descriptorType = VkDescriptorType(i); |
| 9309 | descriptor_write.dstSet = descriptor_sets[i]; |
| 9310 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9311 | error_msgs[i]); |
| 9312 | |
| 9313 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, |
| 9314 | NULL); |
| 9315 | |
| 9316 | m_errorMonitor->VerifyFound(); |
| 9317 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL); |
| 9318 | } |
| 9319 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL); |
| 9320 | vkDestroyImage(m_device->device(), image, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 9321 | vkFreeMemory(m_device->device(), image_mem, NULL); |
Tobin Ehlis | 17826bd | 2016-05-25 11:12:50 -0600 | [diff] [blame] | 9322 | vkDestroyImageView(m_device->device(), image_view, NULL); |
| 9323 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 9324 | vkDestroyBufferView(m_device->device(), buff_view, NULL); |
| 9325 | vkFreeDescriptorSets(m_device->device(), ds_pool, |
| 9326 | VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets); |
| 9327 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 9328 | } |
| 9329 | |
Tobin Ehlis | 585f66d | 2016-07-01 18:23:58 -0600 | [diff] [blame] | 9330 | TEST_F(VkLayerTest, DSBufferInfoErrors) { |
| 9331 | TEST_DESCRIPTION( |
| 9332 | "Attempt to update buffer descriptor set that has incorrect " |
| 9333 | "parameters in VkDescriptorBufferInfo struct. This includes:\n" |
| 9334 | "1. offset value greater than buffer size\n" |
| 9335 | "2. range value of 0\n" |
| 9336 | "3. range value greater than buffer (size - offset)"); |
| 9337 | VkResult err; |
| 9338 | |
| 9339 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9340 | VkDescriptorPoolSize ds_type_count = {}; |
| 9341 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9342 | ds_type_count.descriptorCount = 1; |
| 9343 | |
| 9344 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 9345 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9346 | ds_pool_ci.pNext = NULL; |
| 9347 | ds_pool_ci.maxSets = 1; |
| 9348 | ds_pool_ci.poolSizeCount = 1; |
| 9349 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 9350 | |
| 9351 | VkDescriptorPool ds_pool; |
| 9352 | err = |
| 9353 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 9354 | ASSERT_VK_SUCCESS(err); |
| 9355 | |
| 9356 | // Create layout with single uniform buffer descriptor |
| 9357 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 9358 | dsl_binding.binding = 0; |
| 9359 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9360 | dsl_binding.descriptorCount = 1; |
| 9361 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9362 | dsl_binding.pImmutableSamplers = NULL; |
| 9363 | |
| 9364 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9365 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9366 | ds_layout_ci.pNext = NULL; |
| 9367 | ds_layout_ci.bindingCount = 1; |
| 9368 | ds_layout_ci.pBindings = &dsl_binding; |
| 9369 | VkDescriptorSetLayout ds_layout; |
| 9370 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9371 | &ds_layout); |
| 9372 | ASSERT_VK_SUCCESS(err); |
| 9373 | |
| 9374 | VkDescriptorSet descriptor_set = {}; |
| 9375 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 9376 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 9377 | alloc_info.descriptorSetCount = 1; |
| 9378 | alloc_info.descriptorPool = ds_pool; |
| 9379 | alloc_info.pSetLayouts = &ds_layout; |
| 9380 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9381 | &descriptor_set); |
| 9382 | ASSERT_VK_SUCCESS(err); |
| 9383 | |
| 9384 | // Create a buffer to be used for invalid updates |
| 9385 | VkBufferCreateInfo buff_ci = {}; |
| 9386 | buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 9387 | buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 9388 | buff_ci.size = 256; |
| 9389 | buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 9390 | VkBuffer buffer; |
| 9391 | err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer); |
| 9392 | ASSERT_VK_SUCCESS(err); |
| 9393 | // Have to bind memory to buffer before descriptor update |
| 9394 | VkMemoryAllocateInfo mem_alloc = {}; |
| 9395 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 9396 | mem_alloc.pNext = NULL; |
| 9397 | mem_alloc.allocationSize = 256; |
| 9398 | mem_alloc.memoryTypeIndex = 0; |
| 9399 | |
| 9400 | VkMemoryRequirements mem_reqs; |
| 9401 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs); |
| 9402 | bool pass = |
| 9403 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 9404 | if (!pass) { |
| 9405 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 9406 | return; |
| 9407 | } |
| 9408 | |
| 9409 | VkDeviceMemory mem; |
| 9410 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 9411 | ASSERT_VK_SUCCESS(err); |
| 9412 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 9413 | ASSERT_VK_SUCCESS(err); |
| 9414 | |
| 9415 | VkDescriptorBufferInfo buff_info = {}; |
| 9416 | buff_info.buffer = buffer; |
| 9417 | // First make offset 1 larger than buffer size |
| 9418 | buff_info.offset = 257; |
| 9419 | buff_info.range = VK_WHOLE_SIZE; |
| 9420 | VkWriteDescriptorSet descriptor_write = {}; |
| 9421 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 9422 | descriptor_write.dstBinding = 0; |
| 9423 | descriptor_write.descriptorCount = 1; |
| 9424 | descriptor_write.pTexelBufferView = nullptr; |
| 9425 | descriptor_write.pBufferInfo = &buff_info; |
| 9426 | descriptor_write.pImageInfo = nullptr; |
| 9427 | |
| 9428 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9429 | descriptor_write.dstSet = descriptor_set; |
| 9430 | m_errorMonitor->SetDesiredFailureMsg( |
| 9431 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9432 | " offset of 257 is greater than buffer "); |
| 9433 | |
| 9434 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9435 | |
| 9436 | m_errorMonitor->VerifyFound(); |
| 9437 | // Now cause error due to range of 0 |
| 9438 | buff_info.offset = 0; |
| 9439 | buff_info.range = 0; |
| 9440 | m_errorMonitor->SetDesiredFailureMsg( |
| 9441 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9442 | " range is not VK_WHOLE_SIZE and is zero, which is not allowed."); |
| 9443 | |
| 9444 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9445 | |
| 9446 | m_errorMonitor->VerifyFound(); |
| 9447 | // Now cause error due to range exceeding buffer size - offset |
| 9448 | buff_info.offset = 128; |
| 9449 | buff_info.range = 200; |
| 9450 | m_errorMonitor->SetDesiredFailureMsg( |
| 9451 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9452 | " range is 200 which is greater than buffer size "); |
| 9453 | |
| 9454 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9455 | |
| 9456 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 4bb5409 | 2016-07-06 14:27:19 -0600 | [diff] [blame] | 9457 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | 585f66d | 2016-07-01 18:23:58 -0600 | [diff] [blame] | 9458 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9459 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 9460 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set); |
| 9461 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 9462 | } |
| 9463 | |
Tobin Ehlis | 2fc296b | 2016-06-15 14:05:27 -0600 | [diff] [blame] | 9464 | TEST_F(VkLayerTest, DSAspectBitsErrors) { |
| 9465 | // TODO : Initially only catching case where DEPTH & STENCIL aspect bits |
| 9466 | // are set, but could expand this test to hit more cases. |
| 9467 | TEST_DESCRIPTION("Attempt to update descriptor sets for images " |
| 9468 | "that do not have correct aspect bits sets."); |
| 9469 | VkResult err; |
| 9470 | |
| 9471 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9472 | VkDescriptorPoolSize ds_type_count = {}; |
| 9473 | ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 9474 | ds_type_count.descriptorCount = 1; |
| 9475 | |
| 9476 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 9477 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9478 | ds_pool_ci.pNext = NULL; |
| 9479 | ds_pool_ci.maxSets = 5; |
| 9480 | ds_pool_ci.poolSizeCount = 1; |
| 9481 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 9482 | |
| 9483 | VkDescriptorPool ds_pool; |
| 9484 | err = |
| 9485 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 9486 | ASSERT_VK_SUCCESS(err); |
| 9487 | |
| 9488 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 9489 | dsl_binding.binding = 0; |
| 9490 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 9491 | dsl_binding.descriptorCount = 1; |
| 9492 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9493 | dsl_binding.pImmutableSamplers = NULL; |
| 9494 | |
| 9495 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9496 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9497 | ds_layout_ci.pNext = NULL; |
| 9498 | ds_layout_ci.bindingCount = 1; |
| 9499 | ds_layout_ci.pBindings = &dsl_binding; |
| 9500 | VkDescriptorSetLayout ds_layout; |
| 9501 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9502 | &ds_layout); |
| 9503 | ASSERT_VK_SUCCESS(err); |
| 9504 | |
| 9505 | VkDescriptorSet descriptor_set = {}; |
| 9506 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 9507 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 9508 | alloc_info.descriptorSetCount = 1; |
| 9509 | alloc_info.descriptorPool = ds_pool; |
| 9510 | alloc_info.pSetLayouts = &ds_layout; |
| 9511 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9512 | &descriptor_set); |
| 9513 | ASSERT_VK_SUCCESS(err); |
| 9514 | |
| 9515 | // Create an image to be used for invalid updates |
| 9516 | VkImageCreateInfo image_ci = {}; |
| 9517 | image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 9518 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 9519 | image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 9520 | image_ci.extent.width = 64; |
| 9521 | image_ci.extent.height = 64; |
| 9522 | image_ci.extent.depth = 1; |
| 9523 | image_ci.mipLevels = 1; |
| 9524 | image_ci.arrayLayers = 1; |
| 9525 | image_ci.samples = VK_SAMPLE_COUNT_1_BIT; |
| 9526 | image_ci.tiling = VK_IMAGE_TILING_LINEAR; |
| 9527 | image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 9528 | image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 9529 | image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 9530 | VkImage image; |
| 9531 | err = vkCreateImage(m_device->device(), &image_ci, NULL, &image); |
| 9532 | ASSERT_VK_SUCCESS(err); |
| 9533 | // Bind memory to image |
| 9534 | VkMemoryRequirements mem_reqs; |
| 9535 | VkDeviceMemory image_mem; |
| 9536 | bool pass; |
| 9537 | VkMemoryAllocateInfo mem_alloc = {}; |
| 9538 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 9539 | mem_alloc.pNext = NULL; |
| 9540 | mem_alloc.allocationSize = 0; |
| 9541 | mem_alloc.memoryTypeIndex = 0; |
| 9542 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 9543 | mem_alloc.allocationSize = mem_reqs.size; |
| 9544 | pass = |
| 9545 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 9546 | ASSERT_TRUE(pass); |
| 9547 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem); |
| 9548 | ASSERT_VK_SUCCESS(err); |
| 9549 | err = vkBindImageMemory(m_device->device(), image, image_mem, 0); |
| 9550 | ASSERT_VK_SUCCESS(err); |
| 9551 | // Now create view for image |
| 9552 | VkImageViewCreateInfo image_view_ci = {}; |
| 9553 | image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 9554 | image_view_ci.image = image; |
| 9555 | image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 9556 | image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 9557 | image_view_ci.subresourceRange.layerCount = 1; |
| 9558 | image_view_ci.subresourceRange.baseArrayLayer = 0; |
| 9559 | image_view_ci.subresourceRange.levelCount = 1; |
| 9560 | // Setting both depth & stencil aspect bits is illegal for descriptor |
| 9561 | image_view_ci.subresourceRange.aspectMask = |
| 9562 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 9563 | |
| 9564 | VkImageView image_view; |
| 9565 | err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, |
| 9566 | &image_view); |
| 9567 | ASSERT_VK_SUCCESS(err); |
| 9568 | |
| 9569 | VkDescriptorImageInfo img_info = {}; |
| 9570 | img_info.imageView = image_view; |
| 9571 | VkWriteDescriptorSet descriptor_write = {}; |
| 9572 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 9573 | descriptor_write.dstBinding = 0; |
| 9574 | descriptor_write.descriptorCount = 1; |
| 9575 | descriptor_write.pTexelBufferView = NULL; |
| 9576 | descriptor_write.pBufferInfo = NULL; |
| 9577 | descriptor_write.pImageInfo = &img_info; |
| 9578 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 9579 | descriptor_write.dstSet = descriptor_set; |
| 9580 | const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT " |
| 9581 | "or VK_IMAGE_ASPECT_STENCIL_BIT "; |
| 9582 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9583 | error_msg); |
| 9584 | |
| 9585 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9586 | |
| 9587 | m_errorMonitor->VerifyFound(); |
| 9588 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9589 | vkDestroyImage(m_device->device(), image, NULL); |
| 9590 | vkFreeMemory(m_device->device(), image_mem, NULL); |
| 9591 | vkDestroyImageView(m_device->device(), image_view, NULL); |
| 9592 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set); |
| 9593 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 9594 | } |
| 9595 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9596 | TEST_F(VkLayerTest, DSTypeMismatch) { |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9597 | // 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] | 9598 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9599 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9600 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9601 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9602 | " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update " |
| 9603 | "type is VK_DESCRIPTOR_TYPE_SAMPLER"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9604 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9605 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9606 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9607 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9608 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9609 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9610 | |
| 9611 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9612 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9613 | ds_pool_ci.pNext = NULL; |
| 9614 | ds_pool_ci.maxSets = 1; |
| 9615 | ds_pool_ci.poolSizeCount = 1; |
| 9616 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9617 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9618 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9619 | err = |
| 9620 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9621 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9622 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9623 | dsl_binding.binding = 0; |
| 9624 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9625 | dsl_binding.descriptorCount = 1; |
| 9626 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9627 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9628 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9629 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9630 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9631 | ds_layout_ci.pNext = NULL; |
| 9632 | ds_layout_ci.bindingCount = 1; |
| 9633 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9634 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9635 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9636 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9637 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9638 | ASSERT_VK_SUCCESS(err); |
| 9639 | |
| 9640 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9641 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9642 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9643 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9644 | alloc_info.descriptorPool = ds_pool; |
| 9645 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9646 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9647 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9648 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9649 | |
Tobin Ehlis | 30db8f8 | 2016-05-05 08:19:48 -0600 | [diff] [blame] | 9650 | VkSamplerCreateInfo sampler_ci = {}; |
| 9651 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 9652 | sampler_ci.pNext = NULL; |
| 9653 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 9654 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 9655 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 9656 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9657 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9658 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9659 | sampler_ci.mipLodBias = 1.0; |
| 9660 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 9661 | sampler_ci.maxAnisotropy = 1; |
| 9662 | sampler_ci.compareEnable = VK_FALSE; |
| 9663 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 9664 | sampler_ci.minLod = 1.0; |
| 9665 | sampler_ci.maxLod = 1.0; |
| 9666 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 9667 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
| 9668 | VkSampler sampler; |
| 9669 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
| 9670 | ASSERT_VK_SUCCESS(err); |
| 9671 | |
| 9672 | VkDescriptorImageInfo info = {}; |
| 9673 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9674 | |
| 9675 | VkWriteDescriptorSet descriptor_write; |
| 9676 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 9677 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9678 | descriptor_write.dstSet = descriptorSet; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9679 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9680 | // This is a mismatched type for the layout which expects BUFFER |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9681 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 9682 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9683 | |
| 9684 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9685 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9686 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9687 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9688 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 9689 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9690 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9691 | } |
| 9692 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9693 | TEST_F(VkLayerTest, DSUpdateOutOfBounds) { |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9694 | // For overlapping Update, have arrayIndex exceed that of layout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9695 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9696 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9697 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9698 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9699 | " binding #0 with 1 total descriptors but update of 1 descriptors " |
| 9700 | "starting at binding offset of 0 combined with update array element " |
| 9701 | "offset of 1 oversteps the size of this descriptor set."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9702 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9703 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9704 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9705 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9706 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9707 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9708 | |
| 9709 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9710 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9711 | ds_pool_ci.pNext = NULL; |
| 9712 | ds_pool_ci.maxSets = 1; |
| 9713 | ds_pool_ci.poolSizeCount = 1; |
| 9714 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9715 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9716 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9717 | err = |
| 9718 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9719 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9720 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9721 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9722 | dsl_binding.binding = 0; |
| 9723 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9724 | dsl_binding.descriptorCount = 1; |
| 9725 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9726 | dsl_binding.pImmutableSamplers = NULL; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9727 | |
| 9728 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9729 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9730 | ds_layout_ci.pNext = NULL; |
| 9731 | ds_layout_ci.bindingCount = 1; |
| 9732 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9733 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9734 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9735 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9736 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9737 | ASSERT_VK_SUCCESS(err); |
| 9738 | |
| 9739 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9740 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9741 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9742 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9743 | alloc_info.descriptorPool = ds_pool; |
| 9744 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9745 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9746 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9747 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9748 | |
Tobin Ehlis | 30db8f8 | 2016-05-05 08:19:48 -0600 | [diff] [blame] | 9749 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 9750 | VkDescriptorBufferInfo buff_info = {}; |
| 9751 | buff_info.buffer = |
| 9752 | VkBuffer(0); // Don't care about buffer handle for this test |
| 9753 | buff_info.offset = 0; |
| 9754 | buff_info.range = 1024; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9755 | |
| 9756 | VkWriteDescriptorSet descriptor_write; |
| 9757 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 9758 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9759 | descriptor_write.dstSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9760 | descriptor_write.dstArrayElement = |
| 9761 | 1; /* This index out of bounds for the update */ |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9762 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9763 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9764 | descriptor_write.pBufferInfo = &buff_info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9765 | |
| 9766 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9767 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9768 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9769 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9770 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9771 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9772 | } |
| 9773 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9774 | TEST_F(VkLayerTest, InvalidDSUpdateIndex) { |
| 9775 | // Create layout w/ count of 1 and attempt update to that layout w/ binding |
| 9776 | // index 2 |
| 9777 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9778 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9779 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9780 | " does not have binding 2."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9781 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9782 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9783 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9784 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9785 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9786 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9787 | |
| 9788 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9789 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9790 | ds_pool_ci.pNext = NULL; |
| 9791 | ds_pool_ci.maxSets = 1; |
| 9792 | ds_pool_ci.poolSizeCount = 1; |
| 9793 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 9794 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9795 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9796 | err = |
| 9797 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9798 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9799 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9800 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9801 | dsl_binding.binding = 0; |
| 9802 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9803 | dsl_binding.descriptorCount = 1; |
| 9804 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9805 | dsl_binding.pImmutableSamplers = NULL; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9806 | |
| 9807 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9808 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9809 | ds_layout_ci.pNext = NULL; |
| 9810 | ds_layout_ci.bindingCount = 1; |
| 9811 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9812 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9813 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9814 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9815 | ASSERT_VK_SUCCESS(err); |
| 9816 | |
| 9817 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9818 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9819 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9820 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9821 | alloc_info.descriptorPool = ds_pool; |
| 9822 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9823 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9824 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9825 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9826 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9827 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9828 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 9829 | sampler_ci.pNext = NULL; |
| 9830 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 9831 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 9832 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 9833 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9834 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9835 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9836 | sampler_ci.mipLodBias = 1.0; |
| 9837 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 9838 | sampler_ci.maxAnisotropy = 1; |
| 9839 | sampler_ci.compareEnable = VK_FALSE; |
| 9840 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 9841 | sampler_ci.minLod = 1.0; |
| 9842 | sampler_ci.maxLod = 1.0; |
| 9843 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 9844 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9845 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9846 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9847 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9848 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9849 | |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 9850 | VkDescriptorImageInfo info = {}; |
| 9851 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9852 | |
| 9853 | VkWriteDescriptorSet descriptor_write; |
| 9854 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 9855 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9856 | descriptor_write.dstSet = descriptorSet; |
| 9857 | descriptor_write.dstBinding = 2; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9858 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9859 | // 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] | 9860 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 9861 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9862 | |
| 9863 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9864 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9865 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9866 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9867 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 9868 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9869 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9870 | } |
| 9871 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9872 | TEST_F(VkLayerTest, InvalidDSUpdateStruct) { |
| 9873 | // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* |
| 9874 | // types |
| 9875 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9876 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9877 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 660bcdc | 2016-05-17 10:39:46 -0600 | [diff] [blame] | 9878 | ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9879 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9880 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9881 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9882 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9883 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9884 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9885 | |
| 9886 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9887 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9888 | ds_pool_ci.pNext = NULL; |
| 9889 | ds_pool_ci.maxSets = 1; |
| 9890 | ds_pool_ci.poolSizeCount = 1; |
| 9891 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 9892 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9893 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9894 | err = |
| 9895 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9896 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9897 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9898 | dsl_binding.binding = 0; |
| 9899 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9900 | dsl_binding.descriptorCount = 1; |
| 9901 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9902 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9903 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9904 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9905 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9906 | ds_layout_ci.pNext = NULL; |
| 9907 | ds_layout_ci.bindingCount = 1; |
| 9908 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9909 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9910 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9911 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9912 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9913 | ASSERT_VK_SUCCESS(err); |
| 9914 | |
| 9915 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9916 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9917 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9918 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9919 | alloc_info.descriptorPool = ds_pool; |
| 9920 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9921 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9922 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9923 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9924 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9925 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9926 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 9927 | sampler_ci.pNext = NULL; |
| 9928 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 9929 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 9930 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 9931 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9932 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9933 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9934 | sampler_ci.mipLodBias = 1.0; |
| 9935 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 9936 | sampler_ci.maxAnisotropy = 1; |
| 9937 | sampler_ci.compareEnable = VK_FALSE; |
| 9938 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 9939 | sampler_ci.minLod = 1.0; |
| 9940 | sampler_ci.maxLod = 1.0; |
| 9941 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 9942 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9943 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9944 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9945 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9946 | |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 9947 | VkDescriptorImageInfo info = {}; |
| 9948 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9949 | |
| 9950 | VkWriteDescriptorSet descriptor_write; |
| 9951 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9952 | descriptor_write.sType = |
| 9953 | (VkStructureType)0x99999999; /* Intentionally broken struct type */ |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9954 | descriptor_write.dstSet = descriptorSet; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9955 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9956 | // 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] | 9957 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 9958 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 9959 | |
| 9960 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9961 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9962 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9963 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9964 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 9965 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9966 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9967 | } |
| 9968 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9969 | TEST_F(VkLayerTest, SampleDescriptorUpdateError) { |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9970 | // Create a single Sampler descriptor and send it an invalid Sampler |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9971 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9972 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9973 | m_errorMonitor->SetDesiredFailureMsg( |
| 9974 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9975 | "Attempted write update to sampler descriptor with invalid sampler"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9976 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9977 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9978 | // TODO : Farm Descriptor setup code to helper function(s) to reduce copied |
| 9979 | // code |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9980 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9981 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 9982 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9983 | |
| 9984 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9985 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9986 | ds_pool_ci.pNext = NULL; |
| 9987 | ds_pool_ci.maxSets = 1; |
| 9988 | ds_pool_ci.poolSizeCount = 1; |
| 9989 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9990 | |
| 9991 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9992 | err = |
| 9993 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9994 | ASSERT_VK_SUCCESS(err); |
| 9995 | |
| 9996 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9997 | dsl_binding.binding = 0; |
| 9998 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 9999 | dsl_binding.descriptorCount = 1; |
| 10000 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 10001 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10002 | |
| 10003 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10004 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 10005 | ds_layout_ci.pNext = NULL; |
| 10006 | ds_layout_ci.bindingCount = 1; |
| 10007 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10008 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10009 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 10010 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10011 | ASSERT_VK_SUCCESS(err); |
| 10012 | |
| 10013 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10014 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 10015 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 10016 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10017 | alloc_info.descriptorPool = ds_pool; |
| 10018 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10019 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 10020 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10021 | ASSERT_VK_SUCCESS(err); |
| 10022 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10023 | VkSampler sampler = |
| 10024 | (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10025 | |
| 10026 | VkDescriptorImageInfo descriptor_info; |
| 10027 | memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo)); |
| 10028 | descriptor_info.sampler = sampler; |
| 10029 | |
| 10030 | VkWriteDescriptorSet descriptor_write; |
| 10031 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 10032 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10033 | descriptor_write.dstSet = descriptorSet; |
| 10034 | descriptor_write.dstBinding = 0; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 10035 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10036 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 10037 | descriptor_write.pImageInfo = &descriptor_info; |
| 10038 | |
| 10039 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 10040 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10041 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10042 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10043 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 10044 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10045 | } |
| 10046 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10047 | TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) { |
| 10048 | // Create a single combined Image/Sampler descriptor and send it an invalid |
| 10049 | // imageView |
| 10050 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10051 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 10052 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10053 | "Attempted write update to combined " |
| 10054 | "image sampler descriptor failed due " |
Tobin Ehlis | 63c4b8a | 2016-05-09 10:29:34 -0600 | [diff] [blame] | 10055 | "to: Invalid VkImageView:"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10056 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10057 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 10058 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10059 | ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 10060 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10061 | |
| 10062 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10063 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 10064 | ds_pool_ci.pNext = NULL; |
| 10065 | ds_pool_ci.maxSets = 1; |
| 10066 | ds_pool_ci.poolSizeCount = 1; |
| 10067 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10068 | |
| 10069 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10070 | err = |
| 10071 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10072 | ASSERT_VK_SUCCESS(err); |
| 10073 | |
| 10074 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10075 | dsl_binding.binding = 0; |
| 10076 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 10077 | dsl_binding.descriptorCount = 1; |
| 10078 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 10079 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10080 | |
| 10081 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10082 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 10083 | ds_layout_ci.pNext = NULL; |
| 10084 | ds_layout_ci.bindingCount = 1; |
| 10085 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10086 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10087 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 10088 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10089 | ASSERT_VK_SUCCESS(err); |
| 10090 | |
| 10091 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10092 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 10093 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 10094 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10095 | alloc_info.descriptorPool = ds_pool; |
| 10096 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10097 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 10098 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10099 | ASSERT_VK_SUCCESS(err); |
| 10100 | |
| 10101 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10102 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 10103 | sampler_ci.pNext = NULL; |
| 10104 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 10105 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 10106 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 10107 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 10108 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 10109 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 10110 | sampler_ci.mipLodBias = 1.0; |
| 10111 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 10112 | sampler_ci.maxAnisotropy = 1; |
| 10113 | sampler_ci.compareEnable = VK_FALSE; |
| 10114 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 10115 | sampler_ci.minLod = 1.0; |
| 10116 | sampler_ci.maxLod = 1.0; |
| 10117 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 10118 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10119 | |
| 10120 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10121 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10122 | ASSERT_VK_SUCCESS(err); |
| 10123 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10124 | VkImageView view = |
| 10125 | (VkImageView)((size_t)0xbaadbeef); // invalid imageView object |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10126 | |
| 10127 | VkDescriptorImageInfo descriptor_info; |
| 10128 | memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo)); |
| 10129 | descriptor_info.sampler = sampler; |
| 10130 | descriptor_info.imageView = view; |
| 10131 | |
| 10132 | VkWriteDescriptorSet descriptor_write; |
| 10133 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 10134 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10135 | descriptor_write.dstSet = descriptorSet; |
| 10136 | descriptor_write.dstBinding = 0; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 10137 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10138 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 10139 | descriptor_write.pImageInfo = &descriptor_info; |
| 10140 | |
| 10141 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 10142 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10143 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10144 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10145 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 10146 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 10147 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 10148 | } |
| 10149 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10150 | TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) { |
| 10151 | // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update |
| 10152 | // into the other |
| 10153 | VkResult err; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10154 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 10155 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10156 | " binding #1 with type " |
| 10157 | "VK_DESCRIPTOR_TYPE_SAMPLER. Types do " |
| 10158 | "not match."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10159 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10160 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10161 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 10162 | VkDescriptorPoolSize ds_type_count[2] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10163 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 10164 | ds_type_count[0].descriptorCount = 1; |
| 10165 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 10166 | ds_type_count[1].descriptorCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10167 | |
| 10168 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10169 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 10170 | ds_pool_ci.pNext = NULL; |
| 10171 | ds_pool_ci.maxSets = 1; |
| 10172 | ds_pool_ci.poolSizeCount = 2; |
| 10173 | ds_pool_ci.pPoolSizes = ds_type_count; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10174 | |
| 10175 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10176 | err = |
| 10177 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10178 | ASSERT_VK_SUCCESS(err); |
| 10179 | VkDescriptorSetLayoutBinding dsl_binding[2] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10180 | dsl_binding[0].binding = 0; |
| 10181 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 10182 | dsl_binding[0].descriptorCount = 1; |
| 10183 | dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 10184 | dsl_binding[0].pImmutableSamplers = NULL; |
| 10185 | dsl_binding[1].binding = 1; |
| 10186 | dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 10187 | dsl_binding[1].descriptorCount = 1; |
| 10188 | dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL; |
| 10189 | dsl_binding[1].pImmutableSamplers = NULL; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10190 | |
| 10191 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10192 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 10193 | ds_layout_ci.pNext = NULL; |
| 10194 | ds_layout_ci.bindingCount = 2; |
| 10195 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10196 | |
| 10197 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10198 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 10199 | &ds_layout); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10200 | ASSERT_VK_SUCCESS(err); |
| 10201 | |
| 10202 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10203 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 10204 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 10205 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10206 | alloc_info.descriptorPool = ds_pool; |
| 10207 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10208 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 10209 | &descriptorSet); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10210 | ASSERT_VK_SUCCESS(err); |
| 10211 | |
| 10212 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10213 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 10214 | sampler_ci.pNext = NULL; |
| 10215 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 10216 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 10217 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 10218 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 10219 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 10220 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 10221 | sampler_ci.mipLodBias = 1.0; |
| 10222 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 10223 | sampler_ci.maxAnisotropy = 1; |
| 10224 | sampler_ci.compareEnable = VK_FALSE; |
| 10225 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 10226 | sampler_ci.minLod = 1.0; |
| 10227 | sampler_ci.maxLod = 1.0; |
| 10228 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 10229 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10230 | |
| 10231 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10232 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10233 | ASSERT_VK_SUCCESS(err); |
| 10234 | |
| 10235 | VkDescriptorImageInfo info = {}; |
| 10236 | info.sampler = sampler; |
| 10237 | |
| 10238 | VkWriteDescriptorSet descriptor_write; |
| 10239 | memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet)); |
| 10240 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10241 | descriptor_write.dstSet = descriptorSet; |
| 10242 | descriptor_write.dstBinding = 1; // SAMPLER binding from layout above |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 10243 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10244 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 10245 | descriptor_write.pImageInfo = &info; |
| 10246 | // This write update should succeed |
| 10247 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 10248 | // Now perform a copy update that fails due to type mismatch |
| 10249 | VkCopyDescriptorSet copy_ds_update; |
| 10250 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 10251 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 10252 | copy_ds_update.srcSet = descriptorSet; |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 10253 | copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10254 | copy_ds_update.dstSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10255 | copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 10256 | copy_ds_update.descriptorCount = 1; // copy 1 descriptor |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10257 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 10258 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10259 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10260 | // 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] | 10261 | m_errorMonitor->SetDesiredFailureMsg( |
| 10262 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 10263 | " does not have copy update src binding of 3."); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10264 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 10265 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 10266 | copy_ds_update.srcSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10267 | copy_ds_update.srcBinding = |
| 10268 | 3; // ERROR : Invalid binding for matching layout |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10269 | copy_ds_update.dstSet = descriptorSet; |
| 10270 | copy_ds_update.dstBinding = 0; |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 10271 | copy_ds_update.descriptorCount = 1; // Copy 1 descriptor |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10272 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 10273 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10274 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10275 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10276 | // Now perform a copy update that fails due to binding out of bounds |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10277 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 10278 | VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus " |
| 10279 | "update array offset of 0 and update of " |
| 10280 | "5 descriptors oversteps total number " |
| 10281 | "of descriptors in set: 2."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10282 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10283 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 10284 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 10285 | copy_ds_update.srcSet = descriptorSet; |
| 10286 | copy_ds_update.srcBinding = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10287 | copy_ds_update.dstSet = descriptorSet; |
| 10288 | copy_ds_update.dstBinding = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10289 | copy_ds_update.descriptorCount = |
| 10290 | 5; // ERROR copy 5 descriptors (out of bounds for layout) |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10291 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 10292 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10293 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10294 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10295 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 10296 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 10297 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 10298 | } |
| 10299 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10300 | TEST_F(VkLayerTest, NumSamplesMismatch) { |
| 10301 | // Create CommandBuffer where MSAA samples doesn't match RenderPass |
| 10302 | // sampleCount |
| 10303 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 10304 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10305 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10306 | "Num samples mismatch! "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10307 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 10308 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10309 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 10310 | VkDescriptorPoolSize ds_type_count = {}; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10311 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 10312 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10313 | |
| 10314 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10315 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 10316 | ds_pool_ci.pNext = NULL; |
| 10317 | ds_pool_ci.maxSets = 1; |
| 10318 | ds_pool_ci.poolSizeCount = 1; |
| 10319 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 10320 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 10321 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10322 | err = |
| 10323 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 10324 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 10325 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10326 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 10327 | dsl_binding.binding = 0; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10328 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | 0212448 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 10329 | dsl_binding.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10330 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 10331 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 10332 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10333 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 10334 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 10335 | ds_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 10336 | ds_layout_ci.bindingCount = 1; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 10337 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10338 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 10339 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10340 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 10341 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 10342 | ASSERT_VK_SUCCESS(err); |
| 10343 | |
| 10344 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10345 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 10346 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 10347 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 10348 | alloc_info.descriptorPool = ds_pool; |
| 10349 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10350 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 10351 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 10352 | ASSERT_VK_SUCCESS(err); |
| 10353 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10354 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10355 | pipe_ms_state_ci.sType = |
| 10356 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 10357 | pipe_ms_state_ci.pNext = NULL; |
| 10358 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT; |
| 10359 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 10360 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 10361 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 10362 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10363 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10364 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 10365 | pipeline_layout_ci.pNext = NULL; |
| 10366 | pipeline_layout_ci.setLayoutCount = 1; |
| 10367 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 10368 | |
| 10369 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10370 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 10371 | &pipeline_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 10372 | ASSERT_VK_SUCCESS(err); |
| 10373 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10374 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 10375 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10376 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 10377 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 10378 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10379 | // but add it to be able to run on more devices |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 10380 | VkPipelineObj pipe(m_device); |
| 10381 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 10382 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 10383 | pipe.AddColorAttachment(); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 10384 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 10385 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 10386 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 10387 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10388 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 10389 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 10390 | |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 10391 | // Render triangle (the error should trigger on the attempt to draw). |
| 10392 | Draw(3, 1, 0, 0); |
| 10393 | |
| 10394 | // Finalize recording of the command buffer |
| 10395 | EndCommandBuffer(); |
| 10396 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10397 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 10398 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10399 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 10400 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 10401 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 10402 | } |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 10403 | |
Tobin Ehlis | 85aa15a | 2016-06-15 10:52:37 -0600 | [diff] [blame] | 10404 | TEST_F(VkLayerTest, RenderPassIncompatible) { |
| 10405 | TEST_DESCRIPTION("Hit RenderPass incompatible cases. " |
| 10406 | "Initial case is drawing with an active renderpass that's " |
| 10407 | "not compatible with the bound PSO's creation renderpass"); |
| 10408 | VkResult err; |
| 10409 | |
| 10410 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10411 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10412 | |
| 10413 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 10414 | dsl_binding.binding = 0; |
| 10415 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 10416 | dsl_binding.descriptorCount = 1; |
| 10417 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 10418 | dsl_binding.pImmutableSamplers = NULL; |
| 10419 | |
| 10420 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 10421 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 10422 | ds_layout_ci.pNext = NULL; |
| 10423 | ds_layout_ci.bindingCount = 1; |
| 10424 | ds_layout_ci.pBindings = &dsl_binding; |
| 10425 | |
| 10426 | VkDescriptorSetLayout ds_layout; |
| 10427 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 10428 | &ds_layout); |
| 10429 | ASSERT_VK_SUCCESS(err); |
| 10430 | |
| 10431 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 10432 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 10433 | pipeline_layout_ci.pNext = NULL; |
| 10434 | pipeline_layout_ci.setLayoutCount = 1; |
| 10435 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 10436 | |
| 10437 | VkPipelineLayout pipeline_layout; |
| 10438 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 10439 | &pipeline_layout); |
| 10440 | ASSERT_VK_SUCCESS(err); |
| 10441 | |
| 10442 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 10443 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10444 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 10445 | VK_SHADER_STAGE_FRAGMENT_BIT, |
| 10446 | this); // We shouldn't need a fragment shader |
| 10447 | // but add it to be able to run on more devices |
| 10448 | // Create a renderpass that will be incompatible with default renderpass |
| 10449 | VkAttachmentReference attach = {}; |
| 10450 | attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 10451 | VkAttachmentReference color_att = {}; |
| 10452 | color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 10453 | VkSubpassDescription subpass = {}; |
| 10454 | subpass.inputAttachmentCount = 1; |
| 10455 | subpass.pInputAttachments = &attach; |
| 10456 | subpass.colorAttachmentCount = 1; |
| 10457 | subpass.pColorAttachments = &color_att; |
| 10458 | VkRenderPassCreateInfo rpci = {}; |
| 10459 | rpci.subpassCount = 1; |
| 10460 | rpci.pSubpasses = &subpass; |
| 10461 | rpci.attachmentCount = 1; |
| 10462 | VkAttachmentDescription attach_desc = {}; |
| 10463 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
Cody Northrop | bd16af1 | 2016-06-21 09:25:48 -0600 | [diff] [blame] | 10464 | // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM |
| 10465 | attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM; |
Tobin Ehlis | 85aa15a | 2016-06-15 10:52:37 -0600 | [diff] [blame] | 10466 | rpci.pAttachments = &attach_desc; |
| 10467 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 10468 | VkRenderPass rp; |
| 10469 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 10470 | VkPipelineObj pipe(m_device); |
| 10471 | pipe.AddShader(&vs); |
| 10472 | pipe.AddShader(&fs); |
| 10473 | pipe.AddColorAttachment(); |
| 10474 | VkViewport view_port = {}; |
| 10475 | m_viewports.push_back(view_port); |
| 10476 | pipe.SetViewport(m_viewports); |
| 10477 | VkRect2D rect = {}; |
| 10478 | m_scissors.push_back(rect); |
| 10479 | pipe.SetScissor(m_scissors); |
| 10480 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 10481 | |
| 10482 | VkCommandBufferInheritanceInfo cbii = {}; |
| 10483 | cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; |
| 10484 | cbii.renderPass = rp; |
| 10485 | cbii.subpass = 0; |
| 10486 | VkCommandBufferBeginInfo cbbi = {}; |
| 10487 | cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 10488 | cbbi.pInheritanceInfo = &cbii; |
| 10489 | vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi); |
| 10490 | VkRenderPassBeginInfo rpbi = {}; |
| 10491 | rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 10492 | rpbi.framebuffer = m_framebuffer; |
| 10493 | rpbi.renderPass = rp; |
| 10494 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, |
| 10495 | VK_SUBPASS_CONTENTS_INLINE); |
| 10496 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 10497 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 10498 | |
| 10499 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10500 | " is incompatible w/ gfx pipeline "); |
| 10501 | // Render triangle (the error should trigger on the attempt to draw). |
| 10502 | Draw(3, 1, 0, 0); |
| 10503 | |
| 10504 | // Finalize recording of the command buffer |
| 10505 | EndCommandBuffer(); |
| 10506 | |
| 10507 | m_errorMonitor->VerifyFound(); |
| 10508 | |
| 10509 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 10510 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 10511 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 10512 | } |
| 10513 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 10514 | TEST_F(VkLayerTest, NumBlendAttachMismatch) { |
| 10515 | // Create Pipeline where the number of blend attachments doesn't match the |
| 10516 | // number of color attachments. In this case, we don't add any color |
| 10517 | // blend attachments even though we have a color attachment. |
| 10518 | VkResult err; |
| 10519 | |
| 10520 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 10521 | "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] | 10522 | |
| 10523 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10524 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10525 | VkDescriptorPoolSize ds_type_count = {}; |
| 10526 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 10527 | ds_type_count.descriptorCount = 1; |
| 10528 | |
| 10529 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 10530 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 10531 | ds_pool_ci.pNext = NULL; |
| 10532 | ds_pool_ci.maxSets = 1; |
| 10533 | ds_pool_ci.poolSizeCount = 1; |
| 10534 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 10535 | |
| 10536 | VkDescriptorPool ds_pool; |
| 10537 | err = |
| 10538 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 10539 | ASSERT_VK_SUCCESS(err); |
| 10540 | |
| 10541 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 10542 | dsl_binding.binding = 0; |
| 10543 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 10544 | dsl_binding.descriptorCount = 1; |
| 10545 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 10546 | dsl_binding.pImmutableSamplers = NULL; |
| 10547 | |
| 10548 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 10549 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 10550 | ds_layout_ci.pNext = NULL; |
| 10551 | ds_layout_ci.bindingCount = 1; |
| 10552 | ds_layout_ci.pBindings = &dsl_binding; |
| 10553 | |
| 10554 | VkDescriptorSetLayout ds_layout; |
| 10555 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 10556 | &ds_layout); |
| 10557 | ASSERT_VK_SUCCESS(err); |
| 10558 | |
| 10559 | VkDescriptorSet descriptorSet; |
| 10560 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 10561 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 10562 | alloc_info.descriptorSetCount = 1; |
| 10563 | alloc_info.descriptorPool = ds_pool; |
| 10564 | alloc_info.pSetLayouts = &ds_layout; |
| 10565 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 10566 | &descriptorSet); |
| 10567 | ASSERT_VK_SUCCESS(err); |
| 10568 | |
| 10569 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
| 10570 | pipe_ms_state_ci.sType = |
| 10571 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 10572 | pipe_ms_state_ci.pNext = NULL; |
| 10573 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; |
| 10574 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 10575 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 10576 | pipe_ms_state_ci.pSampleMask = NULL; |
| 10577 | |
| 10578 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 10579 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 10580 | pipeline_layout_ci.pNext = NULL; |
| 10581 | pipeline_layout_ci.setLayoutCount = 1; |
| 10582 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 10583 | |
| 10584 | VkPipelineLayout pipeline_layout; |
| 10585 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 10586 | &pipeline_layout); |
| 10587 | ASSERT_VK_SUCCESS(err); |
| 10588 | |
| 10589 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 10590 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10591 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 10592 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 10593 | this); // We shouldn't need a fragment shader |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 10594 | // but add it to be able to run on more devices |
| 10595 | VkPipelineObj pipe(m_device); |
| 10596 | pipe.AddShader(&vs); |
| 10597 | pipe.AddShader(&fs); |
| 10598 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 10599 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 10600 | |
| 10601 | BeginCommandBuffer(); |
| 10602 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 10603 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 10604 | |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 10605 | // Render triangle (the error should trigger on the attempt to draw). |
| 10606 | Draw(3, 1, 0, 0); |
| 10607 | |
| 10608 | // Finalize recording of the command buffer |
| 10609 | EndCommandBuffer(); |
| 10610 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10611 | m_errorMonitor->VerifyFound(); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 10612 | |
| 10613 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 10614 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 10615 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 10616 | } |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 10617 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 10618 | TEST_F(VkLayerTest, MissingClearAttachment) { |
| 10619 | TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment " |
| 10620 | "structure passed to vkCmdClearAttachments"); |
| 10621 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10622 | "vkCmdClearAttachments() attachment index 1 not found in attachment " |
| 10623 | "reference array of active subpass 0"); |
| 10624 | |
| 10625 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments); |
| 10626 | m_errorMonitor->VerifyFound(); |
| 10627 | } |
| 10628 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10629 | TEST_F(VkLayerTest, ClearCmdNoDraw) { |
| 10630 | // Create CommandBuffer where we add ClearCmd for FB Color attachment prior |
| 10631 | // to issuing a Draw |
| 10632 | VkResult err; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10633 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10634 | m_errorMonitor->SetDesiredFailureMsg( |
Tony Barbour | 7e56d30 | 2016-03-02 15:12:01 -0700 | [diff] [blame] | 10635 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10636 | "vkCmdClearAttachments() issued on CB object "); |
| 10637 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10638 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10639 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10640 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 10641 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10642 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 10643 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10644 | |
| 10645 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10646 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 10647 | ds_pool_ci.pNext = NULL; |
| 10648 | ds_pool_ci.maxSets = 1; |
| 10649 | ds_pool_ci.poolSizeCount = 1; |
| 10650 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10651 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10652 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10653 | err = |
| 10654 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10655 | ASSERT_VK_SUCCESS(err); |
| 10656 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10657 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10658 | dsl_binding.binding = 0; |
| 10659 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 10660 | dsl_binding.descriptorCount = 1; |
| 10661 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 10662 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10663 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10664 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10665 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 10666 | ds_layout_ci.pNext = NULL; |
| 10667 | ds_layout_ci.bindingCount = 1; |
| 10668 | ds_layout_ci.pBindings = &dsl_binding; |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 10669 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10670 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10671 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 10672 | &ds_layout); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10673 | ASSERT_VK_SUCCESS(err); |
| 10674 | |
| 10675 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10676 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 10677 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 10678 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 10679 | alloc_info.descriptorPool = ds_pool; |
| 10680 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10681 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 10682 | &descriptorSet); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10683 | ASSERT_VK_SUCCESS(err); |
| 10684 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10685 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10686 | pipe_ms_state_ci.sType = |
| 10687 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 10688 | pipe_ms_state_ci.pNext = NULL; |
| 10689 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT; |
| 10690 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 10691 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 10692 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10693 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10694 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10695 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 10696 | pipeline_layout_ci.pNext = NULL; |
| 10697 | pipeline_layout_ci.setLayoutCount = 1; |
| 10698 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10699 | |
| 10700 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10701 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 10702 | &pipeline_layout); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10703 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 10704 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10705 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 10706 | VK_SHADER_STAGE_VERTEX_BIT, this); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 10707 | // 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] | 10708 | // on more devices |
| 10709 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 10710 | VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10711 | |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 10712 | VkPipelineObj pipe(m_device); |
| 10713 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 10714 | pipe.AddShader(&fs); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 10715 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 10716 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 10717 | |
| 10718 | BeginCommandBuffer(); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10719 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10720 | // Main thing we care about for this test is that the VkImage obj we're |
| 10721 | // clearing matches Color Attachment of FB |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10722 | // Also pass down other dummy params to keep driver and paramchecker happy |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 10723 | VkClearAttachment color_attachment; |
| 10724 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 10725 | color_attachment.clearValue.color.float32[0] = 1.0; |
| 10726 | color_attachment.clearValue.color.float32[1] = 1.0; |
| 10727 | color_attachment.clearValue.color.float32[2] = 1.0; |
| 10728 | color_attachment.clearValue.color.float32[3] = 1.0; |
| 10729 | color_attachment.colorAttachment = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10730 | VkClearRect clear_rect = { |
| 10731 | {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}}; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10732 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10733 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 10734 | &color_attachment, 1, &clear_rect); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10735 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10736 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 10737 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10738 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 10739 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 10740 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 10741 | } |
| 10742 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10743 | TEST_F(VkLayerTest, VtxBufferBadIndex) { |
| 10744 | VkResult err; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10745 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10746 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 10747 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | dfcd9b6 | 2015-12-14 15:14:10 -0700 | [diff] [blame] | 10748 | "but no vertex buffers are attached to this Pipeline State Object"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10749 | |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10750 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 10751 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10752 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10753 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 10754 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10755 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 10756 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10757 | |
| 10758 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10759 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 10760 | ds_pool_ci.pNext = NULL; |
| 10761 | ds_pool_ci.maxSets = 1; |
| 10762 | ds_pool_ci.poolSizeCount = 1; |
| 10763 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10764 | |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 10765 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10766 | err = |
| 10767 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10768 | ASSERT_VK_SUCCESS(err); |
| 10769 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10770 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10771 | dsl_binding.binding = 0; |
| 10772 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 10773 | dsl_binding.descriptorCount = 1; |
| 10774 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 10775 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10776 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10777 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10778 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 10779 | ds_layout_ci.pNext = NULL; |
| 10780 | ds_layout_ci.bindingCount = 1; |
| 10781 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10782 | |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10783 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10784 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 10785 | &ds_layout); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10786 | ASSERT_VK_SUCCESS(err); |
| 10787 | |
| 10788 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10789 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 10790 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 10791 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 10792 | alloc_info.descriptorPool = ds_pool; |
| 10793 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10794 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 10795 | &descriptorSet); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10796 | ASSERT_VK_SUCCESS(err); |
| 10797 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10798 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10799 | pipe_ms_state_ci.sType = |
| 10800 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 10801 | pipe_ms_state_ci.pNext = NULL; |
| 10802 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; |
| 10803 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 10804 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 10805 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10806 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 10807 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10808 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 10809 | pipeline_layout_ci.pNext = NULL; |
| 10810 | pipeline_layout_ci.setLayoutCount = 1; |
| 10811 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 10812 | VkPipelineLayout pipeline_layout; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10813 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10814 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 10815 | &pipeline_layout); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10816 | ASSERT_VK_SUCCESS(err); |
| 10817 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10818 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 10819 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10820 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 10821 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 10822 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10823 | // but add it to be able to run on more devices |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 10824 | VkPipelineObj pipe(m_device); |
| 10825 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 10826 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 10827 | pipe.AddColorAttachment(); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 10828 | pipe.SetMSAA(&pipe_ms_state_ci); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 10829 | pipe.SetViewport(m_viewports); |
| 10830 | pipe.SetScissor(m_scissors); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 10831 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 10832 | |
| 10833 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10834 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 10835 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | f7bf450 | 2015-09-09 15:12:35 -0600 | [diff] [blame] | 10836 | // Don't care about actual data, just need to get to draw to flag error |
| 10837 | static const float vbo_data[3] = {1.f, 0.f, 1.f}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10838 | VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), |
| 10839 | (const void *)&vbo_data); |
Tobin Ehlis | f7bf450 | 2015-09-09 15:12:35 -0600 | [diff] [blame] | 10840 | 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] | 10841 | Draw(1, 0, 0, 0); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10842 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10843 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 10844 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10845 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 10846 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 10847 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 10848 | } |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 10849 | // INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here) |
| 10850 | TEST_F(VkLayerTest, InvalidImageLayout) { |
| 10851 | TEST_DESCRIPTION("Hit all possible validation checks associated with the " |
| 10852 | "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having" |
| 10853 | "images in the wrong layout when they're copied or transitioned."); |
| 10854 | // 3 in ValidateCmdBufImageLayouts |
| 10855 | // * -1 Attempt to submit cmd buf w/ deleted image |
| 10856 | // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource |
| 10857 | // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource |
| 10858 | m_errorMonitor->SetDesiredFailureMsg( |
| 10859 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 10860 | "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL."); |
| 10861 | |
| 10862 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10863 | // Create src & dst images to use for copy operations |
| 10864 | VkImage src_image; |
| 10865 | VkImage dst_image; |
| 10866 | |
| 10867 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 10868 | const int32_t tex_width = 32; |
| 10869 | const int32_t tex_height = 32; |
| 10870 | |
| 10871 | VkImageCreateInfo image_create_info = {}; |
| 10872 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 10873 | image_create_info.pNext = NULL; |
| 10874 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 10875 | image_create_info.format = tex_format; |
| 10876 | image_create_info.extent.width = tex_width; |
| 10877 | image_create_info.extent.height = tex_height; |
| 10878 | image_create_info.extent.depth = 1; |
| 10879 | image_create_info.mipLevels = 1; |
| 10880 | image_create_info.arrayLayers = 4; |
| 10881 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 10882 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 10883 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 10884 | image_create_info.flags = 0; |
| 10885 | |
| 10886 | VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image); |
| 10887 | ASSERT_VK_SUCCESS(err); |
| 10888 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image); |
| 10889 | ASSERT_VK_SUCCESS(err); |
| 10890 | |
| 10891 | BeginCommandBuffer(); |
| 10892 | VkImageCopy copyRegion; |
| 10893 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 10894 | copyRegion.srcSubresource.mipLevel = 0; |
| 10895 | copyRegion.srcSubresource.baseArrayLayer = 0; |
| 10896 | copyRegion.srcSubresource.layerCount = 1; |
| 10897 | copyRegion.srcOffset.x = 0; |
| 10898 | copyRegion.srcOffset.y = 0; |
| 10899 | copyRegion.srcOffset.z = 0; |
| 10900 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 10901 | copyRegion.dstSubresource.mipLevel = 0; |
| 10902 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 10903 | copyRegion.dstSubresource.layerCount = 1; |
| 10904 | copyRegion.dstOffset.x = 0; |
| 10905 | copyRegion.dstOffset.y = 0; |
| 10906 | copyRegion.dstOffset.z = 0; |
| 10907 | copyRegion.extent.width = 1; |
| 10908 | copyRegion.extent.height = 1; |
| 10909 | copyRegion.extent.depth = 1; |
| 10910 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 10911 | m_errorMonitor->VerifyFound(); |
| 10912 | // Now cause error due to src image layout changing |
| 10913 | m_errorMonitor->SetDesiredFailureMsg( |
| 10914 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10915 | "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL."); |
| 10916 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 10917 | m_errorMonitor->VerifyFound(); |
| 10918 | // Final src error is due to bad layout type |
| 10919 | m_errorMonitor->SetDesiredFailureMsg( |
| 10920 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10921 | "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL."); |
| 10922 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 10923 | m_errorMonitor->VerifyFound(); |
| 10924 | // Now verify same checks for dst |
| 10925 | m_errorMonitor->SetDesiredFailureMsg( |
| 10926 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 10927 | "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL."); |
| 10928 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 10929 | m_errorMonitor->VerifyFound(); |
| 10930 | // Now cause error due to src image layout changing |
| 10931 | m_errorMonitor->SetDesiredFailureMsg( |
| 10932 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10933 | "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL."); |
| 10934 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, ©Region); |
| 10935 | m_errorMonitor->VerifyFound(); |
| 10936 | m_errorMonitor->SetDesiredFailureMsg( |
| 10937 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10938 | "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL."); |
| 10939 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, ©Region); |
| 10940 | m_errorMonitor->VerifyFound(); |
| 10941 | // Now cause error due to bad image layout transition in PipelineBarrier |
| 10942 | VkImageMemoryBarrier image_barrier[1] = {}; |
| 10943 | image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 10944 | image_barrier[0].image = src_image; |
| 10945 | image_barrier[0].subresourceRange.layerCount = 2; |
| 10946 | image_barrier[0].subresourceRange.levelCount = 2; |
| 10947 | image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 10948 | m_errorMonitor->SetDesiredFailureMsg( |
| 10949 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10950 | "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL."); |
| 10951 | vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier); |
| 10952 | m_errorMonitor->VerifyFound(); |
| 10953 | |
| 10954 | // Finally some layout errors at RenderPass create time |
| 10955 | // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing. |
| 10956 | VkAttachmentReference attach = {}; |
| 10957 | // perf warning for GENERAL layout w/ non-DS input attachment |
| 10958 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 10959 | VkSubpassDescription subpass = {}; |
| 10960 | subpass.inputAttachmentCount = 1; |
| 10961 | subpass.pInputAttachments = &attach; |
| 10962 | VkRenderPassCreateInfo rpci = {}; |
| 10963 | rpci.subpassCount = 1; |
| 10964 | rpci.pSubpasses = &subpass; |
| 10965 | rpci.attachmentCount = 1; |
| 10966 | VkAttachmentDescription attach_desc = {}; |
| 10967 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 10968 | rpci.pAttachments = &attach_desc; |
Tobin Ehlis | 1efce02 | 2016-05-11 10:40:34 -0600 | [diff] [blame] | 10969 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 10970 | VkRenderPass rp; |
| 10971 | m_errorMonitor->SetDesiredFailureMsg( |
| 10972 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 10973 | "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL."); |
| 10974 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 10975 | m_errorMonitor->VerifyFound(); |
| 10976 | // error w/ non-general layout |
| 10977 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 10978 | |
| 10979 | m_errorMonitor->SetDesiredFailureMsg( |
| 10980 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10981 | "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL."); |
| 10982 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 10983 | m_errorMonitor->VerifyFound(); |
| 10984 | subpass.inputAttachmentCount = 0; |
| 10985 | subpass.colorAttachmentCount = 1; |
| 10986 | subpass.pColorAttachments = &attach; |
| 10987 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 10988 | // perf warning for GENERAL layout on color attachment |
| 10989 | m_errorMonitor->SetDesiredFailureMsg( |
| 10990 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 10991 | "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL."); |
| 10992 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 10993 | m_errorMonitor->VerifyFound(); |
| 10994 | // error w/ non-color opt or GENERAL layout for color attachment |
| 10995 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 10996 | m_errorMonitor->SetDesiredFailureMsg( |
| 10997 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10998 | "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL."); |
| 10999 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 11000 | m_errorMonitor->VerifyFound(); |
| 11001 | subpass.colorAttachmentCount = 0; |
| 11002 | subpass.pDepthStencilAttachment = &attach; |
| 11003 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 11004 | // perf warning for GENERAL layout on DS attachment |
| 11005 | m_errorMonitor->SetDesiredFailureMsg( |
| 11006 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 11007 | "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL."); |
| 11008 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 11009 | m_errorMonitor->VerifyFound(); |
| 11010 | // error w/ non-ds opt or GENERAL layout for color attachment |
| 11011 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 11012 | m_errorMonitor->SetDesiredFailureMsg( |
| 11013 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11014 | "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL."); |
| 11015 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 11016 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 1efce02 | 2016-05-11 10:40:34 -0600 | [diff] [blame] | 11017 | // For this error we need a valid renderpass so create default one |
| 11018 | attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 11019 | attach.attachment = 0; |
| 11020 | attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 11021 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11022 | attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE; |
| 11023 | attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 11024 | attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 11025 | // Can't do a CLEAR load on READ_ONLY initialLayout |
| 11026 | attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 11027 | attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 11028 | attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 11029 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11030 | " with invalid first layout " |
| 11031 | "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_" |
| 11032 | "ONLY_OPTIMAL"); |
| 11033 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 11034 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 11035 | |
| 11036 | vkDestroyImage(m_device->device(), src_image, NULL); |
| 11037 | vkDestroyImage(m_device->device(), dst_image, NULL); |
| 11038 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 11039 | #endif // DRAW_STATE_TESTS |
| 11040 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 11041 | #if THREADING_TESTS |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11042 | #if GTEST_IS_THREADSAFE |
| 11043 | struct thread_data_struct { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11044 | VkCommandBuffer commandBuffer; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11045 | VkEvent event; |
| 11046 | bool bailout; |
| 11047 | }; |
| 11048 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11049 | extern "C" void *AddToCommandBuffer(void *arg) { |
| 11050 | struct thread_data_struct *data = (struct thread_data_struct *)arg; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11051 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11052 | for (int i = 0; i < 10000; i++) { |
| 11053 | vkCmdSetEvent(data->commandBuffer, data->event, |
| 11054 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11055 | if (data->bailout) { |
| 11056 | break; |
| 11057 | } |
| 11058 | } |
| 11059 | return NULL; |
| 11060 | } |
| 11061 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11062 | TEST_F(VkLayerTest, ThreadCommandBufferCollision) { |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 11063 | test_platform_thread thread; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11064 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11065 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11066 | "THREADING ERROR"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11067 | |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11068 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11069 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 11070 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11071 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11072 | // Calls AllocateCommandBuffers |
| 11073 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
Mark Lobodzinski | 5495d13 | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 11074 | |
| 11075 | // Avoid creating RenderPass |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11076 | commandBuffer.BeginCommandBuffer(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11077 | |
| 11078 | VkEventCreateInfo event_info; |
| 11079 | VkEvent event; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11080 | VkResult err; |
| 11081 | |
| 11082 | memset(&event_info, 0, sizeof(event_info)); |
| 11083 | event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 11084 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11085 | err = vkCreateEvent(device(), &event_info, NULL, &event); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11086 | ASSERT_VK_SUCCESS(err); |
| 11087 | |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11088 | err = vkResetEvent(device(), event); |
| 11089 | ASSERT_VK_SUCCESS(err); |
| 11090 | |
| 11091 | struct thread_data_struct data; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11092 | data.commandBuffer = commandBuffer.GetBufferHandle(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11093 | data.event = event; |
| 11094 | data.bailout = false; |
| 11095 | m_errorMonitor->SetBailout(&data.bailout); |
| 11096 | // Add many entries to command buffer from another thread. |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 11097 | test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11098 | // Add many entries to command buffer from this thread at the same time. |
| 11099 | AddToCommandBuffer(&data); |
Mark Lobodzinski | 5495d13 | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 11100 | |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 11101 | test_platform_thread_join(thread, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11102 | commandBuffer.EndCommandBuffer(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11103 | |
Mike Stroyan | 10b8cb7 | 2016-01-22 15:22:03 -0700 | [diff] [blame] | 11104 | m_errorMonitor->SetBailout(NULL); |
| 11105 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11106 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11107 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11108 | vkDestroyEvent(device(), event, NULL); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 11109 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 11110 | #endif // GTEST_IS_THREADSAFE |
| 11111 | #endif // THREADING_TESTS |
| 11112 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 11113 | #if SHADER_CHECKER_TESTS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11114 | TEST_F(VkLayerTest, InvalidSPIRVCodeSize) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11115 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 11116 | "Invalid SPIR-V header"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11117 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11118 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11119 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11120 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11121 | VkShaderModule module; |
| 11122 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 11123 | struct icd_spv_header spv; |
| 11124 | |
| 11125 | spv.magic = ICD_SPV_MAGIC; |
| 11126 | spv.version = ICD_SPV_VERSION; |
| 11127 | spv.gen_magic = 0; |
| 11128 | |
| 11129 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 11130 | moduleCreateInfo.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11131 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11132 | moduleCreateInfo.codeSize = 4; |
| 11133 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11134 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11135 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11136 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11137 | } |
| 11138 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11139 | TEST_F(VkLayerTest, InvalidSPIRVMagic) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11140 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 11141 | "Invalid SPIR-V magic number"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11142 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11143 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11144 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11145 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11146 | VkShaderModule module; |
| 11147 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 11148 | struct icd_spv_header spv; |
| 11149 | |
| 11150 | spv.magic = ~ICD_SPV_MAGIC; |
| 11151 | spv.version = ICD_SPV_VERSION; |
| 11152 | spv.gen_magic = 0; |
| 11153 | |
| 11154 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 11155 | moduleCreateInfo.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11156 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11157 | moduleCreateInfo.codeSize = sizeof(spv) + 10; |
| 11158 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11159 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11160 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11161 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11162 | } |
| 11163 | |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 11164 | #if 0 |
| 11165 | // Not currently covered by SPIRV-Tools validator |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11166 | TEST_F(VkLayerTest, InvalidSPIRVVersion) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11167 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 11168 | "Invalid SPIR-V header"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11169 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11170 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11171 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11172 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11173 | VkShaderModule module; |
| 11174 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 11175 | struct icd_spv_header spv; |
| 11176 | |
| 11177 | spv.magic = ICD_SPV_MAGIC; |
| 11178 | spv.version = ~ICD_SPV_VERSION; |
| 11179 | spv.gen_magic = 0; |
| 11180 | |
| 11181 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 11182 | moduleCreateInfo.pNext = NULL; |
| 11183 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11184 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11185 | moduleCreateInfo.codeSize = sizeof(spv) + 10; |
| 11186 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11187 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11188 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11189 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11190 | } |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 11191 | #endif |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 11192 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11193 | TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 11194 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11195 | "not consumed by fragment shader"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11196 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 11197 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 11198 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 11199 | |
| 11200 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11201 | "#version 450\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 11202 | "\n" |
| 11203 | "layout(location=0) out float x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11204 | "out gl_PerVertex {\n" |
| 11205 | " vec4 gl_Position;\n" |
| 11206 | "};\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 11207 | "void main(){\n" |
| 11208 | " gl_Position = vec4(1);\n" |
| 11209 | " x = 0;\n" |
| 11210 | "}\n"; |
| 11211 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11212 | "#version 450\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 11213 | "\n" |
| 11214 | "layout(location=0) out vec4 color;\n" |
| 11215 | "void main(){\n" |
| 11216 | " color = vec4(1);\n" |
| 11217 | "}\n"; |
| 11218 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11219 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11220 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 11221 | |
| 11222 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11223 | pipe.AddColorAttachment(); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 11224 | pipe.AddShader(&vs); |
| 11225 | pipe.AddShader(&fs); |
| 11226 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 11227 | VkDescriptorSetObj descriptorSet(m_device); |
| 11228 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11229 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 11230 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11231 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 11232 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11233 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 11234 | } |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 11235 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11236 | TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11237 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11238 | "not written by vertex shader"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11239 | |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 11240 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 11241 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 11242 | |
| 11243 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11244 | "#version 450\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 11245 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11246 | "out gl_PerVertex {\n" |
| 11247 | " vec4 gl_Position;\n" |
| 11248 | "};\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 11249 | "void main(){\n" |
| 11250 | " gl_Position = vec4(1);\n" |
| 11251 | "}\n"; |
| 11252 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11253 | "#version 450\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 11254 | "\n" |
| 11255 | "layout(location=0) in float x;\n" |
| 11256 | "layout(location=0) out vec4 color;\n" |
| 11257 | "void main(){\n" |
| 11258 | " color = vec4(x);\n" |
| 11259 | "}\n"; |
| 11260 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11261 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11262 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 11263 | |
| 11264 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11265 | pipe.AddColorAttachment(); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 11266 | pipe.AddShader(&vs); |
| 11267 | pipe.AddShader(&fs); |
| 11268 | |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 11269 | VkDescriptorSetObj descriptorSet(m_device); |
| 11270 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11271 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 11272 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11273 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 11274 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11275 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 11276 | } |
| 11277 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11278 | TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) { |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 11279 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11280 | "not written by vertex shader"); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 11281 | |
| 11282 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11283 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11284 | |
| 11285 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11286 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 11287 | "\n" |
| 11288 | "out gl_PerVertex {\n" |
| 11289 | " vec4 gl_Position;\n" |
| 11290 | "};\n" |
| 11291 | "void main(){\n" |
| 11292 | " gl_Position = vec4(1);\n" |
| 11293 | "}\n"; |
| 11294 | char const *fsSource = |
| 11295 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 11296 | "\n" |
| 11297 | "in block { layout(location=0) float x; } ins;\n" |
| 11298 | "layout(location=0) out vec4 color;\n" |
| 11299 | "void main(){\n" |
| 11300 | " color = vec4(ins.x);\n" |
| 11301 | "}\n"; |
| 11302 | |
| 11303 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11304 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11305 | |
| 11306 | VkPipelineObj pipe(m_device); |
| 11307 | pipe.AddColorAttachment(); |
| 11308 | pipe.AddShader(&vs); |
| 11309 | pipe.AddShader(&fs); |
| 11310 | |
| 11311 | VkDescriptorSetObj descriptorSet(m_device); |
| 11312 | descriptorSet.AppendDummy(); |
| 11313 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11314 | |
| 11315 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11316 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11317 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 11318 | } |
| 11319 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11320 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) { |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 11321 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 11322 | "Type mismatch on location 0.0: 'ptr to " |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11323 | "output arr[2] of float32' vs 'ptr to " |
| 11324 | "input arr[3] of float32'"); |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 11325 | |
| 11326 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11327 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11328 | |
| 11329 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11330 | "#version 450\n" |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 11331 | "\n" |
| 11332 | "layout(location=0) out float x[2];\n" |
| 11333 | "out gl_PerVertex {\n" |
| 11334 | " vec4 gl_Position;\n" |
| 11335 | "};\n" |
| 11336 | "void main(){\n" |
| 11337 | " x[0] = 0; x[1] = 0;\n" |
| 11338 | " gl_Position = vec4(1);\n" |
| 11339 | "}\n"; |
| 11340 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11341 | "#version 450\n" |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 11342 | "\n" |
| 11343 | "layout(location=0) in float x[3];\n" |
| 11344 | "layout(location=0) out vec4 color;\n" |
| 11345 | "void main(){\n" |
| 11346 | " color = vec4(x[0] + x[1] + x[2]);\n" |
| 11347 | "}\n"; |
| 11348 | |
| 11349 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11350 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11351 | |
| 11352 | VkPipelineObj pipe(m_device); |
| 11353 | pipe.AddColorAttachment(); |
| 11354 | pipe.AddShader(&vs); |
| 11355 | pipe.AddShader(&fs); |
| 11356 | |
| 11357 | VkDescriptorSetObj descriptorSet(m_device); |
| 11358 | descriptorSet.AppendDummy(); |
| 11359 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11360 | |
| 11361 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11362 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11363 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 11364 | } |
| 11365 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11366 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11367 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11368 | "Type mismatch on location 0"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11369 | |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 11370 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 11371 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 11372 | |
| 11373 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11374 | "#version 450\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 11375 | "\n" |
| 11376 | "layout(location=0) out int x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11377 | "out gl_PerVertex {\n" |
| 11378 | " vec4 gl_Position;\n" |
| 11379 | "};\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 11380 | "void main(){\n" |
| 11381 | " x = 0;\n" |
| 11382 | " gl_Position = vec4(1);\n" |
| 11383 | "}\n"; |
| 11384 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11385 | "#version 450\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 11386 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11387 | "layout(location=0) in float x;\n" /* VS writes int */ |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 11388 | "layout(location=0) out vec4 color;\n" |
| 11389 | "void main(){\n" |
| 11390 | " color = vec4(x);\n" |
| 11391 | "}\n"; |
| 11392 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11393 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11394 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 11395 | |
| 11396 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11397 | pipe.AddColorAttachment(); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 11398 | pipe.AddShader(&vs); |
| 11399 | pipe.AddShader(&fs); |
| 11400 | |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 11401 | VkDescriptorSetObj descriptorSet(m_device); |
| 11402 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11403 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 11404 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11405 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 11406 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11407 | m_errorMonitor->VerifyFound(); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 11408 | } |
| 11409 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11410 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) { |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 11411 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11412 | "Type mismatch on location 0"); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 11413 | |
| 11414 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11415 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11416 | |
| 11417 | char const *vsSource = |
| 11418 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 11419 | "\n" |
| 11420 | "out block { layout(location=0) int x; } outs;\n" |
| 11421 | "out gl_PerVertex {\n" |
| 11422 | " vec4 gl_Position;\n" |
| 11423 | "};\n" |
| 11424 | "void main(){\n" |
| 11425 | " outs.x = 0;\n" |
| 11426 | " gl_Position = vec4(1);\n" |
| 11427 | "}\n"; |
| 11428 | char const *fsSource = |
| 11429 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 11430 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11431 | "in block { layout(location=0) float x; } ins;\n" /* VS writes int */ |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 11432 | "layout(location=0) out vec4 color;\n" |
| 11433 | "void main(){\n" |
| 11434 | " color = vec4(ins.x);\n" |
| 11435 | "}\n"; |
| 11436 | |
| 11437 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11438 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11439 | |
| 11440 | VkPipelineObj pipe(m_device); |
| 11441 | pipe.AddColorAttachment(); |
| 11442 | pipe.AddShader(&vs); |
| 11443 | pipe.AddShader(&fs); |
| 11444 | |
| 11445 | VkDescriptorSetObj descriptorSet(m_device); |
| 11446 | descriptorSet.AppendDummy(); |
| 11447 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11448 | |
| 11449 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11450 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11451 | m_errorMonitor->VerifyFound(); |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 11452 | } |
| 11453 | |
| 11454 | TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) { |
| 11455 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11456 | "location 0.0 which is not written by vertex shader"); |
| 11457 | |
| 11458 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11459 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11460 | |
| 11461 | char const *vsSource = |
| 11462 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 11463 | "\n" |
| 11464 | "out block { layout(location=1) float x; } outs;\n" |
| 11465 | "out gl_PerVertex {\n" |
| 11466 | " vec4 gl_Position;\n" |
| 11467 | "};\n" |
| 11468 | "void main(){\n" |
| 11469 | " outs.x = 0;\n" |
| 11470 | " gl_Position = vec4(1);\n" |
| 11471 | "}\n"; |
| 11472 | char const *fsSource = |
| 11473 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 11474 | "\n" |
| 11475 | "in block { layout(location=0) float x; } ins;\n" |
| 11476 | "layout(location=0) out vec4 color;\n" |
| 11477 | "void main(){\n" |
| 11478 | " color = vec4(ins.x);\n" |
| 11479 | "}\n"; |
| 11480 | |
| 11481 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11482 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11483 | |
| 11484 | VkPipelineObj pipe(m_device); |
| 11485 | pipe.AddColorAttachment(); |
| 11486 | pipe.AddShader(&vs); |
| 11487 | pipe.AddShader(&fs); |
| 11488 | |
| 11489 | VkDescriptorSetObj descriptorSet(m_device); |
| 11490 | descriptorSet.AppendDummy(); |
| 11491 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11492 | |
| 11493 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11494 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11495 | m_errorMonitor->VerifyFound(); |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 11496 | } |
| 11497 | |
| 11498 | TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) { |
| 11499 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11500 | "location 0.1 which is not written by vertex shader"); |
| 11501 | |
| 11502 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11503 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11504 | |
| 11505 | char const *vsSource = |
| 11506 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 11507 | "\n" |
| 11508 | "out block { layout(location=0, component=0) float x; } outs;\n" |
| 11509 | "out gl_PerVertex {\n" |
| 11510 | " vec4 gl_Position;\n" |
| 11511 | "};\n" |
| 11512 | "void main(){\n" |
| 11513 | " outs.x = 0;\n" |
| 11514 | " gl_Position = vec4(1);\n" |
| 11515 | "}\n"; |
| 11516 | char const *fsSource = |
| 11517 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 11518 | "\n" |
| 11519 | "in block { layout(location=0, component=1) float x; } ins;\n" |
| 11520 | "layout(location=0) out vec4 color;\n" |
| 11521 | "void main(){\n" |
| 11522 | " color = vec4(ins.x);\n" |
| 11523 | "}\n"; |
| 11524 | |
| 11525 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11526 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11527 | |
| 11528 | VkPipelineObj pipe(m_device); |
| 11529 | pipe.AddColorAttachment(); |
| 11530 | pipe.AddShader(&vs); |
| 11531 | pipe.AddShader(&fs); |
| 11532 | |
| 11533 | VkDescriptorSetObj descriptorSet(m_device); |
| 11534 | descriptorSet.AppendDummy(); |
| 11535 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11536 | |
| 11537 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11538 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11539 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 11540 | } |
| 11541 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11542 | TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 11543 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11544 | "location 0 not consumed by VS"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11545 | |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11546 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 11547 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11548 | |
| 11549 | VkVertexInputBindingDescription input_binding; |
| 11550 | memset(&input_binding, 0, sizeof(input_binding)); |
| 11551 | |
| 11552 | VkVertexInputAttributeDescription input_attrib; |
| 11553 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 11554 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 11555 | |
| 11556 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11557 | "#version 450\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11558 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11559 | "out gl_PerVertex {\n" |
| 11560 | " vec4 gl_Position;\n" |
| 11561 | "};\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11562 | "void main(){\n" |
| 11563 | " gl_Position = vec4(1);\n" |
| 11564 | "}\n"; |
| 11565 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11566 | "#version 450\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11567 | "\n" |
| 11568 | "layout(location=0) out vec4 color;\n" |
| 11569 | "void main(){\n" |
| 11570 | " color = vec4(1);\n" |
| 11571 | "}\n"; |
| 11572 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11573 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11574 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11575 | |
| 11576 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11577 | pipe.AddColorAttachment(); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11578 | pipe.AddShader(&vs); |
| 11579 | pipe.AddShader(&fs); |
| 11580 | |
| 11581 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 11582 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 11583 | |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11584 | VkDescriptorSetObj descriptorSet(m_device); |
| 11585 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11586 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11587 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11588 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11589 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11590 | m_errorMonitor->VerifyFound(); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 11591 | } |
| 11592 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11593 | TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 11594 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11595 | "location 0 not consumed by VS"); |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 11596 | |
| 11597 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11598 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11599 | |
| 11600 | VkVertexInputBindingDescription input_binding; |
| 11601 | memset(&input_binding, 0, sizeof(input_binding)); |
| 11602 | |
| 11603 | VkVertexInputAttributeDescription input_attrib; |
| 11604 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 11605 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 11606 | |
| 11607 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11608 | "#version 450\n" |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 11609 | "\n" |
| 11610 | "layout(location=1) in float x;\n" |
| 11611 | "out gl_PerVertex {\n" |
| 11612 | " vec4 gl_Position;\n" |
| 11613 | "};\n" |
| 11614 | "void main(){\n" |
| 11615 | " gl_Position = vec4(x);\n" |
| 11616 | "}\n"; |
| 11617 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11618 | "#version 450\n" |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 11619 | "\n" |
| 11620 | "layout(location=0) out vec4 color;\n" |
| 11621 | "void main(){\n" |
| 11622 | " color = vec4(1);\n" |
| 11623 | "}\n"; |
| 11624 | |
| 11625 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11626 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11627 | |
| 11628 | VkPipelineObj pipe(m_device); |
| 11629 | pipe.AddColorAttachment(); |
| 11630 | pipe.AddShader(&vs); |
| 11631 | pipe.AddShader(&fs); |
| 11632 | |
| 11633 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 11634 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 11635 | |
| 11636 | VkDescriptorSetObj descriptorSet(m_device); |
| 11637 | descriptorSet.AppendDummy(); |
| 11638 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11639 | |
| 11640 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11641 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11642 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 11643 | } |
| 11644 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11645 | TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) { |
| 11646 | m_errorMonitor->SetDesiredFailureMsg( |
| 11647 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11648 | "VS consumes input at location 0 but not provided"); |
| 11649 | |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11650 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 11651 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11652 | |
| 11653 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11654 | "#version 450\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11655 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11656 | "layout(location=0) in vec4 x;\n" /* not provided */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11657 | "out gl_PerVertex {\n" |
| 11658 | " vec4 gl_Position;\n" |
| 11659 | "};\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11660 | "void main(){\n" |
| 11661 | " gl_Position = x;\n" |
| 11662 | "}\n"; |
| 11663 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11664 | "#version 450\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11665 | "\n" |
| 11666 | "layout(location=0) out vec4 color;\n" |
| 11667 | "void main(){\n" |
| 11668 | " color = vec4(1);\n" |
| 11669 | "}\n"; |
| 11670 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11671 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11672 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11673 | |
| 11674 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11675 | pipe.AddColorAttachment(); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11676 | pipe.AddShader(&vs); |
| 11677 | pipe.AddShader(&fs); |
| 11678 | |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11679 | VkDescriptorSetObj descriptorSet(m_device); |
| 11680 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11681 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11682 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11683 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11684 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11685 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 11686 | } |
| 11687 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11688 | TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) { |
| 11689 | m_errorMonitor->SetDesiredFailureMsg( |
| 11690 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11691 | "location 0 does not match VS input type"); |
| 11692 | |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11693 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 11694 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11695 | |
| 11696 | VkVertexInputBindingDescription input_binding; |
| 11697 | memset(&input_binding, 0, sizeof(input_binding)); |
| 11698 | |
| 11699 | VkVertexInputAttributeDescription input_attrib; |
| 11700 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 11701 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 11702 | |
| 11703 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11704 | "#version 450\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11705 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11706 | "layout(location=0) in int x;\n" /* attrib provided float */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11707 | "out gl_PerVertex {\n" |
| 11708 | " vec4 gl_Position;\n" |
| 11709 | "};\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11710 | "void main(){\n" |
| 11711 | " gl_Position = vec4(x);\n" |
| 11712 | "}\n"; |
| 11713 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11714 | "#version 450\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11715 | "\n" |
| 11716 | "layout(location=0) out vec4 color;\n" |
| 11717 | "void main(){\n" |
| 11718 | " color = vec4(1);\n" |
| 11719 | "}\n"; |
| 11720 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11721 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11722 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11723 | |
| 11724 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11725 | pipe.AddColorAttachment(); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11726 | pipe.AddShader(&vs); |
| 11727 | pipe.AddShader(&fs); |
| 11728 | |
| 11729 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 11730 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 11731 | |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11732 | VkDescriptorSetObj descriptorSet(m_device); |
| 11733 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11734 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11735 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11736 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11737 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11738 | m_errorMonitor->VerifyFound(); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 11739 | } |
| 11740 | |
Chris Forbes | c68b43c | 2016-04-06 11:18:47 +1200 | [diff] [blame] | 11741 | TEST_F(VkLayerTest, CreatePipelineDuplicateStage) { |
| 11742 | m_errorMonitor->SetDesiredFailureMsg( |
| 11743 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11744 | "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT"); |
| 11745 | |
| 11746 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11747 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11748 | |
| 11749 | char const *vsSource = |
| 11750 | "#version 450\n" |
| 11751 | "\n" |
| 11752 | "out gl_PerVertex {\n" |
| 11753 | " vec4 gl_Position;\n" |
| 11754 | "};\n" |
| 11755 | "void main(){\n" |
| 11756 | " gl_Position = vec4(1);\n" |
| 11757 | "}\n"; |
| 11758 | char const *fsSource = |
| 11759 | "#version 450\n" |
| 11760 | "\n" |
| 11761 | "layout(location=0) out vec4 color;\n" |
| 11762 | "void main(){\n" |
| 11763 | " color = vec4(1);\n" |
| 11764 | "}\n"; |
| 11765 | |
| 11766 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11767 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11768 | |
| 11769 | VkPipelineObj pipe(m_device); |
| 11770 | pipe.AddColorAttachment(); |
| 11771 | pipe.AddShader(&vs); |
| 11772 | pipe.AddShader(&vs); |
| 11773 | pipe.AddShader(&fs); |
| 11774 | |
| 11775 | VkDescriptorSetObj descriptorSet(m_device); |
| 11776 | descriptorSet.AppendDummy(); |
| 11777 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11778 | |
| 11779 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11780 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11781 | m_errorMonitor->VerifyFound(); |
Chris Forbes | c68b43c | 2016-04-06 11:18:47 +1200 | [diff] [blame] | 11782 | } |
| 11783 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11784 | TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11785 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11786 | |
| 11787 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11788 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11789 | |
| 11790 | VkVertexInputBindingDescription input_binding; |
| 11791 | memset(&input_binding, 0, sizeof(input_binding)); |
| 11792 | |
| 11793 | VkVertexInputAttributeDescription input_attribs[2]; |
| 11794 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 11795 | |
| 11796 | for (int i = 0; i < 2; i++) { |
| 11797 | input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 11798 | input_attribs[i].location = i; |
| 11799 | } |
| 11800 | |
| 11801 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11802 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11803 | "\n" |
| 11804 | "layout(location=0) in mat2x4 x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11805 | "out gl_PerVertex {\n" |
| 11806 | " vec4 gl_Position;\n" |
| 11807 | "};\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11808 | "void main(){\n" |
| 11809 | " gl_Position = x[0] + x[1];\n" |
| 11810 | "}\n"; |
| 11811 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11812 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11813 | "\n" |
| 11814 | "layout(location=0) out vec4 color;\n" |
| 11815 | "void main(){\n" |
| 11816 | " color = vec4(1);\n" |
| 11817 | "}\n"; |
| 11818 | |
| 11819 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11820 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11821 | |
| 11822 | VkPipelineObj pipe(m_device); |
| 11823 | pipe.AddColorAttachment(); |
| 11824 | pipe.AddShader(&vs); |
| 11825 | pipe.AddShader(&fs); |
| 11826 | |
| 11827 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 11828 | pipe.AddVertexInputAttribs(input_attribs, 2); |
| 11829 | |
| 11830 | VkDescriptorSetObj descriptorSet(m_device); |
| 11831 | descriptorSet.AppendDummy(); |
| 11832 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11833 | |
| 11834 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11835 | |
| 11836 | /* expect success */ |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11837 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11838 | } |
| 11839 | |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11840 | TEST_F(VkLayerTest, CreatePipelineAttribArrayType) |
| 11841 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11842 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11843 | |
| 11844 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11845 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11846 | |
| 11847 | VkVertexInputBindingDescription input_binding; |
| 11848 | memset(&input_binding, 0, sizeof(input_binding)); |
| 11849 | |
| 11850 | VkVertexInputAttributeDescription input_attribs[2]; |
| 11851 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 11852 | |
| 11853 | for (int i = 0; i < 2; i++) { |
| 11854 | input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 11855 | input_attribs[i].location = i; |
| 11856 | } |
| 11857 | |
| 11858 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11859 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11860 | "\n" |
| 11861 | "layout(location=0) in vec4 x[2];\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11862 | "out gl_PerVertex {\n" |
| 11863 | " vec4 gl_Position;\n" |
| 11864 | "};\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11865 | "void main(){\n" |
| 11866 | " gl_Position = x[0] + x[1];\n" |
| 11867 | "}\n"; |
| 11868 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11869 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11870 | "\n" |
| 11871 | "layout(location=0) out vec4 color;\n" |
| 11872 | "void main(){\n" |
| 11873 | " color = vec4(1);\n" |
| 11874 | "}\n"; |
| 11875 | |
| 11876 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11877 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11878 | |
| 11879 | VkPipelineObj pipe(m_device); |
| 11880 | pipe.AddColorAttachment(); |
| 11881 | pipe.AddShader(&vs); |
| 11882 | pipe.AddShader(&fs); |
| 11883 | |
| 11884 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 11885 | pipe.AddVertexInputAttribs(input_attribs, 2); |
| 11886 | |
| 11887 | VkDescriptorSetObj descriptorSet(m_device); |
| 11888 | descriptorSet.AppendDummy(); |
| 11889 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11890 | |
| 11891 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11892 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11893 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11894 | } |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 11895 | |
Chris Forbes | bc290ce | 2016-07-06 12:01:49 +1200 | [diff] [blame] | 11896 | TEST_F(VkLayerTest, CreatePipelineAttribComponents) |
| 11897 | { |
| 11898 | m_errorMonitor->ExpectSuccess(); |
| 11899 | |
| 11900 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11901 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11902 | |
| 11903 | VkVertexInputBindingDescription input_binding; |
| 11904 | memset(&input_binding, 0, sizeof(input_binding)); |
| 11905 | |
| 11906 | VkVertexInputAttributeDescription input_attribs[3]; |
| 11907 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 11908 | |
| 11909 | for (int i = 0; i < 3; i++) { |
| 11910 | input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 11911 | input_attribs[i].location = i; |
| 11912 | } |
| 11913 | |
| 11914 | char const *vsSource = |
| 11915 | "#version 450\n" |
| 11916 | "\n" |
| 11917 | "layout(location=0) in vec4 x;\n" |
| 11918 | "layout(location=1) in vec3 y1;\n" |
| 11919 | "layout(location=1, component=3) in float y2;\n" |
| 11920 | "layout(location=2) in vec4 z;\n" |
| 11921 | "out gl_PerVertex {\n" |
| 11922 | " vec4 gl_Position;\n" |
| 11923 | "};\n" |
| 11924 | "void main(){\n" |
| 11925 | " gl_Position = x + vec4(y1, y2) + z;\n" |
| 11926 | "}\n"; |
| 11927 | char const *fsSource = |
| 11928 | "#version 450\n" |
| 11929 | "\n" |
| 11930 | "layout(location=0) out vec4 color;\n" |
| 11931 | "void main(){\n" |
| 11932 | " color = vec4(1);\n" |
| 11933 | "}\n"; |
| 11934 | |
| 11935 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11936 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11937 | |
| 11938 | VkPipelineObj pipe(m_device); |
| 11939 | pipe.AddColorAttachment(); |
| 11940 | pipe.AddShader(&vs); |
| 11941 | pipe.AddShader(&fs); |
| 11942 | |
| 11943 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 11944 | pipe.AddVertexInputAttribs(input_attribs, 3); |
| 11945 | |
| 11946 | VkDescriptorSetObj descriptorSet(m_device); |
| 11947 | descriptorSet.AppendDummy(); |
| 11948 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11949 | |
| 11950 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11951 | |
| 11952 | m_errorMonitor->VerifyNotFound(); |
| 11953 | } |
| 11954 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 11955 | TEST_F(VkLayerTest, CreatePipelineSimplePositive) |
| 11956 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11957 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 11958 | |
| 11959 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11960 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11961 | |
| 11962 | char const *vsSource = |
| 11963 | "#version 450\n" |
| 11964 | "out gl_PerVertex {\n" |
| 11965 | " vec4 gl_Position;\n" |
| 11966 | "};\n" |
| 11967 | "void main(){\n" |
| 11968 | " gl_Position = vec4(0);\n" |
| 11969 | "}\n"; |
| 11970 | char const *fsSource = |
| 11971 | "#version 450\n" |
| 11972 | "\n" |
| 11973 | "layout(location=0) out vec4 color;\n" |
| 11974 | "void main(){\n" |
| 11975 | " color = vec4(1);\n" |
| 11976 | "}\n"; |
| 11977 | |
| 11978 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11979 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11980 | |
| 11981 | VkPipelineObj pipe(m_device); |
| 11982 | pipe.AddColorAttachment(); |
| 11983 | pipe.AddShader(&vs); |
| 11984 | pipe.AddShader(&fs); |
| 11985 | |
| 11986 | VkDescriptorSetObj descriptorSet(m_device); |
| 11987 | descriptorSet.AppendDummy(); |
| 11988 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11989 | |
| 11990 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11991 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11992 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 11993 | } |
| 11994 | |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 11995 | TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch) |
| 11996 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11997 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 11998 | |
| 11999 | // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block |
| 12000 | |
| 12001 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12002 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 12003 | |
| 12004 | char const *vsSource = |
| 12005 | "#version 450\n" |
| 12006 | "out gl_PerVertex {\n" |
| 12007 | " vec4 gl_Position;\n" |
| 12008 | "};\n" |
| 12009 | "layout(location=0) out vec3 x;\n" |
| 12010 | "layout(location=1) out ivec3 y;\n" |
| 12011 | "layout(location=2) out vec3 z;\n" |
| 12012 | "void main(){\n" |
| 12013 | " gl_Position = vec4(0);\n" |
| 12014 | " x = vec3(0); y = ivec3(0); z = vec3(0);\n" |
| 12015 | "}\n"; |
| 12016 | char const *fsSource = |
| 12017 | "#version 450\n" |
| 12018 | "\n" |
| 12019 | "layout(location=0) out vec4 color;\n" |
| 12020 | "layout(location=0) in float x;\n" |
| 12021 | "layout(location=1) flat in int y;\n" |
| 12022 | "layout(location=2) in vec2 z;\n" |
| 12023 | "void main(){\n" |
| 12024 | " color = vec4(1 + x + y + z.x);\n" |
| 12025 | "}\n"; |
| 12026 | |
| 12027 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 12028 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 12029 | |
| 12030 | VkPipelineObj pipe(m_device); |
| 12031 | pipe.AddColorAttachment(); |
| 12032 | pipe.AddShader(&vs); |
| 12033 | pipe.AddShader(&fs); |
| 12034 | |
| 12035 | VkDescriptorSetObj descriptorSet(m_device); |
| 12036 | descriptorSet.AppendDummy(); |
| 12037 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 12038 | |
Mike Stroyan | 255e958 | 2016-06-24 09:49:32 -0600 | [diff] [blame] | 12039 | VkResult err = VK_SUCCESS; |
| 12040 | err = |
| 12041 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 12042 | ASSERT_VK_SUCCESS(err); |
| 12043 | |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 12044 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12045 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 12046 | } |
| 12047 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 12048 | TEST_F(VkLayerTest, CreatePipelineTessPerVertex) |
| 12049 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12050 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 12051 | |
| 12052 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12053 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 12054 | |
Chris Forbes | c1e852d | 2016-04-04 19:26:42 +1200 | [diff] [blame] | 12055 | if (!m_device->phy().features().tessellationShader) { |
| 12056 | printf("Device does not support tessellation shaders; skipped.\n"); |
| 12057 | return; |
| 12058 | } |
| 12059 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 12060 | char const *vsSource = |
| 12061 | "#version 450\n" |
| 12062 | "void main(){}\n"; |
| 12063 | char const *tcsSource = |
| 12064 | "#version 450\n" |
| 12065 | "layout(location=0) out int x[];\n" |
| 12066 | "layout(vertices=3) out;\n" |
| 12067 | "void main(){\n" |
| 12068 | " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n" |
| 12069 | " gl_TessLevelInner[0] = 1;\n" |
| 12070 | " x[gl_InvocationID] = gl_InvocationID;\n" |
| 12071 | "}\n"; |
| 12072 | char const *tesSource = |
| 12073 | "#version 450\n" |
| 12074 | "layout(triangles, equal_spacing, cw) in;\n" |
| 12075 | "layout(location=0) in int x[];\n" |
| 12076 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 12077 | "void main(){\n" |
| 12078 | " gl_Position.xyz = gl_TessCoord;\n" |
| 12079 | " gl_Position.w = x[0] + x[1] + x[2];\n" |
| 12080 | "}\n"; |
| 12081 | char const *fsSource = |
| 12082 | "#version 450\n" |
| 12083 | "layout(location=0) out vec4 color;\n" |
| 12084 | "void main(){\n" |
| 12085 | " color = vec4(1);\n" |
| 12086 | "}\n"; |
| 12087 | |
| 12088 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 12089 | VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this); |
| 12090 | VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this); |
| 12091 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 12092 | |
| 12093 | VkPipelineInputAssemblyStateCreateInfo iasci{ |
| 12094 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, |
| 12095 | nullptr, |
| 12096 | 0, |
| 12097 | VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, |
| 12098 | VK_FALSE}; |
| 12099 | |
Chris Forbes | b4cacb6 | 2016-04-04 19:15:00 +1200 | [diff] [blame] | 12100 | VkPipelineTessellationStateCreateInfo tsci{ |
| 12101 | VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, |
| 12102 | nullptr, |
| 12103 | 0, |
| 12104 | 3}; |
| 12105 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 12106 | VkPipelineObj pipe(m_device); |
| 12107 | pipe.SetInputAssembly(&iasci); |
Chris Forbes | b4cacb6 | 2016-04-04 19:15:00 +1200 | [diff] [blame] | 12108 | pipe.SetTessellation(&tsci); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 12109 | pipe.AddColorAttachment(); |
| 12110 | pipe.AddShader(&vs); |
| 12111 | pipe.AddShader(&tcs); |
| 12112 | pipe.AddShader(&tes); |
| 12113 | pipe.AddShader(&fs); |
| 12114 | |
| 12115 | VkDescriptorSetObj descriptorSet(m_device); |
| 12116 | descriptorSet.AppendDummy(); |
| 12117 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 12118 | |
| 12119 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 12120 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12121 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 12122 | } |
| 12123 | |
Chris Forbes | a0ab815 | 2016-04-20 13:34:27 +1200 | [diff] [blame] | 12124 | TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive) |
| 12125 | { |
| 12126 | m_errorMonitor->ExpectSuccess(); |
| 12127 | |
| 12128 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12129 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 12130 | |
| 12131 | if (!m_device->phy().features().geometryShader) { |
| 12132 | printf("Device does not support geometry shaders; skipped.\n"); |
| 12133 | return; |
| 12134 | } |
| 12135 | |
| 12136 | char const *vsSource = |
| 12137 | "#version 450\n" |
| 12138 | "layout(location=0) out VertexData { vec4 x; } vs_out;\n" |
| 12139 | "void main(){\n" |
| 12140 | " vs_out.x = vec4(1);\n" |
| 12141 | "}\n"; |
| 12142 | char const *gsSource = |
| 12143 | "#version 450\n" |
| 12144 | "layout(triangles) in;\n" |
| 12145 | "layout(triangle_strip, max_vertices=3) out;\n" |
| 12146 | "layout(location=0) in VertexData { vec4 x; } gs_in[];\n" |
| 12147 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 12148 | "void main() {\n" |
| 12149 | " gl_Position = gs_in[0].x;\n" |
| 12150 | " EmitVertex();\n" |
| 12151 | "}\n"; |
| 12152 | char const *fsSource = |
| 12153 | "#version 450\n" |
| 12154 | "layout(location=0) out vec4 color;\n" |
| 12155 | "void main(){\n" |
| 12156 | " color = vec4(1);\n" |
| 12157 | "}\n"; |
| 12158 | |
| 12159 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 12160 | VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this); |
| 12161 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 12162 | |
| 12163 | VkPipelineObj pipe(m_device); |
| 12164 | pipe.AddColorAttachment(); |
| 12165 | pipe.AddShader(&vs); |
| 12166 | pipe.AddShader(&gs); |
| 12167 | pipe.AddShader(&fs); |
| 12168 | |
| 12169 | VkDescriptorSetObj descriptorSet(m_device); |
| 12170 | descriptorSet.AppendDummy(); |
| 12171 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 12172 | |
| 12173 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 12174 | |
| 12175 | m_errorMonitor->VerifyNotFound(); |
| 12176 | } |
| 12177 | |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 12178 | TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) |
| 12179 | { |
| 12180 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12181 | "is per-vertex in tessellation control shader stage " |
| 12182 | "but per-patch in tessellation evaluation shader stage"); |
| 12183 | |
| 12184 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12185 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 12186 | |
Chris Forbes | c1e852d | 2016-04-04 19:26:42 +1200 | [diff] [blame] | 12187 | if (!m_device->phy().features().tessellationShader) { |
| 12188 | printf("Device does not support tessellation shaders; skipped.\n"); |
| 12189 | return; |
| 12190 | } |
| 12191 | |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 12192 | char const *vsSource = |
| 12193 | "#version 450\n" |
| 12194 | "void main(){}\n"; |
| 12195 | char const *tcsSource = |
| 12196 | "#version 450\n" |
| 12197 | "layout(location=0) out int x[];\n" |
| 12198 | "layout(vertices=3) out;\n" |
| 12199 | "void main(){\n" |
| 12200 | " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n" |
| 12201 | " gl_TessLevelInner[0] = 1;\n" |
| 12202 | " x[gl_InvocationID] = gl_InvocationID;\n" |
| 12203 | "}\n"; |
| 12204 | char const *tesSource = |
| 12205 | "#version 450\n" |
| 12206 | "layout(triangles, equal_spacing, cw) in;\n" |
| 12207 | "layout(location=0) patch in int x;\n" |
| 12208 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 12209 | "void main(){\n" |
| 12210 | " gl_Position.xyz = gl_TessCoord;\n" |
| 12211 | " gl_Position.w = x;\n" |
| 12212 | "}\n"; |
| 12213 | char const *fsSource = |
| 12214 | "#version 450\n" |
| 12215 | "layout(location=0) out vec4 color;\n" |
| 12216 | "void main(){\n" |
| 12217 | " color = vec4(1);\n" |
| 12218 | "}\n"; |
| 12219 | |
| 12220 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 12221 | VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this); |
| 12222 | VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this); |
| 12223 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 12224 | |
| 12225 | VkPipelineInputAssemblyStateCreateInfo iasci{ |
| 12226 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, |
| 12227 | nullptr, |
| 12228 | 0, |
| 12229 | VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, |
| 12230 | VK_FALSE}; |
| 12231 | |
| 12232 | VkPipelineTessellationStateCreateInfo tsci{ |
| 12233 | VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, |
| 12234 | nullptr, |
| 12235 | 0, |
| 12236 | 3}; |
| 12237 | |
| 12238 | VkPipelineObj pipe(m_device); |
| 12239 | pipe.SetInputAssembly(&iasci); |
| 12240 | pipe.SetTessellation(&tsci); |
| 12241 | pipe.AddColorAttachment(); |
| 12242 | pipe.AddShader(&vs); |
| 12243 | pipe.AddShader(&tcs); |
| 12244 | pipe.AddShader(&tes); |
| 12245 | pipe.AddShader(&fs); |
| 12246 | |
| 12247 | VkDescriptorSetObj descriptorSet(m_device); |
| 12248 | descriptorSet.AppendDummy(); |
| 12249 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 12250 | |
| 12251 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 12252 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12253 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 12254 | } |
| 12255 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12256 | TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) { |
| 12257 | m_errorMonitor->SetDesiredFailureMsg( |
| 12258 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12259 | "Duplicate vertex input binding descriptions for binding 0"); |
| 12260 | |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 12261 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 12262 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 12263 | |
| 12264 | /* Two binding descriptions for binding 0 */ |
| 12265 | VkVertexInputBindingDescription input_bindings[2]; |
| 12266 | memset(input_bindings, 0, sizeof(input_bindings)); |
| 12267 | |
| 12268 | VkVertexInputAttributeDescription input_attrib; |
| 12269 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 12270 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 12271 | |
| 12272 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 12273 | "#version 450\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 12274 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12275 | "layout(location=0) in float x;\n" /* attrib provided float */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 12276 | "out gl_PerVertex {\n" |
| 12277 | " vec4 gl_Position;\n" |
| 12278 | "};\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 12279 | "void main(){\n" |
| 12280 | " gl_Position = vec4(x);\n" |
| 12281 | "}\n"; |
| 12282 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 12283 | "#version 450\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 12284 | "\n" |
| 12285 | "layout(location=0) out vec4 color;\n" |
| 12286 | "void main(){\n" |
| 12287 | " color = vec4(1);\n" |
| 12288 | "}\n"; |
| 12289 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 12290 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 12291 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 12292 | |
| 12293 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 12294 | pipe.AddColorAttachment(); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 12295 | pipe.AddShader(&vs); |
| 12296 | pipe.AddShader(&fs); |
| 12297 | |
| 12298 | pipe.AddVertexInputBindings(input_bindings, 2); |
| 12299 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 12300 | |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 12301 | VkDescriptorSetObj descriptorSet(m_device); |
| 12302 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12303 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 12304 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 12305 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 12306 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12307 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 12308 | } |
Chris Forbes | 8f68b56 | 2015-05-25 11:13:32 +1200 | [diff] [blame] | 12309 | |
Chris Forbes | 35efec7 | 2016-04-21 14:32:08 +1200 | [diff] [blame] | 12310 | TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) { |
| 12311 | m_errorMonitor->ExpectSuccess(); |
| 12312 | |
| 12313 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12314 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 12315 | |
Chris Forbes | 91cf3a8 | 2016-06-28 17:51:35 +1200 | [diff] [blame] | 12316 | if (!m_device->phy().features().shaderFloat64) { |
Chris Forbes | 35efec7 | 2016-04-21 14:32:08 +1200 | [diff] [blame] | 12317 | printf("Device does not support 64bit vertex attributes; skipped.\n"); |
| 12318 | return; |
| 12319 | } |
| 12320 | |
| 12321 | VkVertexInputBindingDescription input_bindings[1]; |
| 12322 | memset(input_bindings, 0, sizeof(input_bindings)); |
| 12323 | |
| 12324 | VkVertexInputAttributeDescription input_attribs[4]; |
| 12325 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 12326 | input_attribs[0].location = 0; |
| 12327 | input_attribs[0].offset = 0; |
| 12328 | input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 12329 | input_attribs[1].location = 2; |
| 12330 | input_attribs[1].offset = 32; |
| 12331 | input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 12332 | input_attribs[2].location = 4; |
| 12333 | input_attribs[2].offset = 64; |
| 12334 | input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 12335 | input_attribs[3].location = 6; |
| 12336 | input_attribs[3].offset = 96; |
| 12337 | input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 12338 | |
| 12339 | char const *vsSource = |
| 12340 | "#version 450\n" |
| 12341 | "\n" |
| 12342 | "layout(location=0) in dmat4 x;\n" |
| 12343 | "out gl_PerVertex {\n" |
| 12344 | " vec4 gl_Position;\n" |
| 12345 | "};\n" |
| 12346 | "void main(){\n" |
| 12347 | " gl_Position = vec4(x[0][0]);\n" |
| 12348 | "}\n"; |
| 12349 | char const *fsSource = |
| 12350 | "#version 450\n" |
| 12351 | "\n" |
| 12352 | "layout(location=0) out vec4 color;\n" |
| 12353 | "void main(){\n" |
| 12354 | " color = vec4(1);\n" |
| 12355 | "}\n"; |
| 12356 | |
| 12357 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 12358 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 12359 | |
| 12360 | VkPipelineObj pipe(m_device); |
| 12361 | pipe.AddColorAttachment(); |
| 12362 | pipe.AddShader(&vs); |
| 12363 | pipe.AddShader(&fs); |
| 12364 | |
| 12365 | pipe.AddVertexInputBindings(input_bindings, 1); |
| 12366 | pipe.AddVertexInputAttribs(input_attribs, 4); |
| 12367 | |
| 12368 | VkDescriptorSetObj descriptorSet(m_device); |
| 12369 | descriptorSet.AppendDummy(); |
| 12370 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 12371 | |
| 12372 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 12373 | |
| 12374 | m_errorMonitor->VerifyNotFound(); |
| 12375 | } |
| 12376 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12377 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 12378 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12379 | "Attachment 0 not written by FS"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12380 | |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 12381 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 12382 | |
| 12383 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 12384 | "#version 450\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 12385 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 12386 | "out gl_PerVertex {\n" |
| 12387 | " vec4 gl_Position;\n" |
| 12388 | "};\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 12389 | "void main(){\n" |
| 12390 | " gl_Position = vec4(1);\n" |
| 12391 | "}\n"; |
| 12392 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 12393 | "#version 450\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 12394 | "\n" |
| 12395 | "void main(){\n" |
| 12396 | "}\n"; |
| 12397 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 12398 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 12399 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 12400 | |
| 12401 | VkPipelineObj pipe(m_device); |
| 12402 | pipe.AddShader(&vs); |
| 12403 | pipe.AddShader(&fs); |
| 12404 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 12405 | /* set up CB 0, not written */ |
| 12406 | pipe.AddColorAttachment(); |
| 12407 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 12408 | |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 12409 | VkDescriptorSetObj descriptorSet(m_device); |
| 12410 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12411 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 12412 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 12413 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 12414 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12415 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 12416 | } |
| 12417 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12418 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12419 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 12420 | VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12421 | "FS writes to output location 1 with no matching attachment"); |
| 12422 | |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 12423 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 12424 | |
| 12425 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 12426 | "#version 450\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 12427 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 12428 | "out gl_PerVertex {\n" |
| 12429 | " vec4 gl_Position;\n" |
| 12430 | "};\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 12431 | "void main(){\n" |
| 12432 | " gl_Position = vec4(1);\n" |
| 12433 | "}\n"; |
| 12434 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 12435 | "#version 450\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 12436 | "\n" |
| 12437 | "layout(location=0) out vec4 x;\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12438 | "layout(location=1) out vec4 y;\n" /* no matching attachment for this */ |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 12439 | "void main(){\n" |
| 12440 | " x = vec4(1);\n" |
| 12441 | " y = vec4(1);\n" |
| 12442 | "}\n"; |
| 12443 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 12444 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 12445 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 12446 | |
| 12447 | VkPipelineObj pipe(m_device); |
| 12448 | pipe.AddShader(&vs); |
| 12449 | pipe.AddShader(&fs); |
| 12450 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 12451 | /* set up CB 0, not written */ |
| 12452 | pipe.AddColorAttachment(); |
| 12453 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 12454 | /* FS writes CB 1, but we don't configure it */ |
| 12455 | |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 12456 | VkDescriptorSetObj descriptorSet(m_device); |
| 12457 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12458 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 12459 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 12460 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 12461 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12462 | m_errorMonitor->VerifyFound(); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 12463 | } |
| 12464 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12465 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 12466 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12467 | "does not match FS output type"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12468 | |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 12469 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 12470 | |
| 12471 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 12472 | "#version 450\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 12473 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 12474 | "out gl_PerVertex {\n" |
| 12475 | " vec4 gl_Position;\n" |
| 12476 | "};\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 12477 | "void main(){\n" |
| 12478 | " gl_Position = vec4(1);\n" |
| 12479 | "}\n"; |
| 12480 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 12481 | "#version 450\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 12482 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12483 | "layout(location=0) out ivec4 x;\n" /* not UNORM */ |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 12484 | "void main(){\n" |
| 12485 | " x = ivec4(1);\n" |
| 12486 | "}\n"; |
| 12487 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 12488 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 12489 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 12490 | |
| 12491 | VkPipelineObj pipe(m_device); |
| 12492 | pipe.AddShader(&vs); |
| 12493 | pipe.AddShader(&fs); |
| 12494 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 12495 | /* set up CB 0; type is UNORM by default */ |
| 12496 | pipe.AddColorAttachment(); |
| 12497 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 12498 | |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 12499 | VkDescriptorSetObj descriptorSet(m_device); |
| 12500 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12501 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 12502 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 12503 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 12504 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12505 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 12506 | } |
Chris Forbes | 7b1b893 | 2015-06-05 14:43:36 +1200 | [diff] [blame] | 12507 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12508 | TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 12509 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12510 | "not declared in pipeline layout"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12511 | |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 12512 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 12513 | |
| 12514 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 12515 | "#version 450\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 12516 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 12517 | "out gl_PerVertex {\n" |
| 12518 | " vec4 gl_Position;\n" |
| 12519 | "};\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 12520 | "void main(){\n" |
| 12521 | " gl_Position = vec4(1);\n" |
| 12522 | "}\n"; |
| 12523 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 12524 | "#version 450\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 12525 | "\n" |
| 12526 | "layout(location=0) out vec4 x;\n" |
| 12527 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 12528 | "void main(){\n" |
| 12529 | " x = vec4(bar.y);\n" |
| 12530 | "}\n"; |
| 12531 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 12532 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 12533 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 12534 | |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 12535 | VkPipelineObj pipe(m_device); |
| 12536 | pipe.AddShader(&vs); |
| 12537 | pipe.AddShader(&fs); |
| 12538 | |
| 12539 | /* set up CB 0; type is UNORM by default */ |
| 12540 | pipe.AddColorAttachment(); |
| 12541 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 12542 | |
| 12543 | VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12544 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 12545 | |
| 12546 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 12547 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12548 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 12549 | } |
| 12550 | |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 12551 | TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) { |
| 12552 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12553 | "not declared in layout"); |
| 12554 | |
| 12555 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12556 | |
| 12557 | char const *vsSource = |
| 12558 | "#version 450\n" |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 12559 | "\n" |
| 12560 | "layout(push_constant, std430) uniform foo { float x; } consts;\n" |
| 12561 | "out gl_PerVertex {\n" |
| 12562 | " vec4 gl_Position;\n" |
| 12563 | "};\n" |
| 12564 | "void main(){\n" |
| 12565 | " gl_Position = vec4(consts.x);\n" |
| 12566 | "}\n"; |
| 12567 | char const *fsSource = |
| 12568 | "#version 450\n" |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 12569 | "\n" |
| 12570 | "layout(location=0) out vec4 x;\n" |
| 12571 | "void main(){\n" |
| 12572 | " x = vec4(1);\n" |
| 12573 | "}\n"; |
| 12574 | |
| 12575 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 12576 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 12577 | |
| 12578 | VkPipelineObj pipe(m_device); |
| 12579 | pipe.AddShader(&vs); |
| 12580 | pipe.AddShader(&fs); |
| 12581 | |
| 12582 | /* set up CB 0; type is UNORM by default */ |
| 12583 | pipe.AddColorAttachment(); |
| 12584 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 12585 | |
| 12586 | VkDescriptorSetObj descriptorSet(m_device); |
| 12587 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 12588 | |
| 12589 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 12590 | |
| 12591 | /* should have generated an error -- no push constant ranges provided! */ |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12592 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 12593 | } |
| 12594 | |
Chris Forbes | 10eb9ae | 2016-05-31 16:09:42 +1200 | [diff] [blame] | 12595 | TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) { |
| 12596 | m_errorMonitor->SetDesiredFailureMsg( |
| 12597 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12598 | "Shader uses descriptor slot 0.0"); |
| 12599 | |
| 12600 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12601 | |
| 12602 | char const *csSource = |
| 12603 | "#version 450\n" |
| 12604 | "\n" |
| 12605 | "layout(local_size_x=1) in;\n" |
| 12606 | "layout(set=0, binding=0) buffer block { vec4 x; };\n" |
| 12607 | "void main(){\n" |
| 12608 | " x = vec4(1);\n" |
| 12609 | "}\n"; |
| 12610 | |
| 12611 | VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this); |
| 12612 | |
| 12613 | VkDescriptorSetObj descriptorSet(m_device); |
| 12614 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 12615 | |
| 12616 | VkComputePipelineCreateInfo cpci = { |
| 12617 | VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, |
| 12618 | nullptr, 0, { |
| 12619 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 12620 | nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, |
| 12621 | cs.handle(), "main", nullptr |
| 12622 | }, |
| 12623 | descriptorSet.GetPipelineLayout(), |
| 12624 | VK_NULL_HANDLE, -1 |
| 12625 | }; |
| 12626 | |
| 12627 | VkPipeline pipe; |
| 12628 | VkResult err = vkCreateComputePipelines( |
| 12629 | m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe); |
| 12630 | |
| 12631 | m_errorMonitor->VerifyFound(); |
| 12632 | |
| 12633 | if (err == VK_SUCCESS) { |
| 12634 | vkDestroyPipeline(m_device->device(), pipe, nullptr); |
| 12635 | } |
| 12636 | } |
| 12637 | |
| 12638 | TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) { |
| 12639 | m_errorMonitor->ExpectSuccess(); |
| 12640 | |
| 12641 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12642 | |
| 12643 | char const *csSource = |
| 12644 | "#version 450\n" |
| 12645 | "\n" |
| 12646 | "layout(local_size_x=1) in;\n" |
| 12647 | "layout(set=0, binding=0) buffer block { vec4 x; };\n" |
| 12648 | "void main(){\n" |
| 12649 | " // x is not used.\n" |
| 12650 | "}\n"; |
| 12651 | |
| 12652 | VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this); |
| 12653 | |
| 12654 | VkDescriptorSetObj descriptorSet(m_device); |
| 12655 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 12656 | |
| 12657 | VkComputePipelineCreateInfo cpci = { |
| 12658 | VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, |
| 12659 | nullptr, 0, { |
| 12660 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 12661 | nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, |
| 12662 | cs.handle(), "main", nullptr |
| 12663 | }, |
| 12664 | descriptorSet.GetPipelineLayout(), |
| 12665 | VK_NULL_HANDLE, -1 |
| 12666 | }; |
| 12667 | |
| 12668 | VkPipeline pipe; |
| 12669 | VkResult err = vkCreateComputePipelines( |
| 12670 | m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe); |
| 12671 | |
| 12672 | m_errorMonitor->VerifyNotFound(); |
| 12673 | |
| 12674 | if (err == VK_SUCCESS) { |
| 12675 | vkDestroyPipeline(m_device->device(), pipe, nullptr); |
| 12676 | } |
| 12677 | } |
| 12678 | |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 12679 | #endif // SHADER_CHECKER_TESTS |
| 12680 | |
| 12681 | #if DEVICE_LIMITS_TESTS |
Mark Young | c48c4c1 | 2016-04-11 14:26:49 -0600 | [diff] [blame] | 12682 | TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12683 | m_errorMonitor->SetDesiredFailureMsg( |
| 12684 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12685 | "CreateImage extents exceed allowable limits for format"); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 12686 | |
| 12687 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 12688 | |
| 12689 | // Create an image |
| 12690 | VkImage image; |
| 12691 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12692 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12693 | const int32_t tex_width = 32; |
| 12694 | const int32_t tex_height = 32; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 12695 | |
| 12696 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12697 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12698 | image_create_info.pNext = NULL; |
| 12699 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12700 | image_create_info.format = tex_format; |
| 12701 | image_create_info.extent.width = tex_width; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 12702 | image_create_info.extent.height = tex_height; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12703 | image_create_info.extent.depth = 1; |
| 12704 | image_create_info.mipLevels = 1; |
| 12705 | image_create_info.arrayLayers = 1; |
| 12706 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12707 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12708 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 12709 | image_create_info.flags = 0; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 12710 | |
| 12711 | // Introduce error by sending down a bogus width extent |
| 12712 | image_create_info.extent.width = 65536; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12713 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 12714 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12715 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 12716 | } |
| 12717 | |
Mark Young | c48c4c1 | 2016-04-11 14:26:49 -0600 | [diff] [blame] | 12718 | TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) { |
| 12719 | m_errorMonitor->SetDesiredFailureMsg( |
| 12720 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12721 | "CreateImage extents is 0 for at least one required dimension"); |
| 12722 | |
| 12723 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12724 | |
| 12725 | // Create an image |
| 12726 | VkImage image; |
| 12727 | |
| 12728 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12729 | const int32_t tex_width = 32; |
| 12730 | const int32_t tex_height = 32; |
| 12731 | |
| 12732 | VkImageCreateInfo image_create_info = {}; |
| 12733 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12734 | image_create_info.pNext = NULL; |
| 12735 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12736 | image_create_info.format = tex_format; |
| 12737 | image_create_info.extent.width = tex_width; |
| 12738 | image_create_info.extent.height = tex_height; |
| 12739 | image_create_info.extent.depth = 1; |
| 12740 | image_create_info.mipLevels = 1; |
| 12741 | image_create_info.arrayLayers = 1; |
| 12742 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12743 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12744 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 12745 | image_create_info.flags = 0; |
| 12746 | |
| 12747 | // Introduce error by sending down a bogus width extent |
| 12748 | image_create_info.extent.width = 0; |
| 12749 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 12750 | |
| 12751 | m_errorMonitor->VerifyFound(); |
| 12752 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 12753 | #endif // DEVICE_LIMITS_TESTS |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 12754 | |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12755 | #if IMAGE_TESTS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12756 | TEST_F(VkLayerTest, InvalidImageView) { |
| 12757 | VkResult err; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12758 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12759 | m_errorMonitor->SetDesiredFailureMsg( |
| 12760 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12761 | "vkCreateImageView called with baseMipLevel 10 "); |
| 12762 | |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12763 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12764 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12765 | // Create an image and try to create a view with bad baseMipLevel |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12766 | VkImage image; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12767 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12768 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12769 | const int32_t tex_width = 32; |
| 12770 | const int32_t tex_height = 32; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12771 | |
| 12772 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12773 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12774 | image_create_info.pNext = NULL; |
| 12775 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12776 | image_create_info.format = tex_format; |
| 12777 | image_create_info.extent.width = tex_width; |
| 12778 | image_create_info.extent.height = tex_height; |
| 12779 | image_create_info.extent.depth = 1; |
| 12780 | image_create_info.mipLevels = 1; |
| 12781 | image_create_info.arrayLayers = 1; |
| 12782 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12783 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12784 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 12785 | image_create_info.flags = 0; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12786 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12787 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12788 | ASSERT_VK_SUCCESS(err); |
| 12789 | |
| 12790 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12791 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12792 | image_view_create_info.image = image; |
| 12793 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 12794 | image_view_create_info.format = tex_format; |
| 12795 | image_view_create_info.subresourceRange.layerCount = 1; |
| 12796 | image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error |
| 12797 | image_view_create_info.subresourceRange.levelCount = 1; |
| 12798 | image_view_create_info.subresourceRange.aspectMask = |
| 12799 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12800 | |
| 12801 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12802 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 12803 | &view); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12804 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12805 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 12806 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12807 | } |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12808 | |
Mark Young | d339ba3 | 2016-05-30 13:28:35 -0600 | [diff] [blame] | 12809 | TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) { |
| 12810 | VkResult err; |
| 12811 | |
| 12812 | m_errorMonitor->SetDesiredFailureMsg( |
| 12813 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12814 | "vkCreateImageView called with invalid memory "); |
| 12815 | |
| 12816 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12817 | |
| 12818 | // Create an image and try to create a view with no memory backing the image |
| 12819 | VkImage image; |
| 12820 | |
| 12821 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12822 | const int32_t tex_width = 32; |
| 12823 | const int32_t tex_height = 32; |
| 12824 | |
| 12825 | VkImageCreateInfo image_create_info = {}; |
| 12826 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12827 | image_create_info.pNext = NULL; |
| 12828 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12829 | image_create_info.format = tex_format; |
| 12830 | image_create_info.extent.width = tex_width; |
| 12831 | image_create_info.extent.height = tex_height; |
| 12832 | image_create_info.extent.depth = 1; |
| 12833 | image_create_info.mipLevels = 1; |
| 12834 | image_create_info.arrayLayers = 1; |
| 12835 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12836 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12837 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 12838 | image_create_info.flags = 0; |
| 12839 | |
| 12840 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 12841 | ASSERT_VK_SUCCESS(err); |
| 12842 | |
| 12843 | VkImageViewCreateInfo image_view_create_info = {}; |
| 12844 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12845 | image_view_create_info.image = image; |
| 12846 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 12847 | image_view_create_info.format = tex_format; |
| 12848 | image_view_create_info.subresourceRange.layerCount = 1; |
| 12849 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 12850 | image_view_create_info.subresourceRange.levelCount = 1; |
| 12851 | image_view_create_info.subresourceRange.aspectMask = |
| 12852 | VK_IMAGE_ASPECT_COLOR_BIT; |
| 12853 | |
| 12854 | VkImageView view; |
| 12855 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 12856 | &view); |
| 12857 | |
| 12858 | m_errorMonitor->VerifyFound(); |
| 12859 | vkDestroyImage(m_device->device(), image, NULL); |
| 12860 | // If last error is success, it still created the view, so delete it. |
| 12861 | if (err == VK_SUCCESS) { |
| 12862 | vkDestroyImageView(m_device->device(), view, NULL); |
| 12863 | } |
| 12864 | |
| 12865 | } |
| 12866 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12867 | TEST_F(VkLayerTest, InvalidImageViewAspect) { |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 12868 | TEST_DESCRIPTION( |
| 12869 | "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] | 12870 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12871 | "vkCreateImageView: Color image " |
| 12872 | "formats must have ONLY the " |
| 12873 | "VK_IMAGE_ASPECT_COLOR_BIT set"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12874 | |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 12875 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 12876 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12877 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 12878 | VkImageObj image(m_device); |
| 12879 | image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, |
| 12880 | VK_IMAGE_TILING_LINEAR, 0); |
| 12881 | ASSERT_TRUE(image.initialized()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 12882 | |
| 12883 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12884 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 12885 | image_view_create_info.image = image.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12886 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 12887 | image_view_create_info.format = tex_format; |
| 12888 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 12889 | image_view_create_info.subresourceRange.levelCount = 1; |
| 12890 | // Cause an error by setting an invalid image aspect |
| 12891 | image_view_create_info.subresourceRange.aspectMask = |
| 12892 | VK_IMAGE_ASPECT_METADATA_BIT; |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 12893 | |
| 12894 | VkImageView view; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 12895 | vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 12896 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12897 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 12898 | } |
| 12899 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12900 | TEST_F(VkLayerTest, CopyImageLayerCountMismatch) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12901 | VkResult err; |
| 12902 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12903 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12904 | m_errorMonitor->SetDesiredFailureMsg( |
| 12905 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12906 | "vkCmdCopyImage: number of layers in source and destination subresources for pRegions"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12907 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12908 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12909 | |
| 12910 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12911 | VkImage srcImage; |
| 12912 | VkImage dstImage; |
| 12913 | VkDeviceMemory srcMem; |
| 12914 | VkDeviceMemory destMem; |
| 12915 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12916 | |
| 12917 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12918 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12919 | image_create_info.pNext = NULL; |
| 12920 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12921 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12922 | image_create_info.extent.width = 32; |
| 12923 | image_create_info.extent.height = 32; |
| 12924 | image_create_info.extent.depth = 1; |
| 12925 | image_create_info.mipLevels = 1; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12926 | image_create_info.arrayLayers = 4; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12927 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12928 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12929 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 12930 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12931 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12932 | err = |
| 12933 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12934 | ASSERT_VK_SUCCESS(err); |
| 12935 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12936 | err = |
| 12937 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12938 | ASSERT_VK_SUCCESS(err); |
| 12939 | |
| 12940 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12941 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12942 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12943 | memAlloc.pNext = NULL; |
| 12944 | memAlloc.allocationSize = 0; |
| 12945 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12946 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12947 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12948 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12949 | pass = |
| 12950 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12951 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12952 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12953 | ASSERT_VK_SUCCESS(err); |
| 12954 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12955 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12956 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12957 | pass = |
| 12958 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12959 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12960 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12961 | ASSERT_VK_SUCCESS(err); |
| 12962 | |
| 12963 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12964 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12965 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12966 | ASSERT_VK_SUCCESS(err); |
| 12967 | |
| 12968 | BeginCommandBuffer(); |
| 12969 | VkImageCopy copyRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12970 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12971 | copyRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12972 | copyRegion.srcSubresource.baseArrayLayer = 0; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12973 | copyRegion.srcSubresource.layerCount = 1; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12974 | copyRegion.srcOffset.x = 0; |
| 12975 | copyRegion.srcOffset.y = 0; |
| 12976 | copyRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12977 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12978 | copyRegion.dstSubresource.mipLevel = 0; |
| 12979 | copyRegion.dstSubresource.baseArrayLayer = 0; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12980 | // Introduce failure by forcing the dst layerCount to differ from src |
| 12981 | copyRegion.dstSubresource.layerCount = 3; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12982 | copyRegion.dstOffset.x = 0; |
| 12983 | copyRegion.dstOffset.y = 0; |
| 12984 | copyRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12985 | copyRegion.extent.width = 1; |
| 12986 | copyRegion.extent.height = 1; |
| 12987 | copyRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12988 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12989 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12990 | EndCommandBuffer(); |
| 12991 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12992 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12993 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12994 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12995 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12996 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12997 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12998 | } |
| 12999 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 13000 | TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) { |
| 13001 | |
| 13002 | TEST_DESCRIPTION("Creating images with unsuported formats "); |
| 13003 | |
| 13004 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 13005 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 13006 | VkImageObj image(m_device); |
| 13007 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 13008 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 13009 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 13010 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 13011 | ASSERT_TRUE(image.initialized()); |
| 13012 | |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 13013 | // Create image with unsupported format - Expect FORMAT_UNSUPPORTED |
| 13014 | VkImageCreateInfo image_create_info; |
| 13015 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 13016 | image_create_info.pNext = NULL; |
| 13017 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 13018 | image_create_info.format = VK_FORMAT_UNDEFINED; |
| 13019 | image_create_info.extent.width = 32; |
| 13020 | image_create_info.extent.height = 32; |
| 13021 | image_create_info.extent.depth = 1; |
| 13022 | image_create_info.mipLevels = 1; |
| 13023 | image_create_info.arrayLayers = 1; |
| 13024 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 13025 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 13026 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 13027 | image_create_info.flags = 0; |
| 13028 | |
| 13029 | m_errorMonitor->SetDesiredFailureMsg( |
| 13030 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13031 | "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED"); |
| 13032 | |
| 13033 | VkImage localImage; |
| 13034 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage); |
| 13035 | m_errorMonitor->VerifyFound(); |
| 13036 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 13037 | VkFormat unsupported = VK_FORMAT_UNDEFINED; |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 13038 | // Look for a format that is COMPLETELY unsupported with this hardware |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 13039 | for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) { |
| 13040 | VkFormat format = static_cast<VkFormat>(f); |
| 13041 | VkFormatProperties fProps = m_device->format_properties(format); |
| 13042 | if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && |
| 13043 | fProps.optimalTilingFeatures == 0) { |
| 13044 | unsupported = format; |
| 13045 | break; |
| 13046 | } |
| 13047 | } |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 13048 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 13049 | if (unsupported != VK_FORMAT_UNDEFINED) { |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 13050 | image_create_info.format = unsupported; |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 13051 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 13052 | "is an unsupported format"); |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 13053 | |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 13054 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage); |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 13055 | m_errorMonitor->VerifyFound(); |
| 13056 | } |
| 13057 | } |
| 13058 | |
| 13059 | TEST_F(VkLayerTest, ImageLayerViewTests) { |
| 13060 | VkResult ret; |
| 13061 | TEST_DESCRIPTION("Passing bad parameters to CreateImageView"); |
| 13062 | |
| 13063 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 13064 | |
| 13065 | VkImageObj image(m_device); |
| 13066 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 13067 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 13068 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 13069 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 13070 | ASSERT_TRUE(image.initialized()); |
| 13071 | |
| 13072 | VkImageView imgView; |
| 13073 | VkImageViewCreateInfo imgViewInfo = {}; |
| 13074 | imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 13075 | imgViewInfo.image = image.handle(); |
| 13076 | imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 13077 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 13078 | imgViewInfo.subresourceRange.layerCount = 1; |
| 13079 | imgViewInfo.subresourceRange.baseMipLevel = 0; |
| 13080 | imgViewInfo.subresourceRange.levelCount = 1; |
| 13081 | imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 13082 | |
| 13083 | m_errorMonitor->SetDesiredFailureMsg( |
| 13084 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13085 | "vkCreateImageView called with baseMipLevel"); |
| 13086 | // View can't have baseMipLevel >= image's mipLevels - Expect |
| 13087 | // VIEW_CREATE_ERROR |
| 13088 | imgViewInfo.subresourceRange.baseMipLevel = 1; |
| 13089 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 13090 | m_errorMonitor->VerifyFound(); |
| 13091 | imgViewInfo.subresourceRange.baseMipLevel = 0; |
| 13092 | |
| 13093 | m_errorMonitor->SetDesiredFailureMsg( |
| 13094 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13095 | "vkCreateImageView called with baseArrayLayer"); |
| 13096 | // View can't have baseArrayLayer >= image's arraySize - Expect |
| 13097 | // VIEW_CREATE_ERROR |
| 13098 | imgViewInfo.subresourceRange.baseArrayLayer = 1; |
| 13099 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 13100 | m_errorMonitor->VerifyFound(); |
| 13101 | imgViewInfo.subresourceRange.baseArrayLayer = 0; |
| 13102 | |
| 13103 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13104 | "vkCreateImageView called with 0 in " |
| 13105 | "pCreateInfo->subresourceRange." |
| 13106 | "levelCount"); |
| 13107 | // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR |
| 13108 | imgViewInfo.subresourceRange.levelCount = 0; |
| 13109 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 13110 | m_errorMonitor->VerifyFound(); |
| 13111 | imgViewInfo.subresourceRange.levelCount = 1; |
| 13112 | |
| 13113 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13114 | "vkCreateImageView called with 0 in " |
| 13115 | "pCreateInfo->subresourceRange." |
| 13116 | "layerCount"); |
| 13117 | // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR |
| 13118 | imgViewInfo.subresourceRange.layerCount = 0; |
| 13119 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 13120 | m_errorMonitor->VerifyFound(); |
| 13121 | imgViewInfo.subresourceRange.layerCount = 1; |
| 13122 | |
| 13123 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13124 | "but both must be color formats"); |
| 13125 | // Can't use depth format for view into color image - Expect INVALID_FORMAT |
| 13126 | imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 13127 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 13128 | m_errorMonitor->VerifyFound(); |
| 13129 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 13130 | |
| 13131 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13132 | "Formats MUST be IDENTICAL unless " |
| 13133 | "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT " |
| 13134 | "was set on image creation."); |
| 13135 | // Same compatibility class but no MUTABLE_FORMAT bit - Expect |
| 13136 | // VIEW_CREATE_ERROR |
| 13137 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT; |
| 13138 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 13139 | m_errorMonitor->VerifyFound(); |
| 13140 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 13141 | |
| 13142 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13143 | "can support ImageViews with " |
| 13144 | "differing formats but they must be " |
| 13145 | "in the same compatibility class."); |
| 13146 | // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect |
| 13147 | // VIEW_CREATE_ERROR |
| 13148 | VkImageCreateInfo mutImgInfo = image.create_info(); |
| 13149 | VkImage mutImage; |
| 13150 | mutImgInfo.format = VK_FORMAT_R8_UINT; |
| 13151 | assert( |
| 13152 | m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & |
| 13153 | VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT); |
| 13154 | mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; |
| 13155 | mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 13156 | ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage); |
| 13157 | ASSERT_VK_SUCCESS(ret); |
| 13158 | imgViewInfo.image = mutImage; |
| 13159 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 13160 | m_errorMonitor->VerifyFound(); |
| 13161 | imgViewInfo.image = image.handle(); |
| 13162 | vkDestroyImage(m_device->handle(), mutImage, NULL); |
| 13163 | } |
| 13164 | |
| 13165 | TEST_F(VkLayerTest, MiscImageLayerTests) { |
| 13166 | |
| 13167 | TEST_DESCRIPTION("Image layer tests that don't belong elsewhare"); |
| 13168 | |
| 13169 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 13170 | |
| 13171 | VkImageObj image(m_device); |
| 13172 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 13173 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 13174 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 13175 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 13176 | ASSERT_TRUE(image.initialized()); |
| 13177 | |
| 13178 | m_errorMonitor->SetDesiredFailureMsg( |
| 13179 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13180 | "number of layers in image subresource is zero"); |
| 13181 | vk_testing::Buffer buffer; |
| 13182 | VkMemoryPropertyFlags reqs = 0; |
| 13183 | buffer.init_as_src(*m_device, 128 * 128 * 4, reqs); |
| 13184 | VkBufferImageCopy region = {}; |
| 13185 | region.bufferRowLength = 128; |
| 13186 | region.bufferImageHeight = 128; |
| 13187 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 13188 | // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT |
| 13189 | region.imageSubresource.layerCount = 0; |
| 13190 | region.imageExtent.height = 4; |
| 13191 | region.imageExtent.width = 4; |
| 13192 | region.imageExtent.depth = 1; |
| 13193 | m_commandBuffer->BeginCommandBuffer(); |
| 13194 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 13195 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 13196 | 1, ®ion); |
| 13197 | m_errorMonitor->VerifyFound(); |
| 13198 | region.imageSubresource.layerCount = 1; |
| 13199 | |
| 13200 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13201 | "aspectMasks for each region must " |
| 13202 | "specify only COLOR or DEPTH or " |
| 13203 | "STENCIL"); |
| 13204 | // Expect MISMATCHED_IMAGE_ASPECT |
| 13205 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT; |
| 13206 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 13207 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 13208 | 1, ®ion); |
| 13209 | m_errorMonitor->VerifyFound(); |
| 13210 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 13211 | |
| 13212 | m_errorMonitor->SetDesiredFailureMsg( |
| 13213 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13214 | "If the format of srcImage is a depth, stencil, depth stencil or " |
| 13215 | "integer-based format then filter must be VK_FILTER_NEAREST"); |
| 13216 | // Expect INVALID_FILTER |
| 13217 | VkImageObj intImage1(m_device); |
| 13218 | intImage1.init(128, 128, VK_FORMAT_R8_UINT, |
| 13219 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, |
| 13220 | 0); |
| 13221 | VkImageObj intImage2(m_device); |
| 13222 | intImage2.init(128, 128, VK_FORMAT_R8_UINT, |
| 13223 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, |
| 13224 | 0); |
| 13225 | VkImageBlit blitRegion = {}; |
| 13226 | blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 13227 | blitRegion.srcSubresource.baseArrayLayer = 0; |
| 13228 | blitRegion.srcSubresource.layerCount = 1; |
| 13229 | blitRegion.srcSubresource.mipLevel = 0; |
| 13230 | blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 13231 | blitRegion.dstSubresource.baseArrayLayer = 0; |
| 13232 | blitRegion.dstSubresource.layerCount = 1; |
| 13233 | blitRegion.dstSubresource.mipLevel = 0; |
| 13234 | |
| 13235 | vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), |
| 13236 | intImage1.layout(), intImage2.handle(), intImage2.layout(), |
| 13237 | 16, &blitRegion, VK_FILTER_LINEAR); |
| 13238 | m_errorMonitor->VerifyFound(); |
| 13239 | |
| 13240 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13241 | "called with 0 in ppMemoryBarriers"); |
| 13242 | VkImageMemoryBarrier img_barrier; |
| 13243 | img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 13244 | img_barrier.pNext = NULL; |
| 13245 | img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 13246 | img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 13247 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 13248 | img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 13249 | img_barrier.image = image.handle(); |
| 13250 | img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 13251 | img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 13252 | img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 13253 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 13254 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 13255 | // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE |
| 13256 | img_barrier.subresourceRange.layerCount = 0; |
| 13257 | img_barrier.subresourceRange.levelCount = 1; |
| 13258 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 13259 | VK_PIPELINE_STAGE_HOST_BIT, |
| 13260 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 13261 | nullptr, 1, &img_barrier); |
| 13262 | m_errorMonitor->VerifyFound(); |
| 13263 | img_barrier.subresourceRange.layerCount = 1; |
| 13264 | } |
| 13265 | |
| 13266 | TEST_F(VkLayerTest, ImageFormatLimits) { |
| 13267 | |
| 13268 | TEST_DESCRIPTION("Exceed the limits of image format "); |
| 13269 | |
| 13270 | m_errorMonitor->SetDesiredFailureMsg( |
| 13271 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13272 | "CreateImage extents exceed allowable limits for format"); |
| 13273 | VkImageCreateInfo image_create_info = {}; |
| 13274 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 13275 | image_create_info.pNext = NULL; |
| 13276 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 13277 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 13278 | image_create_info.extent.width = 32; |
| 13279 | image_create_info.extent.height = 32; |
| 13280 | image_create_info.extent.depth = 1; |
| 13281 | image_create_info.mipLevels = 1; |
| 13282 | image_create_info.arrayLayers = 1; |
| 13283 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 13284 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 13285 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 13286 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 13287 | image_create_info.flags = 0; |
| 13288 | |
| 13289 | VkImage nullImg; |
| 13290 | VkImageFormatProperties imgFmtProps; |
| 13291 | vkGetPhysicalDeviceImageFormatProperties( |
| 13292 | gpu(), image_create_info.format, image_create_info.imageType, |
| 13293 | image_create_info.tiling, image_create_info.usage, |
| 13294 | image_create_info.flags, &imgFmtProps); |
| 13295 | image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1; |
| 13296 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 13297 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 13298 | m_errorMonitor->VerifyFound(); |
| 13299 | image_create_info.extent.depth = 1; |
| 13300 | |
| 13301 | m_errorMonitor->SetDesiredFailureMsg( |
| 13302 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13303 | "exceeds allowable maximum supported by format of"); |
| 13304 | image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1; |
| 13305 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 13306 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 13307 | m_errorMonitor->VerifyFound(); |
| 13308 | image_create_info.mipLevels = 1; |
| 13309 | |
| 13310 | m_errorMonitor->SetDesiredFailureMsg( |
| 13311 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13312 | "exceeds allowable maximum supported by format of"); |
| 13313 | image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1; |
| 13314 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 13315 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 13316 | m_errorMonitor->VerifyFound(); |
| 13317 | image_create_info.arrayLayers = 1; |
| 13318 | |
| 13319 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13320 | "is not supported by format"); |
| 13321 | int samples = imgFmtProps.sampleCounts >> 1; |
| 13322 | image_create_info.samples = (VkSampleCountFlagBits)samples; |
| 13323 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 13324 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 13325 | m_errorMonitor->VerifyFound(); |
| 13326 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 13327 | |
| 13328 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13329 | "pCreateInfo->initialLayout, must be " |
| 13330 | "VK_IMAGE_LAYOUT_UNDEFINED or " |
| 13331 | "VK_IMAGE_LAYOUT_PREINITIALIZED"); |
| 13332 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 13333 | // Expect INVALID_LAYOUT |
| 13334 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 13335 | m_errorMonitor->VerifyFound(); |
| 13336 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 13337 | } |
| 13338 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13339 | TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 13340 | VkResult err; |
| 13341 | bool pass; |
| 13342 | |
| 13343 | // Create color images with different format sizes and try to copy between them |
| 13344 | m_errorMonitor->SetDesiredFailureMsg( |
| 13345 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13346 | "vkCmdCopyImage called with unmatched source and dest image format sizes"); |
| 13347 | |
| 13348 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 13349 | |
| 13350 | // Create two images of different types and try to copy between them |
| 13351 | VkImage srcImage; |
| 13352 | VkImage dstImage; |
| 13353 | VkDeviceMemory srcMem; |
| 13354 | VkDeviceMemory destMem; |
| 13355 | VkMemoryRequirements memReqs; |
| 13356 | |
| 13357 | VkImageCreateInfo image_create_info = {}; |
| 13358 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 13359 | image_create_info.pNext = NULL; |
| 13360 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 13361 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 13362 | image_create_info.extent.width = 32; |
| 13363 | image_create_info.extent.height = 32; |
| 13364 | image_create_info.extent.depth = 1; |
| 13365 | image_create_info.mipLevels = 1; |
| 13366 | image_create_info.arrayLayers = 1; |
| 13367 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 13368 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 13369 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 13370 | image_create_info.flags = 0; |
| 13371 | |
| 13372 | err = |
| 13373 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
| 13374 | ASSERT_VK_SUCCESS(err); |
| 13375 | |
| 13376 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 13377 | // Introduce failure by creating second image with a different-sized format. |
| 13378 | image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16; |
| 13379 | |
| 13380 | err = |
| 13381 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
| 13382 | ASSERT_VK_SUCCESS(err); |
| 13383 | |
| 13384 | // Allocate memory |
| 13385 | VkMemoryAllocateInfo memAlloc = {}; |
| 13386 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 13387 | memAlloc.pNext = NULL; |
| 13388 | memAlloc.allocationSize = 0; |
| 13389 | memAlloc.memoryTypeIndex = 0; |
| 13390 | |
| 13391 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
| 13392 | memAlloc.allocationSize = memReqs.size; |
| 13393 | pass = |
| 13394 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
| 13395 | ASSERT_TRUE(pass); |
| 13396 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
| 13397 | ASSERT_VK_SUCCESS(err); |
| 13398 | |
| 13399 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
| 13400 | memAlloc.allocationSize = memReqs.size; |
| 13401 | pass = |
| 13402 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
| 13403 | ASSERT_TRUE(pass); |
| 13404 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
| 13405 | ASSERT_VK_SUCCESS(err); |
| 13406 | |
| 13407 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 13408 | ASSERT_VK_SUCCESS(err); |
| 13409 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
| 13410 | ASSERT_VK_SUCCESS(err); |
| 13411 | |
| 13412 | BeginCommandBuffer(); |
| 13413 | VkImageCopy copyRegion; |
| 13414 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 13415 | copyRegion.srcSubresource.mipLevel = 0; |
| 13416 | copyRegion.srcSubresource.baseArrayLayer = 0; |
| 13417 | copyRegion.srcSubresource.layerCount = 0; |
| 13418 | copyRegion.srcOffset.x = 0; |
| 13419 | copyRegion.srcOffset.y = 0; |
| 13420 | copyRegion.srcOffset.z = 0; |
| 13421 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 13422 | copyRegion.dstSubresource.mipLevel = 0; |
| 13423 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 13424 | copyRegion.dstSubresource.layerCount = 0; |
| 13425 | copyRegion.dstOffset.x = 0; |
| 13426 | copyRegion.dstOffset.y = 0; |
| 13427 | copyRegion.dstOffset.z = 0; |
| 13428 | copyRegion.extent.width = 1; |
| 13429 | copyRegion.extent.height = 1; |
| 13430 | copyRegion.extent.depth = 1; |
| 13431 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 13432 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 13433 | EndCommandBuffer(); |
| 13434 | |
| 13435 | m_errorMonitor->VerifyFound(); |
| 13436 | |
| 13437 | vkDestroyImage(m_device->device(), srcImage, NULL); |
| 13438 | vkDestroyImage(m_device->device(), dstImage, NULL); |
| 13439 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 13440 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13441 | } |
| 13442 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13443 | TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) { |
| 13444 | VkResult err; |
| 13445 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13446 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 13447 | // 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] | 13448 | m_errorMonitor->SetDesiredFailureMsg( |
| 13449 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 13450 | "vkCmdCopyImage called with unmatched source and dest image depth"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 13451 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13452 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13453 | |
| 13454 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13455 | VkImage srcImage; |
| 13456 | VkImage dstImage; |
| 13457 | VkDeviceMemory srcMem; |
| 13458 | VkDeviceMemory destMem; |
| 13459 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13460 | |
| 13461 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13462 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 13463 | image_create_info.pNext = NULL; |
| 13464 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 13465 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 13466 | image_create_info.extent.width = 32; |
| 13467 | image_create_info.extent.height = 32; |
| 13468 | image_create_info.extent.depth = 1; |
| 13469 | image_create_info.mipLevels = 1; |
| 13470 | image_create_info.arrayLayers = 1; |
| 13471 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 13472 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 13473 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 13474 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13475 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13476 | err = |
| 13477 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13478 | ASSERT_VK_SUCCESS(err); |
| 13479 | |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 13480 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 13481 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 13482 | // Introduce failure by creating second image with a depth/stencil format |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13483 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 13484 | image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 13485 | image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13486 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13487 | err = |
| 13488 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13489 | ASSERT_VK_SUCCESS(err); |
| 13490 | |
| 13491 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13492 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13493 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 13494 | memAlloc.pNext = NULL; |
| 13495 | memAlloc.allocationSize = 0; |
| 13496 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13497 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 13498 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13499 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13500 | pass = |
| 13501 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13502 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13503 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13504 | ASSERT_VK_SUCCESS(err); |
| 13505 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13506 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13507 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13508 | pass = |
| 13509 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13510 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13511 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13512 | ASSERT_VK_SUCCESS(err); |
| 13513 | |
| 13514 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 13515 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13516 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13517 | ASSERT_VK_SUCCESS(err); |
| 13518 | |
| 13519 | BeginCommandBuffer(); |
| 13520 | VkImageCopy copyRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13521 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13522 | copyRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 13523 | copyRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13524 | copyRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13525 | copyRegion.srcOffset.x = 0; |
| 13526 | copyRegion.srcOffset.y = 0; |
| 13527 | copyRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13528 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13529 | copyRegion.dstSubresource.mipLevel = 0; |
| 13530 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 13531 | copyRegion.dstSubresource.layerCount = 0; |
| 13532 | copyRegion.dstOffset.x = 0; |
| 13533 | copyRegion.dstOffset.y = 0; |
| 13534 | copyRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13535 | copyRegion.extent.width = 1; |
| 13536 | copyRegion.extent.height = 1; |
| 13537 | copyRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13538 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 13539 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13540 | EndCommandBuffer(); |
| 13541 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 13542 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13543 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13544 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13545 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13546 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 13547 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13548 | } |
| 13549 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13550 | TEST_F(VkLayerTest, ResolveImageLowSampleCount) { |
| 13551 | VkResult err; |
| 13552 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13553 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13554 | m_errorMonitor->SetDesiredFailureMsg( |
| 13555 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 13556 | "vkCmdResolveImage called with source sample count less than 2."); |
| 13557 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13558 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13559 | |
| 13560 | // 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] | 13561 | VkImage srcImage; |
| 13562 | VkImage dstImage; |
| 13563 | VkDeviceMemory srcMem; |
| 13564 | VkDeviceMemory destMem; |
| 13565 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13566 | |
| 13567 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13568 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 13569 | image_create_info.pNext = NULL; |
| 13570 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 13571 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 13572 | image_create_info.extent.width = 32; |
| 13573 | image_create_info.extent.height = 1; |
| 13574 | image_create_info.extent.depth = 1; |
| 13575 | image_create_info.mipLevels = 1; |
| 13576 | image_create_info.arrayLayers = 1; |
| 13577 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 13578 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 13579 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 13580 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13581 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13582 | err = |
| 13583 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13584 | ASSERT_VK_SUCCESS(err); |
| 13585 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13586 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13587 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13588 | err = |
| 13589 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13590 | ASSERT_VK_SUCCESS(err); |
| 13591 | |
| 13592 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13593 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13594 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 13595 | memAlloc.pNext = NULL; |
| 13596 | memAlloc.allocationSize = 0; |
| 13597 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13598 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 13599 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13600 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13601 | pass = |
| 13602 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13603 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13604 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13605 | ASSERT_VK_SUCCESS(err); |
| 13606 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13607 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13608 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13609 | pass = |
| 13610 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13611 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13612 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13613 | ASSERT_VK_SUCCESS(err); |
| 13614 | |
| 13615 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 13616 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13617 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13618 | ASSERT_VK_SUCCESS(err); |
| 13619 | |
| 13620 | BeginCommandBuffer(); |
| 13621 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13622 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 13623 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13624 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13625 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13626 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 13627 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13628 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13629 | resolveRegion.srcOffset.x = 0; |
| 13630 | resolveRegion.srcOffset.y = 0; |
| 13631 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13632 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13633 | resolveRegion.dstSubresource.mipLevel = 0; |
| 13634 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 13635 | resolveRegion.dstSubresource.layerCount = 0; |
| 13636 | resolveRegion.dstOffset.x = 0; |
| 13637 | resolveRegion.dstOffset.y = 0; |
| 13638 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13639 | resolveRegion.extent.width = 1; |
| 13640 | resolveRegion.extent.height = 1; |
| 13641 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13642 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 13643 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13644 | EndCommandBuffer(); |
| 13645 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 13646 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13647 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13648 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13649 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13650 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 13651 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13652 | } |
| 13653 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13654 | TEST_F(VkLayerTest, ResolveImageHighSampleCount) { |
| 13655 | VkResult err; |
| 13656 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13657 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13658 | m_errorMonitor->SetDesiredFailureMsg( |
| 13659 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 13660 | "vkCmdResolveImage called with dest sample count greater than 1."); |
| 13661 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13662 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13663 | |
Chris Forbes | a753069 | 2016-05-08 12:35:39 +1200 | [diff] [blame] | 13664 | // 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] | 13665 | VkImage srcImage; |
| 13666 | VkImage dstImage; |
| 13667 | VkDeviceMemory srcMem; |
| 13668 | VkDeviceMemory destMem; |
| 13669 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13670 | |
| 13671 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13672 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 13673 | image_create_info.pNext = NULL; |
| 13674 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 13675 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 13676 | image_create_info.extent.width = 32; |
| 13677 | image_create_info.extent.height = 1; |
| 13678 | image_create_info.extent.depth = 1; |
| 13679 | image_create_info.mipLevels = 1; |
| 13680 | image_create_info.arrayLayers = 1; |
Chris Forbes | a753069 | 2016-05-08 12:35:39 +1200 | [diff] [blame] | 13681 | image_create_info.samples = VK_SAMPLE_COUNT_4_BIT; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13682 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 13683 | // Note: Some implementations expect color attachment usage for any |
| 13684 | // multisample surface |
| 13685 | image_create_info.usage = |
| 13686 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 13687 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13688 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13689 | err = |
| 13690 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13691 | ASSERT_VK_SUCCESS(err); |
| 13692 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13693 | // Note: Some implementations expect color attachment usage for any |
| 13694 | // multisample surface |
| 13695 | image_create_info.usage = |
| 13696 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13697 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13698 | err = |
| 13699 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13700 | ASSERT_VK_SUCCESS(err); |
| 13701 | |
| 13702 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13703 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13704 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 13705 | memAlloc.pNext = NULL; |
| 13706 | memAlloc.allocationSize = 0; |
| 13707 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13708 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 13709 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13710 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13711 | pass = |
| 13712 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13713 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13714 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13715 | ASSERT_VK_SUCCESS(err); |
| 13716 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13717 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13718 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13719 | pass = |
| 13720 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13721 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13722 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13723 | ASSERT_VK_SUCCESS(err); |
| 13724 | |
| 13725 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 13726 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13727 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13728 | ASSERT_VK_SUCCESS(err); |
| 13729 | |
| 13730 | BeginCommandBuffer(); |
| 13731 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13732 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 13733 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13734 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13735 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13736 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 13737 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13738 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13739 | resolveRegion.srcOffset.x = 0; |
| 13740 | resolveRegion.srcOffset.y = 0; |
| 13741 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13742 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13743 | resolveRegion.dstSubresource.mipLevel = 0; |
| 13744 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 13745 | resolveRegion.dstSubresource.layerCount = 0; |
| 13746 | resolveRegion.dstOffset.x = 0; |
| 13747 | resolveRegion.dstOffset.y = 0; |
| 13748 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13749 | resolveRegion.extent.width = 1; |
| 13750 | resolveRegion.extent.height = 1; |
| 13751 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13752 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 13753 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13754 | EndCommandBuffer(); |
| 13755 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 13756 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13757 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13758 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13759 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13760 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 13761 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13762 | } |
| 13763 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13764 | TEST_F(VkLayerTest, ResolveImageFormatMismatch) { |
| 13765 | VkResult err; |
| 13766 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13767 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13768 | m_errorMonitor->SetDesiredFailureMsg( |
| 13769 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 13770 | "vkCmdResolveImage called with unmatched source and dest formats."); |
| 13771 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13772 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13773 | |
| 13774 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13775 | VkImage srcImage; |
| 13776 | VkImage dstImage; |
| 13777 | VkDeviceMemory srcMem; |
| 13778 | VkDeviceMemory destMem; |
| 13779 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13780 | |
| 13781 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13782 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 13783 | image_create_info.pNext = NULL; |
| 13784 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 13785 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 13786 | image_create_info.extent.width = 32; |
| 13787 | image_create_info.extent.height = 1; |
| 13788 | image_create_info.extent.depth = 1; |
| 13789 | image_create_info.mipLevels = 1; |
| 13790 | image_create_info.arrayLayers = 1; |
| 13791 | image_create_info.samples = VK_SAMPLE_COUNT_2_BIT; |
| 13792 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 13793 | // Note: Some implementations expect color attachment usage for any |
| 13794 | // multisample surface |
| 13795 | image_create_info.usage = |
| 13796 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 13797 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13798 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13799 | err = |
| 13800 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13801 | ASSERT_VK_SUCCESS(err); |
| 13802 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13803 | // Set format to something other than source image |
| 13804 | image_create_info.format = VK_FORMAT_R32_SFLOAT; |
| 13805 | // Note: Some implementations expect color attachment usage for any |
| 13806 | // multisample surface |
| 13807 | image_create_info.usage = |
| 13808 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 13809 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13810 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13811 | err = |
| 13812 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13813 | ASSERT_VK_SUCCESS(err); |
| 13814 | |
| 13815 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13816 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13817 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 13818 | memAlloc.pNext = NULL; |
| 13819 | memAlloc.allocationSize = 0; |
| 13820 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13821 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 13822 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13823 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13824 | pass = |
| 13825 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13826 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13827 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13828 | ASSERT_VK_SUCCESS(err); |
| 13829 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13830 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13831 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13832 | pass = |
| 13833 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13834 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13835 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13836 | ASSERT_VK_SUCCESS(err); |
| 13837 | |
| 13838 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 13839 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13840 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13841 | ASSERT_VK_SUCCESS(err); |
| 13842 | |
| 13843 | BeginCommandBuffer(); |
| 13844 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13845 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 13846 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13847 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13848 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13849 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 13850 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13851 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13852 | resolveRegion.srcOffset.x = 0; |
| 13853 | resolveRegion.srcOffset.y = 0; |
| 13854 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13855 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13856 | resolveRegion.dstSubresource.mipLevel = 0; |
| 13857 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 13858 | resolveRegion.dstSubresource.layerCount = 0; |
| 13859 | resolveRegion.dstOffset.x = 0; |
| 13860 | resolveRegion.dstOffset.y = 0; |
| 13861 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13862 | resolveRegion.extent.width = 1; |
| 13863 | resolveRegion.extent.height = 1; |
| 13864 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13865 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 13866 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13867 | EndCommandBuffer(); |
| 13868 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 13869 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13870 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13871 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13872 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13873 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 13874 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13875 | } |
| 13876 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13877 | TEST_F(VkLayerTest, ResolveImageTypeMismatch) { |
| 13878 | VkResult err; |
| 13879 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13880 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13881 | m_errorMonitor->SetDesiredFailureMsg( |
| 13882 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 13883 | "vkCmdResolveImage called with unmatched source and dest image types."); |
| 13884 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13885 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13886 | |
| 13887 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13888 | VkImage srcImage; |
| 13889 | VkImage dstImage; |
| 13890 | VkDeviceMemory srcMem; |
| 13891 | VkDeviceMemory destMem; |
| 13892 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13893 | |
| 13894 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13895 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 13896 | image_create_info.pNext = NULL; |
| 13897 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 13898 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 13899 | image_create_info.extent.width = 32; |
| 13900 | image_create_info.extent.height = 1; |
| 13901 | image_create_info.extent.depth = 1; |
| 13902 | image_create_info.mipLevels = 1; |
| 13903 | image_create_info.arrayLayers = 1; |
| 13904 | image_create_info.samples = VK_SAMPLE_COUNT_2_BIT; |
| 13905 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 13906 | // Note: Some implementations expect color attachment usage for any |
| 13907 | // multisample surface |
| 13908 | image_create_info.usage = |
| 13909 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 13910 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13911 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13912 | err = |
| 13913 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13914 | ASSERT_VK_SUCCESS(err); |
| 13915 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13916 | image_create_info.imageType = VK_IMAGE_TYPE_1D; |
| 13917 | // Note: Some implementations expect color attachment usage for any |
| 13918 | // multisample surface |
| 13919 | image_create_info.usage = |
| 13920 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 13921 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13922 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13923 | err = |
| 13924 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13925 | ASSERT_VK_SUCCESS(err); |
| 13926 | |
| 13927 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13928 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13929 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 13930 | memAlloc.pNext = NULL; |
| 13931 | memAlloc.allocationSize = 0; |
| 13932 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13933 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 13934 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13935 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13936 | pass = |
| 13937 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13938 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13939 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13940 | ASSERT_VK_SUCCESS(err); |
| 13941 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13942 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13943 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13944 | pass = |
| 13945 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 13946 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13947 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13948 | ASSERT_VK_SUCCESS(err); |
| 13949 | |
| 13950 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 13951 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13952 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13953 | ASSERT_VK_SUCCESS(err); |
| 13954 | |
| 13955 | BeginCommandBuffer(); |
| 13956 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13957 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 13958 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13959 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13960 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13961 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 13962 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13963 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13964 | resolveRegion.srcOffset.x = 0; |
| 13965 | resolveRegion.srcOffset.y = 0; |
| 13966 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 13967 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13968 | resolveRegion.dstSubresource.mipLevel = 0; |
| 13969 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 13970 | resolveRegion.dstSubresource.layerCount = 0; |
| 13971 | resolveRegion.dstOffset.x = 0; |
| 13972 | resolveRegion.dstOffset.y = 0; |
| 13973 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13974 | resolveRegion.extent.width = 1; |
| 13975 | resolveRegion.extent.height = 1; |
| 13976 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13977 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 13978 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13979 | EndCommandBuffer(); |
| 13980 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 13981 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13982 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13983 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 13984 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13985 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 13986 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 13987 | } |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13988 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13989 | TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) { |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13990 | // 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] | 13991 | // to using a DS format, then cause it to hit error due to COLOR_BIT not |
| 13992 | // set in aspect |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13993 | // The image format check comes 2nd in validation so we trigger it first, |
| 13994 | // 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] | 13995 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13996 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13997 | m_errorMonitor->SetDesiredFailureMsg( |
| 13998 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 13999 | "Combination depth/stencil image formats can have only the "); |
| 14000 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14001 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 14002 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 14003 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14004 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 14005 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14006 | |
| 14007 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14008 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 14009 | ds_pool_ci.pNext = NULL; |
| 14010 | ds_pool_ci.maxSets = 1; |
| 14011 | ds_pool_ci.poolSizeCount = 1; |
| 14012 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14013 | |
| 14014 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14015 | err = |
| 14016 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14017 | ASSERT_VK_SUCCESS(err); |
| 14018 | |
| 14019 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14020 | dsl_binding.binding = 0; |
| 14021 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 14022 | dsl_binding.descriptorCount = 1; |
| 14023 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 14024 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14025 | |
| 14026 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14027 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 14028 | ds_layout_ci.pNext = NULL; |
| 14029 | ds_layout_ci.bindingCount = 1; |
| 14030 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14031 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14032 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 14033 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14034 | ASSERT_VK_SUCCESS(err); |
| 14035 | |
| 14036 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 14037 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 14038 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 14039 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14040 | alloc_info.descriptorPool = ds_pool; |
| 14041 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14042 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 14043 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14044 | ASSERT_VK_SUCCESS(err); |
| 14045 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14046 | VkImage image_bad; |
| 14047 | VkImage image_good; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14048 | // One bad format and one good format for Color attachment |
Tobin Ehlis | 269f032 | 2016-05-25 16:24:21 -0600 | [diff] [blame] | 14049 | const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14050 | const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14051 | const int32_t tex_width = 32; |
| 14052 | const int32_t tex_height = 32; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14053 | |
| 14054 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14055 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 14056 | image_create_info.pNext = NULL; |
| 14057 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 14058 | image_create_info.format = tex_format_bad; |
| 14059 | image_create_info.extent.width = tex_width; |
| 14060 | image_create_info.extent.height = tex_height; |
| 14061 | image_create_info.extent.depth = 1; |
| 14062 | image_create_info.mipLevels = 1; |
| 14063 | image_create_info.arrayLayers = 1; |
| 14064 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 14065 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 14066 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | |
| 14067 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 14068 | image_create_info.flags = 0; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14069 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14070 | err = |
| 14071 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14072 | ASSERT_VK_SUCCESS(err); |
| 14073 | image_create_info.format = tex_format_good; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14074 | image_create_info.usage = |
| 14075 | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 14076 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, |
| 14077 | &image_good); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14078 | ASSERT_VK_SUCCESS(err); |
| 14079 | |
| 14080 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14081 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 14082 | image_view_create_info.image = image_bad; |
| 14083 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 14084 | image_view_create_info.format = tex_format_bad; |
| 14085 | image_view_create_info.subresourceRange.baseArrayLayer = 0; |
| 14086 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 14087 | image_view_create_info.subresourceRange.layerCount = 1; |
| 14088 | image_view_create_info.subresourceRange.levelCount = 1; |
| 14089 | image_view_create_info.subresourceRange.aspectMask = |
| 14090 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14091 | |
| 14092 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 14093 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 14094 | &view); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 14095 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 14096 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14097 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 14098 | vkDestroyImage(m_device->device(), image_bad, NULL); |
| 14099 | vkDestroyImage(m_device->device(), image_good, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 14100 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 14101 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 14102 | } |
Tobin Ehlis | 6e23d77 | 2016-05-19 11:08:34 -0600 | [diff] [blame] | 14103 | |
| 14104 | TEST_F(VkLayerTest, ClearImageErrors) { |
| 14105 | TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and " |
| 14106 | "ClearDepthStencilImage with a color image."); |
| 14107 | |
| 14108 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 14109 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 14110 | |
| 14111 | // Renderpass is started here so end it as Clear cmds can't be in renderpass |
| 14112 | BeginCommandBuffer(); |
| 14113 | m_commandBuffer->EndRenderPass(); |
| 14114 | |
| 14115 | // Color image |
| 14116 | VkClearColorValue clear_color; |
| 14117 | memset(clear_color.uint32, 0, sizeof(uint32_t) * 4); |
| 14118 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 14119 | const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 14120 | const int32_t img_width = 32; |
| 14121 | const int32_t img_height = 32; |
| 14122 | VkImageCreateInfo image_create_info = {}; |
| 14123 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 14124 | image_create_info.pNext = NULL; |
| 14125 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 14126 | image_create_info.format = color_format; |
| 14127 | image_create_info.extent.width = img_width; |
| 14128 | image_create_info.extent.height = img_height; |
| 14129 | image_create_info.extent.depth = 1; |
| 14130 | image_create_info.mipLevels = 1; |
| 14131 | image_create_info.arrayLayers = 1; |
| 14132 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 14133 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 14134 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 14135 | |
| 14136 | vk_testing::Image color_image; |
| 14137 | color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 14138 | reqs); |
| 14139 | |
| 14140 | const VkImageSubresourceRange color_range = |
| 14141 | vk_testing::Image::subresource_range(image_create_info, |
| 14142 | VK_IMAGE_ASPECT_COLOR_BIT); |
| 14143 | |
| 14144 | // Depth/Stencil image |
| 14145 | VkClearDepthStencilValue clear_value = {0}; |
| 14146 | reqs = 0; // don't need HOST_VISIBLE DS image |
| 14147 | VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info(); |
| 14148 | ds_image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 14149 | ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 14150 | ds_image_create_info.extent.width = 64; |
| 14151 | ds_image_create_info.extent.height = 64; |
| 14152 | ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 14153 | ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 14154 | |
| 14155 | vk_testing::Image ds_image; |
| 14156 | ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, |
| 14157 | reqs); |
| 14158 | |
| 14159 | const VkImageSubresourceRange ds_range = |
| 14160 | vk_testing::Image::subresource_range(ds_image_create_info, |
| 14161 | VK_IMAGE_ASPECT_DEPTH_BIT); |
| 14162 | |
| 14163 | m_errorMonitor->SetDesiredFailureMsg( |
| 14164 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 14165 | "vkCmdClearColorImage called with depth/stencil image."); |
| 14166 | |
| 14167 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), |
| 14168 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, |
| 14169 | &color_range); |
| 14170 | |
| 14171 | m_errorMonitor->VerifyFound(); |
| 14172 | |
Tony Barbour | 26434b9 | 2016-06-02 09:43:50 -0600 | [diff] [blame] | 14173 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 14174 | "vkCmdClearColorImage called with " |
| 14175 | "image created without " |
| 14176 | "VK_IMAGE_USAGE_TRANSFER_DST_BIT"); |
| 14177 | |
| 14178 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), |
| 14179 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, |
| 14180 | &color_range); |
| 14181 | |
| 14182 | m_errorMonitor->VerifyFound(); |
| 14183 | |
Tobin Ehlis | 6e23d77 | 2016-05-19 11:08:34 -0600 | [diff] [blame] | 14184 | // Call CmdClearDepthStencilImage with color image |
| 14185 | m_errorMonitor->SetDesiredFailureMsg( |
| 14186 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 14187 | "vkCmdClearDepthStencilImage called without a depth/stencil image."); |
| 14188 | |
| 14189 | vkCmdClearDepthStencilImage( |
| 14190 | m_commandBuffer->GetBufferHandle(), color_image.handle(), |
| 14191 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, |
| 14192 | &ds_range); |
| 14193 | |
| 14194 | m_errorMonitor->VerifyFound(); |
| 14195 | } |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 14196 | #endif // IMAGE_TESTS |
| 14197 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 14198 | int main(int argc, char **argv) { |
| 14199 | int result; |
| 14200 | |
Cody Northrop | 8e54a40 | 2016-03-08 22:25:52 -0700 | [diff] [blame] | 14201 | #ifdef ANDROID |
| 14202 | int vulkanSupport = InitVulkan(); |
| 14203 | if (vulkanSupport == 0) |
| 14204 | return 1; |
| 14205 | #endif |
| 14206 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 14207 | ::testing::InitGoogleTest(&argc, argv); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 14208 | VkTestFramework::InitArgs(&argc, argv); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 14209 | |
| 14210 | ::testing::AddGlobalTestEnvironment(new TestEnvironment); |
| 14211 | |
| 14212 | result = RUN_ALL_TESTS(); |
| 14213 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 14214 | VkTestFramework::Finish(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 14215 | return result; |
| 14216 | } |