Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015-2016 The Khronos Group Inc. |
| 3 | * Copyright (c) 2015-2016 Valve Corporation |
| 4 | * Copyright (c) 2015-2016 LunarG, Inc. |
Michael Lentine | 0a369f6 | 2016-02-03 16:51:46 -0600 | [diff] [blame] | 5 | * Copyright (c) 2015-2016 Google, Inc. |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12 | * |
| 13 | * Author: Chia-I Wu <olvaffe@gmail.com> |
| 14 | * Author: Chris Forbes <chrisf@ijw.co.nz> |
| 15 | * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
| 16 | * Author: Mark Lobodzinski <mark@lunarg.com> |
| 17 | * Author: Mike Stroyan <mike@LunarG.com> |
| 18 | * Author: Tobin Ehlis <tobine@google.com> |
| 19 | * Author: Tony Barbour <tony@LunarG.com> |
| 20 | */ |
Tony Barbour | 65c48b3 | 2015-11-17 10:02:56 -0700 | [diff] [blame] | 21 | |
Cody Northrop | 8e54a40 | 2016-03-08 22:25:52 -0700 | [diff] [blame] | 22 | #ifdef ANDROID |
| 23 | #include "vulkan_wrapper.h" |
| 24 | #else |
David Pinedo | 9316d3b | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 25 | #include <vulkan/vulkan.h> |
Cody Northrop | 8e54a40 | 2016-03-08 22:25:52 -0700 | [diff] [blame] | 26 | #endif |
Courtney Goeltzenleuchter | 58f3eff | 2015-10-07 13:28:58 -0600 | [diff] [blame] | 27 | #include "test_common.h" |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 28 | #include "vkrenderframework.h" |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 29 | #include "vk_layer_config.h" |
Jon Ashburn | 7fa7e22 | 2016-02-02 12:08:10 -0700 | [diff] [blame] | 30 | #include "icd-spv.h" |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 31 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 32 | #define GLM_FORCE_RADIANS |
| 33 | #include "glm/glm.hpp" |
| 34 | #include <glm/gtc/matrix_transform.hpp> |
| 35 | |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 36 | #define PARAMETER_VALIDATION_TESTS 1 |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 37 | #define MEM_TRACKER_TESTS 1 |
| 38 | #define OBJ_TRACKER_TESTS 1 |
| 39 | #define DRAW_STATE_TESTS 1 |
| 40 | #define THREADING_TESTS 1 |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 41 | #define SHADER_CHECKER_TESTS 1 |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 42 | #define DEVICE_LIMITS_TESTS 1 |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 43 | #define IMAGE_TESTS 1 |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 44 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 45 | //-------------------------------------------------------------------------------------- |
| 46 | // Mesh and VertexFormat Data |
| 47 | //-------------------------------------------------------------------------------------- |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 48 | struct Vertex { |
| 49 | float posX, posY, posZ, posW; // Position data |
| 50 | float r, g, b, a; // Color |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 51 | }; |
| 52 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 53 | #define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 54 | |
| 55 | typedef enum _BsoFailSelect { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 56 | BsoFailNone = 0x00000000, |
| 57 | BsoFailLineWidth = 0x00000001, |
| 58 | BsoFailDepthBias = 0x00000002, |
| 59 | BsoFailViewport = 0x00000004, |
| 60 | BsoFailScissor = 0x00000008, |
| 61 | BsoFailBlend = 0x00000010, |
| 62 | BsoFailDepthBounds = 0x00000020, |
| 63 | BsoFailStencilReadMask = 0x00000040, |
| 64 | BsoFailStencilWriteMask = 0x00000080, |
| 65 | BsoFailStencilReference = 0x00000100, |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 66 | BsoFailCmdClearAttachments = 0x00000200, |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 67 | } BsoFailSelect; |
| 68 | |
| 69 | struct vktriangle_vs_uniform { |
| 70 | // Must start with MVP |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 71 | float mvp[4][4]; |
| 72 | float position[3][4]; |
| 73 | float color[3][4]; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 74 | }; |
| 75 | |
Mark Lobodzinski | 75a97e6 | 2015-06-02 09:41:30 -0500 | [diff] [blame] | 76 | static const char bindStateVertShaderText[] = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 77 | "#version 450\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 78 | "vec2 vertices[3];\n" |
| 79 | "out gl_PerVertex {\n" |
| 80 | " vec4 gl_Position;\n" |
| 81 | "};\n" |
| 82 | "void main() {\n" |
| 83 | " vertices[0] = vec2(-1.0, -1.0);\n" |
| 84 | " vertices[1] = vec2( 1.0, -1.0);\n" |
| 85 | " vertices[2] = vec2( 0.0, 1.0);\n" |
| 86 | " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n" |
| 87 | "}\n"; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 88 | |
Mark Lobodzinski | 75a97e6 | 2015-06-02 09:41:30 -0500 | [diff] [blame] | 89 | static const char bindStateFragShaderText[] = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 90 | "#version 450\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 91 | "\n" |
| 92 | "layout(location = 0) out vec4 uFragColor;\n" |
| 93 | "void main(){\n" |
| 94 | " uFragColor = vec4(0,1,0,1);\n" |
| 95 | "}\n"; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 96 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 97 | static VKAPI_ATTR VkBool32 VKAPI_CALL |
| 98 | myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, |
| 99 | uint64_t srcObject, size_t location, int32_t msgCode, |
| 100 | const char *pLayerPrefix, const char *pMsg, void *pUserData); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 101 | |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 102 | // ******************************************************** |
| 103 | // ErrorMonitor Usage: |
| 104 | // |
| 105 | // Call SetDesiredFailureMsg with a string to be compared against all |
| 106 | // encountered log messages. Passing NULL will match all log messages. |
| 107 | // logMsg will return true for skipCall only if msg is matched or NULL. |
| 108 | // |
| 109 | // Call DesiredMsgFound to determine if the desired failure message |
| 110 | // was encountered. |
| 111 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 112 | class ErrorMonitor { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 113 | public: |
| 114 | ErrorMonitor() { |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 115 | test_platform_thread_create_mutex(&m_mutex); |
| 116 | test_platform_thread_lock_mutex(&m_mutex); |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 117 | m_msgFlags = VK_DEBUG_REPORT_INFORMATION_BIT_EXT; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 118 | m_bailout = NULL; |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 119 | test_platform_thread_unlock_mutex(&m_mutex); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 120 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 121 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 122 | ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); } |
| 123 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 124 | void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 125 | // also discard all collected messages to this point |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 126 | test_platform_thread_lock_mutex(&m_mutex); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 127 | m_failureMsg.clear(); |
| 128 | m_otherMsgs.clear(); |
| 129 | m_desiredMsg = msgString; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 130 | m_msgFound = VK_FALSE; |
| 131 | m_msgFlags = msgFlags; |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 132 | test_platform_thread_unlock_mutex(&m_mutex); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 133 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 134 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 135 | VkBool32 CheckForDesiredMsg(VkFlags msgFlags, const char *msgString) { |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 136 | VkBool32 result = VK_FALSE; |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 137 | test_platform_thread_lock_mutex(&m_mutex); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 138 | if (m_bailout != NULL) { |
| 139 | *m_bailout = true; |
| 140 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 141 | string errorString(msgString); |
| 142 | if (msgFlags & m_msgFlags) { |
| 143 | if (errorString.find(m_desiredMsg) != string::npos) { |
Chris Forbes | c7b8ad7 | 2016-04-04 18:50:38 +1200 | [diff] [blame] | 144 | if (m_msgFound) { /* if multiple matches, don't lose all but the last! */ |
| 145 | m_otherMsgs.push_back(m_failureMsg); |
| 146 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 147 | m_failureMsg = errorString; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 148 | m_msgFound = VK_TRUE; |
| 149 | result = VK_TRUE; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 150 | } else { |
| 151 | m_otherMsgs.push_back(errorString); |
| 152 | } |
| 153 | } |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 154 | test_platform_thread_unlock_mutex(&m_mutex); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 155 | return result; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 156 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 157 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 158 | vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 159 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 160 | string GetFailureMsg(void) { return m_failureMsg; } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 161 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 162 | VkBool32 DesiredMsgFound(void) { return m_msgFound; } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 163 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 164 | void SetBailout(bool *bailout) { m_bailout = bailout; } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 165 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 166 | void DumpFailureMsgs(void) { |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 167 | vector<string> otherMsgs = GetOtherFailureMsgs(); |
| 168 | cout << "Other error messages logged for this test were:" << endl; |
| 169 | for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) { |
| 170 | cout << " " << *iter << endl; |
| 171 | } |
| 172 | } |
| 173 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 174 | /* helpers */ |
| 175 | |
| 176 | void ExpectSuccess() { |
| 177 | // match anything |
| 178 | SetDesiredFailureMsg(~0u, ""); |
| 179 | } |
| 180 | |
| 181 | void VerifyFound() { |
| 182 | // Not seeing the desired message is a failure. /Before/ throwing, dump |
| 183 | // any other messages. |
| 184 | if (!DesiredMsgFound()) { |
| 185 | DumpFailureMsgs(); |
| 186 | FAIL() << "Did not receive expected error '" << m_desiredMsg << "'"; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | void VerifyNotFound() { |
| 191 | // ExpectSuccess() configured us to match anything. Any error is a |
| 192 | // failure. |
| 193 | if (DesiredMsgFound()) { |
| 194 | DumpFailureMsgs(); |
| 195 | FAIL() << "Expected to succeed but got error: " << GetFailureMsg(); |
| 196 | } |
| 197 | } |
| 198 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 199 | private: |
| 200 | VkFlags m_msgFlags; |
| 201 | string m_desiredMsg; |
| 202 | string m_failureMsg; |
| 203 | vector<string> m_otherMsgs; |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 204 | test_platform_thread_mutex m_mutex; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 205 | bool *m_bailout; |
| 206 | VkBool32 m_msgFound; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 207 | }; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 208 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 209 | static VKAPI_ATTR VkBool32 VKAPI_CALL |
| 210 | myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, |
| 211 | uint64_t srcObject, size_t location, int32_t msgCode, |
| 212 | const char *pLayerPrefix, const char *pMsg, void *pUserData) { |
| 213 | if (msgFlags & |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 214 | (VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 215 | VK_DEBUG_REPORT_ERROR_BIT_EXT)) { |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 216 | ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 217 | return errMonitor->CheckForDesiredMsg(msgFlags, pMsg); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 218 | } |
Courtney Goeltzenleuchter | 0664083 | 2015-09-04 13:52:24 -0600 | [diff] [blame] | 219 | return false; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 220 | } |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 221 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 222 | class VkLayerTest : public VkRenderFramework { |
| 223 | public: |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 224 | VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer); |
| 225 | VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 226 | void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, |
| 227 | BsoFailSelect failMask); |
| 228 | void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, |
| 229 | VkPipelineObj &pipelineobj, |
| 230 | VkDescriptorSetObj &descriptorSet, |
| 231 | BsoFailSelect failMask); |
| 232 | void GenericDrawPreparation(VkPipelineObj &pipelineobj, |
| 233 | VkDescriptorSetObj &descriptorSet, |
| 234 | BsoFailSelect failMask) { |
| 235 | GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, |
| 236 | failMask); |
| 237 | } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 238 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 239 | /* Convenience functions that use built-in command buffer */ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 240 | VkResult BeginCommandBuffer() { |
| 241 | return BeginCommandBuffer(*m_commandBuffer); |
| 242 | } |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 243 | VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 244 | void Draw(uint32_t vertexCount, uint32_t instanceCount, |
| 245 | uint32_t firstVertex, uint32_t firstInstance) { |
| 246 | m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, |
| 247 | firstInstance); |
| 248 | } |
| 249 | void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, |
| 250 | uint32_t firstIndex, int32_t vertexOffset, |
| 251 | uint32_t firstInstance) { |
| 252 | m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, |
| 253 | vertexOffset, firstInstance); |
| 254 | } |
Mark Lobodzinski | cf0ae75 | 2016-06-23 10:02:24 -0600 | [diff] [blame] | 255 | void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 256 | void QueueCommandBuffer(const VkFence &fence) { |
| 257 | m_commandBuffer->QueueCommandBuffer(fence); |
| 258 | } |
| 259 | void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, |
| 260 | VkDeviceSize offset, uint32_t binding) { |
| 261 | m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding); |
| 262 | } |
| 263 | void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) { |
| 264 | m_commandBuffer->BindIndexBuffer(indexBuffer, offset); |
| 265 | } |
| 266 | |
| 267 | protected: |
| 268 | ErrorMonitor *m_errorMonitor; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 269 | bool m_enableWSI; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 270 | |
| 271 | virtual void SetUp() { |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 272 | std::vector<const char *> instance_layer_names; |
| 273 | std::vector<const char *> device_layer_names; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 274 | std::vector<const char *> instance_extension_names; |
| 275 | std::vector<const char *> device_extension_names; |
Tony Barbour | 3fdff9e | 2015-04-23 12:55:36 -0600 | [diff] [blame] | 276 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 277 | instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); |
Courtney Goeltzenleuchter | c2b06fe | 2015-06-16 15:59:11 -0600 | [diff] [blame] | 278 | /* |
| 279 | * Since CreateDbgMsgCallback is an instance level extension call |
| 280 | * any extension / layer that utilizes that feature also needs |
| 281 | * to be enabled at create instance time. |
| 282 | */ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 283 | // Use Threading layer first to protect others from |
| 284 | // ThreadCommandBufferCollision test |
Courtney Goeltzenleuchter | 7688532 | 2016-02-06 17:11:22 -0700 | [diff] [blame] | 285 | instance_layer_names.push_back("VK_LAYER_GOOGLE_threading"); |
Tobin Ehlis | 24aab04 | 2016-03-24 10:54:18 -0600 | [diff] [blame] | 286 | instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation"); |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 287 | instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker"); |
Tobin Ehlis | c96f806 | 2016-03-09 16:12:48 -0700 | [diff] [blame] | 288 | instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation"); |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 289 | instance_layer_names.push_back("VK_LAYER_LUNARG_device_limits"); |
| 290 | instance_layer_names.push_back("VK_LAYER_LUNARG_image"); |
Ian Elliott | e48a138 | 2016-04-28 14:22:58 -0600 | [diff] [blame] | 291 | instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain"); |
Dustin Graves | eaa78cd | 2016-01-26 16:30:22 -0700 | [diff] [blame] | 292 | instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects"); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 293 | |
Courtney Goeltzenleuchter | 7688532 | 2016-02-06 17:11:22 -0700 | [diff] [blame] | 294 | device_layer_names.push_back("VK_LAYER_GOOGLE_threading"); |
Tobin Ehlis | 24aab04 | 2016-03-24 10:54:18 -0600 | [diff] [blame] | 295 | device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation"); |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 296 | device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker"); |
Tobin Ehlis | c96f806 | 2016-03-09 16:12:48 -0700 | [diff] [blame] | 297 | device_layer_names.push_back("VK_LAYER_LUNARG_core_validation"); |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 298 | device_layer_names.push_back("VK_LAYER_LUNARG_device_limits"); |
| 299 | device_layer_names.push_back("VK_LAYER_LUNARG_image"); |
Ian Elliott | e48a138 | 2016-04-28 14:22:58 -0600 | [diff] [blame] | 300 | device_layer_names.push_back("VK_LAYER_LUNARG_swapchain"); |
Dustin Graves | eaa78cd | 2016-01-26 16:30:22 -0700 | [diff] [blame] | 301 | device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects"); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 302 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 303 | if (m_enableWSI) { |
| 304 | instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME); |
| 305 | device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME); |
| 306 | #ifdef NEED_TO_TEST_THIS_ON_PLATFORM |
| 307 | #if defined(VK_USE_PLATFORM_ANDROID_KHR) |
| 308 | instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME); |
| 309 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 310 | #if defined(VK_USE_PLATFORM_MIR_KHR) |
| 311 | instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME); |
| 312 | #endif // VK_USE_PLATFORM_MIR_KHR |
| 313 | #if defined(VK_USE_PLATFORM_WAYLAND_KHR) |
| 314 | instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME); |
| 315 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
| 316 | #if defined(VK_USE_PLATFORM_WIN32_KHR) |
| 317 | instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); |
| 318 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 319 | #endif // NEED_TO_TEST_THIS_ON_PLATFORM |
| 320 | #if defined(VK_USE_PLATFORM_XCB_KHR) |
| 321 | instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME); |
| 322 | #elif defined(VK_USE_PLATFORM_XLIB_KHR) |
| 323 | instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME); |
| 324 | #endif // VK_USE_PLATFORM_XLIB_KHR |
| 325 | } |
| 326 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 327 | this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 328 | this->app_info.pNext = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 329 | this->app_info.pApplicationName = "layer_tests"; |
| 330 | this->app_info.applicationVersion = 1; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 331 | this->app_info.pEngineName = "unittest"; |
| 332 | this->app_info.engineVersion = 1; |
Jon Ashburn | c5012ff | 2016-03-22 13:57:46 -0600 | [diff] [blame] | 333 | this->app_info.apiVersion = VK_API_VERSION_1_0; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 334 | |
Tony Barbour | 15524c3 | 2015-04-29 17:34:29 -0600 | [diff] [blame] | 335 | m_errorMonitor = new ErrorMonitor; |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 336 | InitFramework(instance_layer_names, device_layer_names, |
| 337 | instance_extension_names, device_extension_names, |
| 338 | myDbgFunc, m_errorMonitor); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | virtual void TearDown() { |
| 342 | // Clean up resources before we reset |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 343 | ShutdownFramework(); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 344 | delete m_errorMonitor; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 345 | } |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 346 | |
| 347 | VkLayerTest() { |
| 348 | m_enableWSI = false; |
| 349 | } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 350 | }; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 351 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 352 | VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 353 | VkResult result; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 354 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 355 | result = commandBuffer.BeginCommandBuffer(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 356 | |
| 357 | /* |
| 358 | * For render test all drawing happens in a single render pass |
| 359 | * on a single command buffer. |
| 360 | */ |
Chris Forbes | 76a5eeb | 2015-06-16 14:05:59 +1200 | [diff] [blame] | 361 | if (VK_SUCCESS == result && renderPass()) { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 362 | commandBuffer.BeginRenderPass(renderPassBeginInfo()); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | return result; |
| 366 | } |
| 367 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 368 | VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 369 | VkResult result; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 370 | |
Chris Forbes | 76a5eeb | 2015-06-16 14:05:59 +1200 | [diff] [blame] | 371 | if (renderPass()) { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 372 | commandBuffer.EndRenderPass(); |
Chris Forbes | 76a5eeb | 2015-06-16 14:05:59 +1200 | [diff] [blame] | 373 | } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 374 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 375 | result = commandBuffer.EndCommandBuffer(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 376 | |
| 377 | return result; |
| 378 | } |
| 379 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 380 | void VkLayerTest::VKTriangleTest(const char *vertShaderText, |
| 381 | const char *fragShaderText, |
| 382 | BsoFailSelect failMask) { |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 383 | // Create identity matrix |
| 384 | int i; |
| 385 | struct vktriangle_vs_uniform data; |
| 386 | |
| 387 | glm::mat4 Projection = glm::mat4(1.0f); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 388 | glm::mat4 View = glm::mat4(1.0f); |
| 389 | glm::mat4 Model = glm::mat4(1.0f); |
| 390 | glm::mat4 MVP = Projection * View * Model; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 391 | const int matrixSize = sizeof(MVP); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 392 | const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 393 | |
| 394 | memcpy(&data.mvp, &MVP[0][0], matrixSize); |
| 395 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 396 | static const Vertex tri_data[] = { |
| 397 | {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, |
| 398 | {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, |
| 399 | {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)}, |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 400 | }; |
| 401 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 402 | for (i = 0; i < 3; i++) { |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 403 | data.position[i][0] = tri_data[i].posX; |
| 404 | data.position[i][1] = tri_data[i].posY; |
| 405 | data.position[i][2] = tri_data[i].posZ; |
| 406 | data.position[i][3] = tri_data[i].posW; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 407 | data.color[i][0] = tri_data[i].r; |
| 408 | data.color[i][1] = tri_data[i].g; |
| 409 | data.color[i][2] = tri_data[i].b; |
| 410 | data.color[i][3] = tri_data[i].a; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 414 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 415 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 416 | VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), |
| 417 | (const void *)&data); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 418 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 419 | VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 420 | VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, |
| 421 | this); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 422 | |
| 423 | VkPipelineObj pipelineobj(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 424 | pipelineobj.AddColorAttachment(); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 425 | pipelineobj.AddShader(&vs); |
| 426 | pipelineobj.AddShader(&ps); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 427 | if (failMask & BsoFailLineWidth) { |
| 428 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH); |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 429 | VkPipelineInputAssemblyStateCreateInfo ia_state = {}; |
| 430 | ia_state.sType = |
| 431 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 432 | ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST; |
| 433 | pipelineobj.SetInputAssembly(&ia_state); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 434 | } |
| 435 | if (failMask & BsoFailDepthBias) { |
| 436 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS); |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 437 | VkPipelineRasterizationStateCreateInfo rs_state = {}; |
| 438 | rs_state.sType = |
| 439 | VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 440 | rs_state.depthBiasEnable = VK_TRUE; |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 441 | rs_state.lineWidth = 1.0f; |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 442 | pipelineobj.SetRasterization(&rs_state); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 443 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 444 | // Viewport and scissors must stay in synch or other errors will occur than |
| 445 | // the ones we want |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 446 | if (failMask & BsoFailViewport) { |
| 447 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 448 | m_viewports.clear(); |
| 449 | m_scissors.clear(); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 450 | } |
| 451 | if (failMask & BsoFailScissor) { |
| 452 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 453 | m_scissors.clear(); |
| 454 | m_viewports.clear(); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 455 | } |
| 456 | if (failMask & BsoFailBlend) { |
| 457 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS); |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 458 | VkPipelineColorBlendAttachmentState att_state = {}; |
| 459 | att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR; |
| 460 | att_state.blendEnable = VK_TRUE; |
| 461 | pipelineobj.AddColorAttachment(0, &att_state); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 462 | } |
| 463 | if (failMask & BsoFailDepthBounds) { |
| 464 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS); |
| 465 | } |
| 466 | if (failMask & BsoFailStencilReadMask) { |
| 467 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK); |
| 468 | } |
| 469 | if (failMask & BsoFailStencilWriteMask) { |
| 470 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK); |
| 471 | } |
| 472 | if (failMask & BsoFailStencilReference) { |
| 473 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE); |
| 474 | } |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 475 | |
| 476 | VkDescriptorSetObj descriptorSet(m_device); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 477 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, |
| 478 | constantBuffer); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 479 | |
| 480 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 481 | ASSERT_VK_SUCCESS(BeginCommandBuffer()); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 482 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 483 | GenericDrawPreparation(pipelineobj, descriptorSet, failMask); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 484 | |
| 485 | // render triangle |
Courtney Goeltzenleuchter | 08c2637 | 2015-09-23 12:31:50 -0600 | [diff] [blame] | 486 | Draw(3, 1, 0, 0); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 487 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 488 | if (failMask & BsoFailCmdClearAttachments) { |
| 489 | VkClearAttachment color_attachment = {}; |
| 490 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 491 | color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index; |
| 492 | VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0}; |
| 493 | |
| 494 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 495 | &color_attachment, 1, &clear_rect); |
| 496 | } |
| 497 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 498 | // finalize recording of the command buffer |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 499 | EndCommandBuffer(); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 500 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 501 | QueueCommandBuffer(); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 502 | } |
| 503 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 504 | void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, |
| 505 | VkPipelineObj &pipelineobj, |
| 506 | VkDescriptorSetObj &descriptorSet, |
| 507 | BsoFailSelect failMask) { |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 508 | if (m_depthStencil->Initialized()) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 509 | commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 510 | m_stencil_clear_color, m_depthStencil); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 511 | } else { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 512 | commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 513 | m_stencil_clear_color, NULL); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 514 | } |
| 515 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 516 | commandBuffer->PrepareAttachments(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 517 | // Make sure depthWriteEnable is set so that Depth fail test will work |
| 518 | // correctly |
| 519 | // Make sure stencilTestEnable is set so that Stencil fail test will work |
| 520 | // correctly |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 521 | VkStencilOpState stencil = {}; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 522 | stencil.failOp = VK_STENCIL_OP_KEEP; |
| 523 | stencil.passOp = VK_STENCIL_OP_KEEP; |
| 524 | stencil.depthFailOp = VK_STENCIL_OP_KEEP; |
| 525 | stencil.compareOp = VK_COMPARE_OP_NEVER; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 526 | |
| 527 | VkPipelineDepthStencilStateCreateInfo ds_ci = {}; |
| 528 | ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 529 | ds_ci.pNext = NULL; |
| 530 | ds_ci.depthTestEnable = VK_FALSE; |
| 531 | ds_ci.depthWriteEnable = VK_TRUE; |
| 532 | ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER; |
| 533 | ds_ci.depthBoundsTestEnable = VK_FALSE; |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 534 | if (failMask & BsoFailDepthBounds) { |
| 535 | ds_ci.depthBoundsTestEnable = VK_TRUE; |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 536 | ds_ci.maxDepthBounds = 0.0f; |
| 537 | ds_ci.minDepthBounds = 0.0f; |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 538 | } |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 539 | ds_ci.stencilTestEnable = VK_TRUE; |
| 540 | ds_ci.front = stencil; |
| 541 | ds_ci.back = stencil; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 542 | |
Tobin Ehlis | 4bf96d1 | 2015-06-25 11:58:41 -0600 | [diff] [blame] | 543 | pipelineobj.SetDepthStencil(&ds_ci); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 544 | pipelineobj.SetViewport(m_viewports); |
| 545 | pipelineobj.SetScissor(m_scissors); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 546 | descriptorSet.CreateVKDescriptorSet(commandBuffer); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 547 | VkResult err = pipelineobj.CreateVKPipeline( |
| 548 | descriptorSet.GetPipelineLayout(), renderPass()); |
Cody Northrop | 29a08f2 | 2015-08-27 10:20:35 -0600 | [diff] [blame] | 549 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 550 | commandBuffer->BindPipeline(pipelineobj); |
| 551 | commandBuffer->BindDescriptorSet(descriptorSet); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 552 | } |
| 553 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 554 | class VkWsiEnabledLayerTest : public VkLayerTest { |
| 555 | public: |
| 556 | protected: |
| 557 | VkWsiEnabledLayerTest() { |
| 558 | m_enableWSI = true; |
| 559 | } |
| 560 | }; |
| 561 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 562 | // ******************************************************************************************************************** |
| 563 | // ******************************************************************************************************************** |
| 564 | // ******************************************************************************************************************** |
| 565 | // ******************************************************************************************************************** |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 566 | #if PARAMETER_VALIDATION_TESTS |
| 567 | TEST_F(VkLayerTest, RequiredParameter) { |
| 568 | TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, " |
| 569 | "pointer, array, and array count parameters"); |
| 570 | |
| 571 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 572 | |
| 573 | m_errorMonitor->SetDesiredFailureMsg( |
| 574 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 575 | "required parameter pFeatures specified as NULL"); |
| 576 | // Specify NULL for a pointer to a handle |
| 577 | // Expected to trigger an error with |
| 578 | // parameter_validation::validate_required_pointer |
| 579 | vkGetPhysicalDeviceFeatures(gpu(), NULL); |
| 580 | m_errorMonitor->VerifyFound(); |
| 581 | |
| 582 | m_errorMonitor->SetDesiredFailureMsg( |
| 583 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Dustin Graves | a4bb8c1 | 2016-05-16 17:22:51 -0600 | [diff] [blame] | 584 | "required parameter pQueueFamilyPropertyCount specified as NULL"); |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 585 | // Specify NULL for pointer to array count |
| 586 | // Expected to trigger an error with parameter_validation::validate_array |
Dustin Graves | a4bb8c1 | 2016-05-16 17:22:51 -0600 | [diff] [blame] | 587 | vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL); |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 588 | m_errorMonitor->VerifyFound(); |
| 589 | |
| 590 | m_errorMonitor->SetDesiredFailureMsg( |
| 591 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 592 | "parameter viewportCount must be greater than 0"); |
| 593 | // Specify 0 for a required array count |
| 594 | // Expected to trigger an error with parameter_validation::validate_array |
| 595 | VkViewport view_port = {}; |
| 596 | m_commandBuffer->SetViewport(0, 0, &view_port); |
| 597 | m_errorMonitor->VerifyFound(); |
| 598 | |
| 599 | m_errorMonitor->SetDesiredFailureMsg( |
| 600 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 601 | "required parameter pViewports specified as NULL"); |
| 602 | // Specify NULL for a required array |
| 603 | // Expected to trigger an error with parameter_validation::validate_array |
| 604 | m_commandBuffer->SetViewport(0, 1, NULL); |
| 605 | m_errorMonitor->VerifyFound(); |
| 606 | |
| 607 | m_errorMonitor->SetDesiredFailureMsg( |
| 608 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 609 | "required parameter memory specified as VK_NULL_HANDLE"); |
| 610 | // Specify VK_NULL_HANDLE for a required handle |
| 611 | // Expected to trigger an error with |
| 612 | // parameter_validation::validate_required_handle |
| 613 | vkUnmapMemory(device(), VK_NULL_HANDLE); |
| 614 | m_errorMonitor->VerifyFound(); |
| 615 | |
| 616 | m_errorMonitor->SetDesiredFailureMsg( |
| 617 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 618 | "required parameter pFences[0] specified as VK_NULL_HANDLE"); |
| 619 | // Specify VK_NULL_HANDLE for a required handle array entry |
| 620 | // Expected to trigger an error with |
| 621 | // parameter_validation::validate_required_handle_array |
| 622 | VkFence fence = VK_NULL_HANDLE; |
| 623 | vkResetFences(device(), 1, &fence); |
| 624 | m_errorMonitor->VerifyFound(); |
| 625 | |
| 626 | m_errorMonitor->SetDesiredFailureMsg( |
| 627 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 628 | "required parameter pAllocateInfo specified as NULL"); |
| 629 | // Specify NULL for a required struct pointer |
| 630 | // Expected to trigger an error with |
| 631 | // parameter_validation::validate_struct_type |
| 632 | VkDeviceMemory memory = VK_NULL_HANDLE; |
| 633 | vkAllocateMemory(device(), NULL, NULL, &memory); |
| 634 | m_errorMonitor->VerifyFound(); |
| 635 | |
| 636 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 637 | "value of faceMask must not be 0"); |
| 638 | // Specify 0 for a required VkFlags parameter |
| 639 | // Expected to trigger an error with parameter_validation::validate_flags |
| 640 | m_commandBuffer->SetStencilReference(0, 0); |
| 641 | m_errorMonitor->VerifyFound(); |
| 642 | |
| 643 | m_errorMonitor->SetDesiredFailureMsg( |
| 644 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 645 | "value of pSubmits[i].pWaitDstStageMask[0] must not be 0"); |
| 646 | // Specify 0 for a required VkFlags array entry |
| 647 | // Expected to trigger an error with |
| 648 | // parameter_validation::validate_flags_array |
| 649 | VkSemaphore semaphore = VK_NULL_HANDLE; |
| 650 | VkPipelineStageFlags stageFlags = 0; |
| 651 | VkSubmitInfo submitInfo = {}; |
| 652 | submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 653 | submitInfo.waitSemaphoreCount = 1; |
| 654 | submitInfo.pWaitSemaphores = &semaphore; |
| 655 | submitInfo.pWaitDstStageMask = &stageFlags; |
| 656 | vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE); |
| 657 | m_errorMonitor->VerifyFound(); |
| 658 | } |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 659 | |
Dustin Graves | fce74c0 | 2016-05-10 11:42:58 -0600 | [diff] [blame] | 660 | TEST_F(VkLayerTest, ReservedParameter) { |
| 661 | TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter"); |
| 662 | |
| 663 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 664 | |
| 665 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 666 | " must be 0"); |
| 667 | // Specify 0 for a reserved VkFlags parameter |
| 668 | // Expected to trigger an error with |
| 669 | // parameter_validation::validate_reserved_flags |
| 670 | VkEvent event_handle = VK_NULL_HANDLE; |
| 671 | VkEventCreateInfo event_info = {}; |
| 672 | event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 673 | event_info.flags = 1; |
| 674 | vkCreateEvent(device(), &event_info, NULL, &event_handle); |
| 675 | m_errorMonitor->VerifyFound(); |
| 676 | } |
| 677 | |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 678 | TEST_F(VkLayerTest, InvalidStructSType) { |
| 679 | TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan " |
| 680 | "structure's sType field"); |
| 681 | |
| 682 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 683 | |
| 684 | m_errorMonitor->SetDesiredFailureMsg( |
| 685 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 686 | "parameter pAllocateInfo->sType must be"); |
| 687 | // Zero struct memory, effectively setting sType to |
| 688 | // VK_STRUCTURE_TYPE_APPLICATION_INFO |
| 689 | // Expected to trigger an error with |
| 690 | // parameter_validation::validate_struct_type |
| 691 | VkMemoryAllocateInfo alloc_info = {}; |
| 692 | VkDeviceMemory memory = VK_NULL_HANDLE; |
| 693 | vkAllocateMemory(device(), &alloc_info, NULL, &memory); |
| 694 | m_errorMonitor->VerifyFound(); |
| 695 | |
| 696 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 697 | "parameter pSubmits[0].sType must be"); |
| 698 | // Zero struct memory, effectively setting sType to |
| 699 | // VK_STRUCTURE_TYPE_APPLICATION_INFO |
| 700 | // Expected to trigger an error with |
| 701 | // parameter_validation::validate_struct_type_array |
| 702 | VkSubmitInfo submit_info = {}; |
| 703 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 704 | m_errorMonitor->VerifyFound(); |
| 705 | } |
| 706 | |
| 707 | TEST_F(VkLayerTest, InvalidStructPNext) { |
| 708 | TEST_DESCRIPTION( |
| 709 | "Specify an invalid value for a Vulkan structure's pNext field"); |
| 710 | |
| 711 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 712 | |
| 713 | m_errorMonitor->SetDesiredFailureMsg( |
| 714 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 715 | "value of pAllocateInfo->pNext must be NULL"); |
| 716 | // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be |
| 717 | // NULL |
| 718 | // Expected to trigger an error with |
| 719 | // parameter_validation::validate_struct_pnext |
| 720 | VkDeviceMemory memory = VK_NULL_HANDLE; |
| 721 | // Zero-initialization will provide the correct sType |
| 722 | VkApplicationInfo app_info = {}; |
Dustin Graves | 47b6cba | 2016-05-10 17:34:38 -0600 | [diff] [blame] | 723 | VkMemoryAllocateInfo memory_alloc_info = {}; |
| 724 | memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 725 | memory_alloc_info.pNext = &app_info; |
| 726 | vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory); |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 727 | m_errorMonitor->VerifyFound(); |
| 728 | |
Dustin Graves | 47b6cba | 2016-05-10 17:34:38 -0600 | [diff] [blame] | 729 | m_errorMonitor->SetDesiredFailureMsg( |
| 730 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 731 | " chain includes a structure with unexpected VkStructureType "); |
| 732 | // Set VkGraphicsPipelineCreateInfo::VkPipelineRasterizationStateCreateInfo::pNext to an invalid structure, when pNext is allowed to be a non-NULL value |
| 733 | // Expected to trigger an error with |
| 734 | // parameter_validation::validate_struct_pnext |
| 735 | VkDescriptorPoolSize ds_type_count = {}; |
| 736 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 737 | ds_type_count.descriptorCount = 1; |
| 738 | |
| 739 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 740 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 741 | ds_pool_ci.pNext = NULL; |
| 742 | ds_pool_ci.maxSets = 1; |
| 743 | ds_pool_ci.poolSizeCount = 1; |
| 744 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 745 | |
| 746 | VkDescriptorPool ds_pool; |
| 747 | VkResult err = |
| 748 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 749 | ASSERT_VK_SUCCESS(err); |
| 750 | |
| 751 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 752 | dsl_binding.binding = 0; |
| 753 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 754 | dsl_binding.descriptorCount = 1; |
| 755 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 756 | dsl_binding.pImmutableSamplers = NULL; |
| 757 | |
| 758 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 759 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 760 | ds_layout_ci.pNext = NULL; |
| 761 | ds_layout_ci.bindingCount = 1; |
| 762 | ds_layout_ci.pBindings = &dsl_binding; |
| 763 | |
| 764 | VkDescriptorSetLayout ds_layout; |
| 765 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 766 | &ds_layout); |
| 767 | ASSERT_VK_SUCCESS(err); |
| 768 | |
| 769 | VkDescriptorSet descriptorSet; |
| 770 | VkDescriptorSetAllocateInfo ds_alloc_info = {}; |
| 771 | ds_alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 772 | ds_alloc_info.descriptorSetCount = 1; |
| 773 | ds_alloc_info.descriptorPool = ds_pool; |
| 774 | ds_alloc_info.pSetLayouts = &ds_layout; |
| 775 | err = vkAllocateDescriptorSets(m_device->device(), &ds_alloc_info, |
| 776 | &descriptorSet); |
| 777 | ASSERT_VK_SUCCESS(err); |
| 778 | |
| 779 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 780 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 781 | pipeline_layout_ci.setLayoutCount = 1; |
| 782 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 783 | |
| 784 | VkPipelineLayout pipeline_layout; |
| 785 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 786 | &pipeline_layout); |
| 787 | ASSERT_VK_SUCCESS(err); |
| 788 | |
| 789 | VkViewport vp = {}; // Just need dummy vp to point to |
| 790 | VkRect2D sc = {}; // dummy scissor to point to |
| 791 | |
| 792 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 793 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 794 | vp_state_ci.scissorCount = 1; |
| 795 | vp_state_ci.pScissors = ≻ |
| 796 | vp_state_ci.viewportCount = 1; |
| 797 | vp_state_ci.pViewports = &vp; |
| 798 | |
| 799 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 800 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 801 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 802 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 803 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 804 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 805 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 806 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 807 | |
| 808 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 809 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 810 | gp_ci.pViewportState = &vp_state_ci; |
| 811 | gp_ci.pRasterizationState = &rs_state_ci; |
| 812 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 813 | gp_ci.layout = pipeline_layout; |
| 814 | gp_ci.renderPass = renderPass(); |
| 815 | |
| 816 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 817 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 818 | pc_ci.initialDataSize = 0; |
| 819 | pc_ci.pInitialData = 0; |
| 820 | |
| 821 | VkPipeline pipeline; |
| 822 | VkPipelineCache pipelineCache; |
| 823 | |
| 824 | err = |
| 825 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 826 | ASSERT_VK_SUCCESS(err); |
| 827 | |
| 828 | // Set VkPipelineRasterizationStateCreateInfo::pNext to an invalid value |
| 829 | VkApplicationInfo invalid_pnext_struct = {}; |
| 830 | rs_state_ci.pNext = &invalid_pnext_struct; |
| 831 | |
| 832 | vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 833 | &gp_ci, NULL, &pipeline); |
| 834 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 835 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 836 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 837 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 838 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 839 | |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 840 | } |
Dustin Graves | 5d33d53 | 2016-05-09 16:21:12 -0600 | [diff] [blame] | 841 | |
| 842 | TEST_F(VkLayerTest, UnrecognizedValue) { |
| 843 | TEST_DESCRIPTION( |
| 844 | "Specify unrecognized Vulkan enumeration, flags, and VkBool32 values"); |
| 845 | |
| 846 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 847 | |
| 848 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 849 | "does not fall within the begin..end " |
| 850 | "range of the core VkFormat " |
| 851 | "enumeration tokens"); |
| 852 | // Specify an invalid VkFormat value |
| 853 | // Expected to trigger an error with |
| 854 | // parameter_validation::validate_ranged_enum |
| 855 | VkFormatProperties format_properties; |
| 856 | vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), |
| 857 | &format_properties); |
| 858 | m_errorMonitor->VerifyFound(); |
| 859 | |
| 860 | m_errorMonitor->SetDesiredFailureMsg( |
| 861 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 862 | "contains flag bits that are not recognized members of"); |
| 863 | // Specify an invalid VkFlags bitmask value |
| 864 | // Expected to trigger an error with parameter_validation::validate_flags |
| 865 | VkImageFormatProperties image_format_properties; |
| 866 | vkGetPhysicalDeviceImageFormatProperties( |
| 867 | gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, |
| 868 | VK_IMAGE_TILING_OPTIMAL, static_cast<VkImageUsageFlags>(1 << 25), 0, |
| 869 | &image_format_properties); |
| 870 | m_errorMonitor->VerifyFound(); |
| 871 | |
| 872 | m_errorMonitor->SetDesiredFailureMsg( |
| 873 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 874 | "contains flag bits that are not recognized members of"); |
| 875 | // Specify an invalid VkFlags array entry |
| 876 | // Expected to trigger an error with |
| 877 | // parameter_validation::validate_flags_array |
| 878 | VkSemaphore semaphore = VK_NULL_HANDLE; |
| 879 | VkPipelineStageFlags stage_flags = |
| 880 | static_cast<VkPipelineStageFlags>(1 << 25); |
| 881 | VkSubmitInfo submit_info = {}; |
| 882 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 883 | submit_info.waitSemaphoreCount = 1; |
| 884 | submit_info.pWaitSemaphores = &semaphore; |
| 885 | submit_info.pWaitDstStageMask = &stage_flags; |
| 886 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 887 | m_errorMonitor->VerifyFound(); |
| 888 | |
| 889 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
| 890 | "is neither VK_TRUE nor VK_FALSE"); |
| 891 | // Specify an invalid VkBool32 value |
| 892 | // Expected to trigger a warning with |
| 893 | // parameter_validation::validate_bool32 |
| 894 | VkSampler sampler = VK_NULL_HANDLE; |
| 895 | VkSamplerCreateInfo sampler_info = {}; |
| 896 | sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 897 | sampler_info.pNext = NULL; |
| 898 | sampler_info.magFilter = VK_FILTER_NEAREST; |
| 899 | sampler_info.minFilter = VK_FILTER_NEAREST; |
| 900 | sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 901 | sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 902 | sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 903 | sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 904 | sampler_info.mipLodBias = 1.0; |
| 905 | sampler_info.maxAnisotropy = 1; |
| 906 | sampler_info.compareEnable = VK_FALSE; |
| 907 | sampler_info.compareOp = VK_COMPARE_OP_NEVER; |
| 908 | sampler_info.minLod = 1.0; |
| 909 | sampler_info.maxLod = 1.0; |
| 910 | sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 911 | sampler_info.unnormalizedCoordinates = VK_FALSE; |
| 912 | // Not VK_TRUE or VK_FALSE |
| 913 | sampler_info.anisotropyEnable = 3; |
| 914 | vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler); |
| 915 | m_errorMonitor->VerifyFound(); |
| 916 | } |
Dustin Graves | fce74c0 | 2016-05-10 11:42:58 -0600 | [diff] [blame] | 917 | |
| 918 | TEST_F(VkLayerTest, FailedReturnValue) { |
| 919 | TEST_DESCRIPTION("Check for a message describing a VkResult failure code"); |
| 920 | |
| 921 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 922 | |
Dustin Graves | 13c1e2b | 2016-05-16 15:31:02 -0600 | [diff] [blame] | 923 | // Find an unsupported image format |
| 924 | VkFormat unsupported = VK_FORMAT_UNDEFINED; |
| 925 | for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) { |
| 926 | VkFormat format = static_cast<VkFormat>(f); |
| 927 | VkFormatProperties fProps = m_device->format_properties(format); |
| 928 | if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && |
| 929 | fProps.optimalTilingFeatures == 0) { |
| 930 | unsupported = format; |
| 931 | break; |
| 932 | } |
| 933 | } |
| 934 | |
| 935 | if (unsupported != VK_FORMAT_UNDEFINED) { |
| 936 | m_errorMonitor->SetDesiredFailureMsg( |
| 937 | VK_DEBUG_REPORT_WARNING_BIT_EXT, |
| 938 | "the requested format is not supported on this device"); |
| 939 | // Specify an unsupported VkFormat value to generate a |
| 940 | // VK_ERROR_FORMAT_NOT_SUPPORTED return code |
| 941 | // Expected to trigger a warning from |
| 942 | // parameter_validation::validate_result |
| 943 | VkImageFormatProperties image_format_properties; |
| 944 | VkResult err = vkGetPhysicalDeviceImageFormatProperties( |
| 945 | gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL, |
| 946 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties); |
| 947 | ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED); |
| 948 | m_errorMonitor->VerifyFound(); |
| 949 | } |
Dustin Graves | fce74c0 | 2016-05-10 11:42:58 -0600 | [diff] [blame] | 950 | } |
Mark Lobodzinski | e090fef | 2016-06-09 17:04:56 -0600 | [diff] [blame] | 951 | |
| 952 | TEST_F(VkLayerTest, UpdateBufferAlignment) { |
| 953 | TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer"); |
| 954 | uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; |
| 955 | |
| 956 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 957 | |
| 958 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 959 | vk_testing::Buffer buffer; |
| 960 | buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs); |
| 961 | |
| 962 | BeginCommandBuffer(); |
| 963 | // Introduce failure by using dstOffset that is not multiple of 4 |
| 964 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 965 | " is not a multiple of 4"); |
| 966 | m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData); |
| 967 | m_errorMonitor->VerifyFound(); |
| 968 | |
| 969 | // Introduce failure by using dataSize that is not multiple of 4 |
| 970 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 971 | " is not a multiple of 4"); |
| 972 | m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData); |
| 973 | m_errorMonitor->VerifyFound(); |
| 974 | |
| 975 | // Introduce failure by using dataSize that is < 0 |
| 976 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 977 | "must be greater than zero and less than or equal to 65536"); |
| 978 | m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData); |
| 979 | m_errorMonitor->VerifyFound(); |
| 980 | |
| 981 | // Introduce failure by using dataSize that is > 65536 |
| 982 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 983 | "must be greater than zero and less than or equal to 65536"); |
| 984 | m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData); |
| 985 | m_errorMonitor->VerifyFound(); |
| 986 | |
| 987 | EndCommandBuffer(); |
| 988 | } |
| 989 | |
| 990 | TEST_F(VkLayerTest, FillBufferAlignment) { |
| 991 | TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer"); |
| 992 | |
| 993 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 994 | |
| 995 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 996 | vk_testing::Buffer buffer; |
| 997 | buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs); |
| 998 | |
| 999 | BeginCommandBuffer(); |
| 1000 | |
| 1001 | // Introduce failure by using dstOffset that is not multiple of 4 |
| 1002 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1003 | " is not a multiple of 4"); |
| 1004 | m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111); |
| 1005 | m_errorMonitor->VerifyFound(); |
| 1006 | |
| 1007 | // Introduce failure by using size that is not multiple of 4 |
| 1008 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1009 | " is not a multiple of 4"); |
| 1010 | m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111); |
| 1011 | m_errorMonitor->VerifyFound(); |
| 1012 | |
| 1013 | // Introduce failure by using size that is zero |
| 1014 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1015 | "must be greater than zero"); |
| 1016 | m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111); |
| 1017 | m_errorMonitor->VerifyFound(); |
| 1018 | |
| 1019 | EndCommandBuffer(); |
| 1020 | } |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 1021 | #endif // PARAMETER_VALIDATION_TESTS |
| 1022 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 1023 | #if MEM_TRACKER_TESTS |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 1024 | #if 0 |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1025 | TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion) |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1026 | { |
| 1027 | vk_testing::Fence testFence; |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1028 | VkFenceCreateInfo fenceInfo = {}; |
| 1029 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 1030 | fenceInfo.pNext = NULL; |
| 1031 | fenceInfo.flags = 0; |
| 1032 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1033 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 1034 | |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1035 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tony Barbour | c1eb1a5 | 2015-07-20 13:00:10 -0600 | [diff] [blame] | 1036 | |
| 1037 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 1038 | vk_testing::Buffer buffer; |
| 1039 | buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1040 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1041 | BeginCommandBuffer(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1042 | m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1043 | EndCommandBuffer(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1044 | |
| 1045 | testFence.init(*m_device, fenceInfo); |
| 1046 | |
| 1047 | // Bypass framework since it does the waits automatically |
| 1048 | VkResult err = VK_SUCCESS; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1049 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 1050 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 1051 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1052 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1053 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 1054 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1055 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1056 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1057 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1058 | submit_info.pSignalSemaphores = NULL; |
Courtney Goeltzenleuchter | 646b907 | 2015-10-20 18:04:07 -0600 | [diff] [blame] | 1059 | |
| 1060 | err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle()); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1061 | ASSERT_VK_SUCCESS( err ); |
| 1062 | |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1063 | // Introduce failure by calling begin again before checking fence |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1064 | vkResetCommandBuffer(m_commandBuffer->handle(), 0); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1065 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 1066 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1067 | } |
| 1068 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1069 | TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion) |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1070 | { |
| 1071 | vk_testing::Fence testFence; |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1072 | VkFenceCreateInfo fenceInfo = {}; |
| 1073 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 1074 | fenceInfo.pNext = NULL; |
| 1075 | fenceInfo.flags = 0; |
| 1076 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1077 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 1078 | |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1079 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1080 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1081 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 1082 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1083 | BeginCommandBuffer(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1084 | m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1085 | EndCommandBuffer(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1086 | |
| 1087 | testFence.init(*m_device, fenceInfo); |
| 1088 | |
| 1089 | // Bypass framework since it does the waits automatically |
| 1090 | VkResult err = VK_SUCCESS; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1091 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 1092 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 1093 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1094 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1095 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 1096 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1097 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1098 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1099 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1100 | submit_info.pSignalSemaphores = NULL; |
Courtney Goeltzenleuchter | 646b907 | 2015-10-20 18:04:07 -0600 | [diff] [blame] | 1101 | |
| 1102 | err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle()); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1103 | ASSERT_VK_SUCCESS( err ); |
| 1104 | |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 1105 | VkCommandBufferInheritanceInfo hinfo = {}; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1106 | VkCommandBufferBeginInfo info = {}; |
| 1107 | info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
| 1108 | info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 1109 | info.renderPass = VK_NULL_HANDLE; |
| 1110 | info.subpass = 0; |
| 1111 | info.framebuffer = VK_NULL_HANDLE; |
Chia-I Wu | b8d47ae | 2015-11-11 10:18:12 +0800 | [diff] [blame] | 1112 | info.occlusionQueryEnable = VK_FALSE; |
| 1113 | info.queryFlags = 0; |
| 1114 | info.pipelineStatistics = 0; |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 1115 | |
| 1116 | // Introduce failure by calling BCB again before checking fence |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1117 | vkBeginCommandBuffer(m_commandBuffer->handle(), &info); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1118 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 1119 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1120 | } |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 1121 | #endif |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 1122 | |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1123 | // This is a positive test. No failures are expected. |
| 1124 | TEST_F(VkLayerTest, TestAliasedMemoryTracking) { |
| 1125 | VkResult err; |
| 1126 | bool pass; |
| 1127 | |
| 1128 | TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy " |
| 1129 | "the buffer, create an image, and bind the same memory to " |
| 1130 | "it"); |
| 1131 | |
| 1132 | m_errorMonitor->ExpectSuccess(); |
| 1133 | |
| 1134 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1135 | |
| 1136 | VkBuffer buffer; |
| 1137 | VkImage image; |
| 1138 | VkDeviceMemory mem; |
| 1139 | VkMemoryRequirements mem_reqs; |
| 1140 | |
| 1141 | VkBufferCreateInfo buf_info = {}; |
| 1142 | buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1143 | buf_info.pNext = NULL; |
| 1144 | buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 1145 | buf_info.size = 256; |
| 1146 | buf_info.queueFamilyIndexCount = 0; |
| 1147 | buf_info.pQueueFamilyIndices = NULL; |
| 1148 | buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1149 | buf_info.flags = 0; |
| 1150 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer); |
| 1151 | ASSERT_VK_SUCCESS(err); |
| 1152 | |
| 1153 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs); |
| 1154 | |
| 1155 | VkMemoryAllocateInfo alloc_info = {}; |
| 1156 | alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1157 | alloc_info.pNext = NULL; |
| 1158 | alloc_info.memoryTypeIndex = 0; |
| 1159 | |
| 1160 | // Ensure memory is big enough for both bindings |
| 1161 | alloc_info.allocationSize = 0x10000; |
| 1162 | |
| 1163 | pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, |
| 1164 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 1165 | if (!pass) { |
| 1166 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1167 | return; |
| 1168 | } |
| 1169 | |
| 1170 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem); |
| 1171 | ASSERT_VK_SUCCESS(err); |
| 1172 | |
| 1173 | uint8_t *pData; |
| 1174 | err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, |
| 1175 | (void **)&pData); |
| 1176 | ASSERT_VK_SUCCESS(err); |
| 1177 | |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 1178 | memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size)); |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1179 | |
| 1180 | vkUnmapMemory(m_device->device(), mem); |
| 1181 | |
| 1182 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 1183 | ASSERT_VK_SUCCESS(err); |
| 1184 | |
| 1185 | // NOW, destroy the buffer. Obviously, the resource no longer occupies this |
| 1186 | // memory. In fact, it was never used by the GPU. |
| 1187 | // Just be be sure, wait for idle. |
| 1188 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1189 | vkDeviceWaitIdle(m_device->device()); |
| 1190 | |
| 1191 | VkImageCreateInfo image_create_info = {}; |
| 1192 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 1193 | image_create_info.pNext = NULL; |
| 1194 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 1195 | image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 1196 | image_create_info.extent.width = 64; |
| 1197 | image_create_info.extent.height = 64; |
| 1198 | image_create_info.extent.depth = 1; |
| 1199 | image_create_info.mipLevels = 1; |
| 1200 | image_create_info.arrayLayers = 1; |
| 1201 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 1202 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 1203 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 1204 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 1205 | image_create_info.queueFamilyIndexCount = 0; |
| 1206 | image_create_info.pQueueFamilyIndices = NULL; |
| 1207 | image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1208 | image_create_info.flags = 0; |
| 1209 | |
| 1210 | VkMemoryAllocateInfo mem_alloc = {}; |
| 1211 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1212 | mem_alloc.pNext = NULL; |
| 1213 | mem_alloc.allocationSize = 0; |
| 1214 | mem_alloc.memoryTypeIndex = 0; |
| 1215 | |
| 1216 | /* Create a mappable image. It will be the texture if linear images are ok |
| 1217 | * to be textures or it will be the staging image if they are not. |
| 1218 | */ |
| 1219 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 1220 | ASSERT_VK_SUCCESS(err); |
| 1221 | |
| 1222 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 1223 | |
| 1224 | mem_alloc.allocationSize = mem_reqs.size; |
| 1225 | |
| 1226 | pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, |
| 1227 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 1228 | if (!pass) { |
| 1229 | vkDestroyImage(m_device->device(), image, NULL); |
| 1230 | return; |
| 1231 | } |
| 1232 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1233 | // VALIDATION FAILURE: |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1234 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 1235 | ASSERT_VK_SUCCESS(err); |
| 1236 | |
| 1237 | m_errorMonitor->VerifyNotFound(); |
| 1238 | |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 1239 | vkFreeMemory(m_device->device(), mem, NULL); |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1240 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1241 | vkDestroyImage(m_device->device(), image, NULL); |
| 1242 | } |
| 1243 | |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1244 | TEST_F(VkLayerTest, InvalidMemoryAliasing) { |
| 1245 | TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the " |
| 1246 | "buffer and image to memory such that they will alias."); |
| 1247 | VkResult err; |
| 1248 | bool pass; |
| 1249 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1250 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1251 | VkBuffer buffer, buffer2; |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1252 | VkImage image; |
| 1253 | VkDeviceMemory mem; // buffer will be bound first |
| 1254 | VkDeviceMemory mem_img; // image bound first |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1255 | VkMemoryRequirements buff_mem_reqs, img_mem_reqs; |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1256 | |
| 1257 | VkBufferCreateInfo buf_info = {}; |
| 1258 | buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1259 | buf_info.pNext = NULL; |
| 1260 | buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 1261 | buf_info.size = 256; |
| 1262 | buf_info.queueFamilyIndexCount = 0; |
| 1263 | buf_info.pQueueFamilyIndices = NULL; |
| 1264 | buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1265 | buf_info.flags = 0; |
| 1266 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer); |
| 1267 | ASSERT_VK_SUCCESS(err); |
| 1268 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1269 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1270 | |
| 1271 | VkImageCreateInfo image_create_info = {}; |
| 1272 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 1273 | image_create_info.pNext = NULL; |
| 1274 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 1275 | image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 1276 | image_create_info.extent.width = 64; |
| 1277 | image_create_info.extent.height = 64; |
| 1278 | image_create_info.extent.depth = 1; |
| 1279 | image_create_info.mipLevels = 1; |
| 1280 | image_create_info.arrayLayers = 1; |
| 1281 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 1282 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 1283 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 1284 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 1285 | image_create_info.queueFamilyIndexCount = 0; |
| 1286 | image_create_info.pQueueFamilyIndices = NULL; |
| 1287 | image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1288 | image_create_info.flags = 0; |
| 1289 | |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1290 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 1291 | ASSERT_VK_SUCCESS(err); |
| 1292 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1293 | vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs); |
| 1294 | |
| 1295 | VkMemoryAllocateInfo alloc_info = {}; |
| 1296 | alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1297 | alloc_info.pNext = NULL; |
| 1298 | alloc_info.memoryTypeIndex = 0; |
| 1299 | // Ensure memory is big enough for both bindings |
| 1300 | alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size; |
| 1301 | pass = m_device->phy().set_memory_type( |
| 1302 | buff_mem_reqs.memoryTypeBits | img_mem_reqs.memoryTypeBits, &alloc_info, |
| 1303 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1304 | if (!pass) { |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1305 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1306 | vkDestroyImage(m_device->device(), image, NULL); |
| 1307 | return; |
| 1308 | } |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1309 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem); |
| 1310 | ASSERT_VK_SUCCESS(err); |
| 1311 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 1312 | ASSERT_VK_SUCCESS(err); |
| 1313 | |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1314 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1315 | " is aliased with buffer 0x"); |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1316 | // VALIDATION FAILURE due to image mapping overlapping buffer mapping |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1317 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 1318 | m_errorMonitor->VerifyFound(); |
| 1319 | |
| 1320 | // Now correctly bind image to second mem allocation before incorrectly |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1321 | // aliasing buffer2 |
| 1322 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2); |
| 1323 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1324 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img); |
| 1325 | ASSERT_VK_SUCCESS(err); |
| 1326 | err = vkBindImageMemory(m_device->device(), image, mem_img, 0); |
| 1327 | ASSERT_VK_SUCCESS(err); |
| 1328 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1329 | " is aliased with image 0x"); |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1330 | err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1331 | m_errorMonitor->VerifyFound(); |
| 1332 | |
| 1333 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1334 | vkDestroyBuffer(m_device->device(), buffer2, NULL); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1335 | vkDestroyImage(m_device->device(), image, NULL); |
| 1336 | vkFreeMemory(m_device->device(), mem, NULL); |
| 1337 | vkFreeMemory(m_device->device(), mem_img, NULL); |
| 1338 | } |
| 1339 | |
Tobin Ehlis | 3537252 | 2016-05-12 08:32:31 -0600 | [diff] [blame] | 1340 | TEST_F(VkLayerTest, InvalidMemoryMapping) { |
| 1341 | TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways"); |
| 1342 | VkResult err; |
| 1343 | bool pass; |
| 1344 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1345 | |
| 1346 | VkBuffer buffer; |
| 1347 | VkDeviceMemory mem; |
| 1348 | VkMemoryRequirements mem_reqs; |
| 1349 | |
| 1350 | VkBufferCreateInfo buf_info = {}; |
| 1351 | buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1352 | buf_info.pNext = NULL; |
| 1353 | buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 1354 | buf_info.size = 256; |
| 1355 | buf_info.queueFamilyIndexCount = 0; |
| 1356 | buf_info.pQueueFamilyIndices = NULL; |
| 1357 | buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1358 | buf_info.flags = 0; |
| 1359 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer); |
| 1360 | ASSERT_VK_SUCCESS(err); |
| 1361 | |
| 1362 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs); |
| 1363 | VkMemoryAllocateInfo alloc_info = {}; |
| 1364 | alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1365 | alloc_info.pNext = NULL; |
| 1366 | alloc_info.memoryTypeIndex = 0; |
| 1367 | |
| 1368 | // Ensure memory is big enough for both bindings |
| 1369 | static const VkDeviceSize allocation_size = 0x10000; |
| 1370 | alloc_info.allocationSize = allocation_size; |
| 1371 | pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, |
| 1372 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 1373 | if (!pass) { |
| 1374 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1375 | return; |
| 1376 | } |
| 1377 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem); |
| 1378 | ASSERT_VK_SUCCESS(err); |
| 1379 | |
| 1380 | uint8_t *pData; |
| 1381 | // Attempt to map memory size 0 is invalid |
| 1382 | m_errorMonitor->SetDesiredFailureMsg( |
| 1383 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1384 | "VkMapMemory: Attempting to map memory range of size zero"); |
| 1385 | err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData); |
| 1386 | m_errorMonitor->VerifyFound(); |
| 1387 | // Map memory twice |
| 1388 | err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, |
| 1389 | (void **)&pData); |
| 1390 | ASSERT_VK_SUCCESS(err); |
| 1391 | m_errorMonitor->SetDesiredFailureMsg( |
| 1392 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1393 | "VkMapMemory: Attempting to map memory on an already-mapped object "); |
| 1394 | err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, |
| 1395 | (void **)&pData); |
| 1396 | m_errorMonitor->VerifyFound(); |
| 1397 | |
| 1398 | // Unmap the memory to avoid re-map error |
| 1399 | vkUnmapMemory(m_device->device(), mem); |
| 1400 | // overstep allocation with VK_WHOLE_SIZE |
| 1401 | m_errorMonitor->SetDesiredFailureMsg( |
| 1402 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1403 | " with size of VK_WHOLE_SIZE oversteps total array size 0x"); |
| 1404 | err = vkMapMemory(m_device->device(), mem, allocation_size + 1, |
| 1405 | VK_WHOLE_SIZE, 0, (void **)&pData); |
| 1406 | m_errorMonitor->VerifyFound(); |
| 1407 | // overstep allocation w/o VK_WHOLE_SIZE |
| 1408 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1409 | " oversteps total array size 0x"); |
| 1410 | err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, |
| 1411 | (void **)&pData); |
| 1412 | m_errorMonitor->VerifyFound(); |
| 1413 | // Now error due to unmapping memory that's not mapped |
| 1414 | m_errorMonitor->SetDesiredFailureMsg( |
| 1415 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1416 | "Unmapping Memory without memory being mapped: "); |
| 1417 | vkUnmapMemory(m_device->device(), mem); |
| 1418 | m_errorMonitor->VerifyFound(); |
| 1419 | // Now map memory and cause errors due to flushing invalid ranges |
| 1420 | err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0, |
| 1421 | (void **)&pData); |
| 1422 | ASSERT_VK_SUCCESS(err); |
| 1423 | VkMappedMemoryRange mmr = {}; |
Chris Forbes | 3aec089 | 2016-06-13 10:29:26 +1200 | [diff] [blame] | 1424 | mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; |
Tobin Ehlis | 3537252 | 2016-05-12 08:32:31 -0600 | [diff] [blame] | 1425 | mmr.memory = mem; |
| 1426 | mmr.offset = 15; // Error b/c offset less than offset of mapped mem |
| 1427 | m_errorMonitor->SetDesiredFailureMsg( |
| 1428 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1429 | ") is less than Memory Object's offset ("); |
| 1430 | vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr); |
| 1431 | m_errorMonitor->VerifyFound(); |
| 1432 | // Now flush range that oversteps mapped range |
| 1433 | vkUnmapMemory(m_device->device(), mem); |
| 1434 | err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData); |
| 1435 | ASSERT_VK_SUCCESS(err); |
| 1436 | mmr.offset = 16; |
| 1437 | mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256) |
| 1438 | m_errorMonitor->SetDesiredFailureMsg( |
| 1439 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1440 | ") exceeds the Memory Object's upper-bound ("); |
| 1441 | vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr); |
| 1442 | m_errorMonitor->VerifyFound(); |
| 1443 | |
| 1444 | pass = |
| 1445 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, |
| 1446 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, |
| 1447 | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); |
| 1448 | if (!pass) { |
| 1449 | vkFreeMemory(m_device->device(), mem, NULL); |
| 1450 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1451 | return; |
| 1452 | } |
| 1453 | // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of |
| 1454 | // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver() |
| 1455 | |
| 1456 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1457 | vkFreeMemory(m_device->device(), mem, NULL); |
| 1458 | } |
| 1459 | |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1460 | TEST_F(VkLayerTest, EnableWsiBeforeUse) { |
| 1461 | VkResult err; |
| 1462 | bool pass; |
| 1463 | |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1464 | // FIXME: After we turn on this code for non-Linux platforms, uncomment the |
| 1465 | // following declaration (which is temporarily being moved below): |
| 1466 | // VkSurfaceKHR surface = VK_NULL_HANDLE; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1467 | VkSwapchainKHR swapchain = VK_NULL_HANDLE; |
| 1468 | VkSwapchainCreateInfoKHR swapchain_create_info = {}; |
| 1469 | uint32_t swapchain_image_count = 0; |
| 1470 | // VkImage swapchain_images[1] = {VK_NULL_HANDLE}; |
| 1471 | uint32_t image_index = 0; |
| 1472 | // VkPresentInfoKHR present_info = {}; |
| 1473 | |
| 1474 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1475 | |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1476 | #ifdef NEED_TO_TEST_THIS_ON_PLATFORM |
| 1477 | #if defined(VK_USE_PLATFORM_ANDROID_KHR) |
| 1478 | // Use the functions from the VK_KHR_android_surface extension without |
| 1479 | // enabling that extension: |
| 1480 | |
| 1481 | // Create a surface: |
| 1482 | VkAndroidSurfaceCreateInfoKHR android_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1483 | m_errorMonitor->SetDesiredFailureMsg( |
| 1484 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1485 | "extension was not enabled for this"); |
| 1486 | err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, |
| 1487 | &surface); |
| 1488 | pass = (err != VK_SUCCESS); |
| 1489 | ASSERT_TRUE(pass); |
| 1490 | m_errorMonitor->VerifyFound(); |
| 1491 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 1492 | |
| 1493 | |
| 1494 | #if defined(VK_USE_PLATFORM_MIR_KHR) |
| 1495 | // Use the functions from the VK_KHR_mir_surface extension without enabling |
| 1496 | // that extension: |
| 1497 | |
| 1498 | // Create a surface: |
| 1499 | VkMirSurfaceCreateInfoKHR mir_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1500 | m_errorMonitor->SetDesiredFailureMsg( |
| 1501 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1502 | "extension was not enabled for this"); |
| 1503 | err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface); |
| 1504 | pass = (err != VK_SUCCESS); |
| 1505 | ASSERT_TRUE(pass); |
| 1506 | m_errorMonitor->VerifyFound(); |
| 1507 | |
| 1508 | // Tell whether an mir_connection supports presentation: |
| 1509 | MirConnection *mir_connection = NULL; |
| 1510 | m_errorMonitor->SetDesiredFailureMsg( |
| 1511 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1512 | "extension was not enabled for this"); |
| 1513 | vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, |
| 1514 | visual_id); |
| 1515 | m_errorMonitor->VerifyFound(); |
| 1516 | #endif // VK_USE_PLATFORM_MIR_KHR |
| 1517 | |
| 1518 | |
| 1519 | #if defined(VK_USE_PLATFORM_WAYLAND_KHR) |
| 1520 | // Use the functions from the VK_KHR_wayland_surface extension without |
| 1521 | // enabling that extension: |
| 1522 | |
| 1523 | // Create a surface: |
| 1524 | VkWaylandSurfaceCreateInfoKHR wayland_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1525 | m_errorMonitor->SetDesiredFailureMsg( |
| 1526 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1527 | "extension was not enabled for this"); |
| 1528 | err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, |
| 1529 | &surface); |
| 1530 | pass = (err != VK_SUCCESS); |
| 1531 | ASSERT_TRUE(pass); |
| 1532 | m_errorMonitor->VerifyFound(); |
| 1533 | |
| 1534 | // Tell whether an wayland_display supports presentation: |
| 1535 | struct wl_display wayland_display = {}; |
| 1536 | m_errorMonitor->SetDesiredFailureMsg( |
| 1537 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1538 | "extension was not enabled for this"); |
| 1539 | vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, |
| 1540 | &wayland_display); |
| 1541 | m_errorMonitor->VerifyFound(); |
| 1542 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1543 | #endif // NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1544 | |
| 1545 | |
| 1546 | #if defined(VK_USE_PLATFORM_WIN32_KHR) |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1547 | // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED |
| 1548 | // TO NON-LINUX PLATFORMS: |
| 1549 | VkSurfaceKHR surface = VK_NULL_HANDLE; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1550 | // Use the functions from the VK_KHR_win32_surface extension without |
| 1551 | // enabling that extension: |
| 1552 | |
| 1553 | // Create a surface: |
| 1554 | VkWin32SurfaceCreateInfoKHR win32_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1555 | m_errorMonitor->SetDesiredFailureMsg( |
| 1556 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1557 | "extension was not enabled for this"); |
| 1558 | err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, |
| 1559 | &surface); |
| 1560 | pass = (err != VK_SUCCESS); |
| 1561 | ASSERT_TRUE(pass); |
| 1562 | m_errorMonitor->VerifyFound(); |
| 1563 | |
| 1564 | // Tell whether win32 supports presentation: |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1565 | m_errorMonitor->SetDesiredFailureMsg( |
| 1566 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1567 | "extension was not enabled for this"); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1568 | vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0); |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1569 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1570 | // Set this (for now, until all platforms are supported and tested): |
| 1571 | #define NEED_TO_TEST_THIS_ON_PLATFORM |
| 1572 | #endif // VK_USE_PLATFORM_WIN32_KHR |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1573 | |
| 1574 | |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1575 | #if defined(VK_USE_PLATFORM_XCB_KHR) |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1576 | // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED |
| 1577 | // TO NON-LINUX PLATFORMS: |
| 1578 | VkSurfaceKHR surface = VK_NULL_HANDLE; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1579 | // Use the functions from the VK_KHR_xcb_surface extension without enabling |
| 1580 | // that extension: |
| 1581 | |
| 1582 | // Create a surface: |
| 1583 | VkXcbSurfaceCreateInfoKHR xcb_create_info = {}; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1584 | m_errorMonitor->SetDesiredFailureMsg( |
| 1585 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1586 | "extension was not enabled for this"); |
| 1587 | err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface); |
| 1588 | pass = (err != VK_SUCCESS); |
| 1589 | ASSERT_TRUE(pass); |
| 1590 | m_errorMonitor->VerifyFound(); |
| 1591 | |
| 1592 | // Tell whether an xcb_visualid_t supports presentation: |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1593 | xcb_connection_t *xcb_connection = NULL; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1594 | xcb_visualid_t visual_id = 0; |
| 1595 | m_errorMonitor->SetDesiredFailureMsg( |
| 1596 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1597 | "extension was not enabled for this"); |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1598 | vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1599 | visual_id); |
| 1600 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1601 | // Set this (for now, until all platforms are supported and tested): |
| 1602 | #define NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1603 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 1604 | |
| 1605 | |
Ian Elliott | 1263081 | 2016-04-29 14:35:43 -0600 | [diff] [blame] | 1606 | #if defined(VK_USE_PLATFORM_XLIB_KHR) |
| 1607 | // Use the functions from the VK_KHR_xlib_surface extension without enabling |
| 1608 | // that extension: |
| 1609 | |
| 1610 | // Create a surface: |
| 1611 | VkXlibSurfaceCreateInfoKHR xlib_create_info = {}; |
Ian Elliott | 1263081 | 2016-04-29 14:35:43 -0600 | [diff] [blame] | 1612 | m_errorMonitor->SetDesiredFailureMsg( |
| 1613 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1614 | "extension was not enabled for this"); |
| 1615 | err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface); |
| 1616 | pass = (err != VK_SUCCESS); |
| 1617 | ASSERT_TRUE(pass); |
| 1618 | m_errorMonitor->VerifyFound(); |
| 1619 | |
| 1620 | // Tell whether an Xlib VisualID supports presentation: |
| 1621 | Display *dpy = NULL; |
| 1622 | VisualID visual = 0; |
| 1623 | m_errorMonitor->SetDesiredFailureMsg( |
| 1624 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1625 | "extension was not enabled for this"); |
| 1626 | vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual); |
| 1627 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1628 | // Set this (for now, until all platforms are supported and tested): |
| 1629 | #define NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1263081 | 2016-04-29 14:35:43 -0600 | [diff] [blame] | 1630 | #endif // VK_USE_PLATFORM_XLIB_KHR |
| 1631 | |
| 1632 | |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1633 | // Use the functions from the VK_KHR_surface extension without enabling |
| 1634 | // that extension: |
| 1635 | |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1636 | #ifdef NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1637 | // Destroy a surface: |
| 1638 | m_errorMonitor->SetDesiredFailureMsg( |
| 1639 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1640 | "extension was not enabled for this"); |
| 1641 | vkDestroySurfaceKHR(instance(), surface, NULL); |
| 1642 | m_errorMonitor->VerifyFound(); |
| 1643 | |
| 1644 | // Check if surface supports presentation: |
| 1645 | VkBool32 supported = false; |
| 1646 | m_errorMonitor->SetDesiredFailureMsg( |
| 1647 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1648 | "extension was not enabled for this"); |
| 1649 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported); |
| 1650 | pass = (err != VK_SUCCESS); |
| 1651 | ASSERT_TRUE(pass); |
| 1652 | m_errorMonitor->VerifyFound(); |
| 1653 | |
| 1654 | // Check surface capabilities: |
| 1655 | VkSurfaceCapabilitiesKHR capabilities = {}; |
| 1656 | m_errorMonitor->SetDesiredFailureMsg( |
| 1657 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1658 | "extension was not enabled for this"); |
| 1659 | err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, |
| 1660 | &capabilities); |
| 1661 | pass = (err != VK_SUCCESS); |
| 1662 | ASSERT_TRUE(pass); |
| 1663 | m_errorMonitor->VerifyFound(); |
| 1664 | |
| 1665 | // Check surface formats: |
| 1666 | uint32_t format_count = 0; |
| 1667 | VkSurfaceFormatKHR *formats = NULL; |
| 1668 | m_errorMonitor->SetDesiredFailureMsg( |
| 1669 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1670 | "extension was not enabled for this"); |
| 1671 | err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, |
| 1672 | &format_count, formats); |
| 1673 | pass = (err != VK_SUCCESS); |
| 1674 | ASSERT_TRUE(pass); |
| 1675 | m_errorMonitor->VerifyFound(); |
| 1676 | |
| 1677 | // Check surface present modes: |
| 1678 | uint32_t present_mode_count = 0; |
| 1679 | VkSurfaceFormatKHR *present_modes = NULL; |
| 1680 | m_errorMonitor->SetDesiredFailureMsg( |
| 1681 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1682 | "extension was not enabled for this"); |
| 1683 | err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, |
| 1684 | &present_mode_count, present_modes); |
| 1685 | pass = (err != VK_SUCCESS); |
| 1686 | ASSERT_TRUE(pass); |
| 1687 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1688 | #endif // NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1689 | |
| 1690 | |
| 1691 | // Use the functions from the VK_KHR_swapchain extension without enabling |
| 1692 | // that extension: |
| 1693 | |
| 1694 | // Create a swapchain: |
| 1695 | m_errorMonitor->SetDesiredFailureMsg( |
| 1696 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1697 | "extension was not enabled for this"); |
| 1698 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 1699 | swapchain_create_info.pNext = NULL; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1700 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, |
| 1701 | NULL, &swapchain); |
| 1702 | pass = (err != VK_SUCCESS); |
| 1703 | ASSERT_TRUE(pass); |
| 1704 | m_errorMonitor->VerifyFound(); |
| 1705 | |
| 1706 | // Get the images from the swapchain: |
| 1707 | m_errorMonitor->SetDesiredFailureMsg( |
| 1708 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1709 | "extension was not enabled for this"); |
| 1710 | err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, |
| 1711 | &swapchain_image_count, NULL); |
| 1712 | pass = (err != VK_SUCCESS); |
| 1713 | ASSERT_TRUE(pass); |
| 1714 | m_errorMonitor->VerifyFound(); |
| 1715 | |
| 1716 | // Try to acquire an image: |
| 1717 | m_errorMonitor->SetDesiredFailureMsg( |
| 1718 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1719 | "extension was not enabled for this"); |
| 1720 | err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, |
| 1721 | VK_NULL_HANDLE, VK_NULL_HANDLE, &image_index); |
| 1722 | pass = (err != VK_SUCCESS); |
| 1723 | ASSERT_TRUE(pass); |
| 1724 | m_errorMonitor->VerifyFound(); |
| 1725 | |
| 1726 | // Try to present an image: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1727 | // |
| 1728 | // NOTE: Currently can't test this because a real swapchain is needed (as |
| 1729 | // opposed to the fake one we created) in order for the layer to lookup the |
| 1730 | // VkDevice used to enable the extension: |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1731 | |
| 1732 | // Destroy the swapchain: |
| 1733 | m_errorMonitor->SetDesiredFailureMsg( |
| 1734 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1735 | "extension was not enabled for this"); |
| 1736 | vkDestroySwapchainKHR(m_device->device(), swapchain, NULL); |
| 1737 | m_errorMonitor->VerifyFound(); |
| 1738 | } |
| 1739 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1740 | TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) { |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1741 | |
Dustin Graves | 6c6d898 | 2016-05-17 10:09:21 -0600 | [diff] [blame] | 1742 | #if defined(VK_USE_PLATFORM_XCB_KHR) |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1743 | VkSurfaceKHR surface = VK_NULL_HANDLE; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1744 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1745 | VkResult err; |
| 1746 | bool pass; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1747 | VkSwapchainKHR swapchain = VK_NULL_HANDLE; |
| 1748 | VkSwapchainCreateInfoKHR swapchain_create_info = {}; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1749 | // uint32_t swapchain_image_count = 0; |
| 1750 | // VkImage swapchain_images[1] = {VK_NULL_HANDLE}; |
| 1751 | // uint32_t image_index = 0; |
| 1752 | // VkPresentInfoKHR present_info = {}; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1753 | |
| 1754 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1755 | |
| 1756 | // Use the create function from one of the VK_KHR_*_surface extension in |
| 1757 | // order to create a surface, testing all known errors in the process, |
| 1758 | // before successfully creating a surface: |
| 1759 | // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1760 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1761 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1762 | err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface); |
| 1763 | pass = (err != VK_SUCCESS); |
| 1764 | ASSERT_TRUE(pass); |
| 1765 | m_errorMonitor->VerifyFound(); |
| 1766 | |
| 1767 | // Next, try to create a surface with the wrong |
| 1768 | // VkXcbSurfaceCreateInfoKHR::sType: |
| 1769 | VkXcbSurfaceCreateInfoKHR xcb_create_info = {}; |
| 1770 | xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1771 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1772 | "called with the wrong value for"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1773 | err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface); |
| 1774 | pass = (err != VK_SUCCESS); |
| 1775 | ASSERT_TRUE(pass); |
| 1776 | m_errorMonitor->VerifyFound(); |
| 1777 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1778 | // Create a native window, and then correctly create a surface: |
| 1779 | xcb_connection_t *connection; |
| 1780 | xcb_screen_t *screen; |
| 1781 | xcb_window_t xcb_window; |
| 1782 | xcb_intern_atom_reply_t *atom_wm_delete_window; |
| 1783 | |
| 1784 | const xcb_setup_t *setup; |
| 1785 | xcb_screen_iterator_t iter; |
| 1786 | int scr; |
| 1787 | uint32_t value_mask, value_list[32]; |
| 1788 | int width = 1; |
| 1789 | int height = 1; |
| 1790 | |
| 1791 | connection = xcb_connect(NULL, &scr); |
| 1792 | ASSERT_TRUE(connection != NULL); |
| 1793 | setup = xcb_get_setup(connection); |
| 1794 | iter = xcb_setup_roots_iterator(setup); |
| 1795 | while (scr-- > 0) |
| 1796 | xcb_screen_next(&iter); |
| 1797 | screen = iter.data; |
| 1798 | |
| 1799 | xcb_window = xcb_generate_id(connection); |
| 1800 | |
| 1801 | value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; |
| 1802 | value_list[0] = screen->black_pixel; |
| 1803 | value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | |
| 1804 | XCB_EVENT_MASK_STRUCTURE_NOTIFY; |
| 1805 | |
| 1806 | xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, |
| 1807 | screen->root, 0, 0, width, height, 0, |
| 1808 | XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, |
| 1809 | value_mask, value_list); |
| 1810 | |
| 1811 | /* Magic code that will send notification when window is destroyed */ |
| 1812 | xcb_intern_atom_cookie_t cookie = |
| 1813 | xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS"); |
| 1814 | xcb_intern_atom_reply_t *reply = |
| 1815 | xcb_intern_atom_reply(connection, cookie, 0); |
| 1816 | |
| 1817 | xcb_intern_atom_cookie_t cookie2 = |
| 1818 | xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW"); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1819 | atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1820 | xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, |
| 1821 | (*reply).atom, 4, 32, 1, |
| 1822 | &(*atom_wm_delete_window).atom); |
| 1823 | free(reply); |
| 1824 | |
| 1825 | xcb_map_window(connection, xcb_window); |
| 1826 | |
| 1827 | // Force the x/y coordinates to 100,100 results are identical in consecutive |
| 1828 | // runs |
| 1829 | const uint32_t coords[] = {100, 100}; |
| 1830 | xcb_configure_window(connection, xcb_window, |
| 1831 | XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords); |
| 1832 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1833 | // Finally, try to correctly create a surface: |
| 1834 | xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; |
| 1835 | xcb_create_info.pNext = NULL; |
| 1836 | xcb_create_info.flags = 0; |
| 1837 | xcb_create_info.connection = connection; |
| 1838 | xcb_create_info.window = xcb_window; |
| 1839 | err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface); |
| 1840 | pass = (err == VK_SUCCESS); |
| 1841 | ASSERT_TRUE(pass); |
| 1842 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1843 | // Check if surface supports presentation: |
| 1844 | |
| 1845 | // 1st, do so without having queried the queue families: |
| 1846 | VkBool32 supported = false; |
| 1847 | // TODO: Get the following error to come out: |
| 1848 | m_errorMonitor->SetDesiredFailureMsg( |
| 1849 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1850 | "called before calling the vkGetPhysicalDeviceQueueFamilyProperties " |
| 1851 | "function"); |
| 1852 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported); |
| 1853 | pass = (err != VK_SUCCESS); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1854 | // ASSERT_TRUE(pass); |
| 1855 | // m_errorMonitor->VerifyFound(); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1856 | |
| 1857 | // Next, query a queue family index that's too large: |
| 1858 | m_errorMonitor->SetDesiredFailureMsg( |
| 1859 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1860 | "called with a queueFamilyIndex that is too large"); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1861 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, |
| 1862 | &supported); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1863 | pass = (err != VK_SUCCESS); |
| 1864 | ASSERT_TRUE(pass); |
| 1865 | m_errorMonitor->VerifyFound(); |
| 1866 | |
| 1867 | // Finally, do so correctly: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1868 | // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S |
| 1869 | // SUPPORTED |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1870 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported); |
| 1871 | pass = (err == VK_SUCCESS); |
| 1872 | ASSERT_TRUE(pass); |
| 1873 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1874 | // Before proceeding, try to create a swapchain without having called |
| 1875 | // vkGetPhysicalDeviceSurfaceCapabilitiesKHR(): |
| 1876 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 1877 | swapchain_create_info.pNext = NULL; |
| 1878 | swapchain_create_info.flags = 0; |
| 1879 | m_errorMonitor->SetDesiredFailureMsg( |
| 1880 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1881 | "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR()."); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1882 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 1883 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1884 | pass = (err != VK_SUCCESS); |
| 1885 | ASSERT_TRUE(pass); |
| 1886 | m_errorMonitor->VerifyFound(); |
| 1887 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1888 | // Get the surface capabilities: |
| 1889 | VkSurfaceCapabilitiesKHR surface_capabilities; |
| 1890 | |
| 1891 | // Do so correctly (only error logged by this entrypoint is if the |
| 1892 | // extension isn't enabled): |
| 1893 | err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, |
| 1894 | &surface_capabilities); |
| 1895 | pass = (err == VK_SUCCESS); |
| 1896 | ASSERT_TRUE(pass); |
| 1897 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1898 | // Get the surface formats: |
| 1899 | uint32_t surface_format_count; |
| 1900 | |
| 1901 | // First, try without a pointer to surface_format_count: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1902 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1903 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1904 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL); |
| 1905 | pass = (err == VK_SUCCESS); |
| 1906 | ASSERT_TRUE(pass); |
| 1907 | m_errorMonitor->VerifyFound(); |
| 1908 | |
| 1909 | // Next, call with a non-NULL pSurfaceFormats, even though we haven't |
| 1910 | // correctly done a 1st try (to get the count): |
| 1911 | m_errorMonitor->SetDesiredFailureMsg( |
| 1912 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1913 | "but no prior positive value has been seen for"); |
| 1914 | surface_format_count = 0; |
| 1915 | vkGetPhysicalDeviceSurfaceFormatsKHR( |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1916 | gpu(), surface, &surface_format_count, |
| 1917 | (VkSurfaceFormatKHR *)&surface_format_count); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1918 | pass = (err == VK_SUCCESS); |
| 1919 | ASSERT_TRUE(pass); |
| 1920 | m_errorMonitor->VerifyFound(); |
| 1921 | |
| 1922 | // Next, correctly do a 1st try (with a NULL pointer to surface_formats): |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1923 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
| 1924 | NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1925 | pass = (err == VK_SUCCESS); |
| 1926 | ASSERT_TRUE(pass); |
| 1927 | |
| 1928 | // Allocate memory for the correct number of VkSurfaceFormatKHR's: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1929 | VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc( |
| 1930 | surface_format_count * sizeof(VkSurfaceFormatKHR)); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1931 | |
| 1932 | // Next, do a 2nd try with surface_format_count being set too high: |
| 1933 | surface_format_count += 5; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1934 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1935 | "that is greater than the value"); |
| 1936 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1937 | surface_formats); |
| 1938 | pass = (err == VK_SUCCESS); |
| 1939 | ASSERT_TRUE(pass); |
| 1940 | m_errorMonitor->VerifyFound(); |
| 1941 | |
| 1942 | // Finally, do a correct 1st and 2nd try: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1943 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
| 1944 | NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1945 | pass = (err == VK_SUCCESS); |
| 1946 | ASSERT_TRUE(pass); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1947 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1948 | surface_formats); |
| 1949 | pass = (err == VK_SUCCESS); |
| 1950 | ASSERT_TRUE(pass); |
| 1951 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1952 | // Get the surface present modes: |
| 1953 | uint32_t surface_present_mode_count; |
| 1954 | |
| 1955 | // First, try without a pointer to surface_format_count: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1956 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1957 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1958 | vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL); |
| 1959 | pass = (err == VK_SUCCESS); |
| 1960 | ASSERT_TRUE(pass); |
| 1961 | m_errorMonitor->VerifyFound(); |
| 1962 | |
| 1963 | // Next, call with a non-NULL VkPresentModeKHR, even though we haven't |
| 1964 | // correctly done a 1st try (to get the count): |
| 1965 | m_errorMonitor->SetDesiredFailureMsg( |
| 1966 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1967 | "but no prior positive value has been seen for"); |
| 1968 | surface_present_mode_count = 0; |
| 1969 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1970 | gpu(), surface, &surface_present_mode_count, |
| 1971 | (VkPresentModeKHR *)&surface_present_mode_count); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1972 | pass = (err == VK_SUCCESS); |
| 1973 | ASSERT_TRUE(pass); |
| 1974 | m_errorMonitor->VerifyFound(); |
| 1975 | |
| 1976 | // Next, correctly do a 1st try (with a NULL pointer to surface_formats): |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1977 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 1978 | gpu(), surface, &surface_present_mode_count, NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1979 | pass = (err == VK_SUCCESS); |
| 1980 | ASSERT_TRUE(pass); |
| 1981 | |
| 1982 | // Allocate memory for the correct number of VkSurfaceFormatKHR's: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1983 | VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc( |
| 1984 | surface_present_mode_count * sizeof(VkPresentModeKHR)); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1985 | |
| 1986 | // Next, do a 2nd try with surface_format_count being set too high: |
| 1987 | surface_present_mode_count += 5; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1988 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1989 | "that is greater than the value"); |
| 1990 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 1991 | gpu(), surface, &surface_present_mode_count, surface_present_modes); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1992 | pass = (err == VK_SUCCESS); |
| 1993 | ASSERT_TRUE(pass); |
| 1994 | m_errorMonitor->VerifyFound(); |
| 1995 | |
| 1996 | // Finally, do a correct 1st and 2nd try: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1997 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 1998 | gpu(), surface, &surface_present_mode_count, NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1999 | pass = (err == VK_SUCCESS); |
| 2000 | ASSERT_TRUE(pass); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2001 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 2002 | gpu(), surface, &surface_present_mode_count, surface_present_modes); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2003 | pass = (err == VK_SUCCESS); |
| 2004 | ASSERT_TRUE(pass); |
| 2005 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2006 | // Create a swapchain: |
| 2007 | |
| 2008 | // First, try without a pointer to swapchain_create_info: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2009 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2010 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2011 | err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain); |
| 2012 | pass = (err != VK_SUCCESS); |
| 2013 | ASSERT_TRUE(pass); |
| 2014 | m_errorMonitor->VerifyFound(); |
| 2015 | |
| 2016 | // Next, call with a non-NULL swapchain_create_info, that has the wrong |
| 2017 | // sType: |
| 2018 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2019 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2020 | "called with the wrong value for"); |
| 2021 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2022 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2023 | pass = (err != VK_SUCCESS); |
| 2024 | ASSERT_TRUE(pass); |
| 2025 | m_errorMonitor->VerifyFound(); |
| 2026 | |
| 2027 | // Next, call with a NULL swapchain pointer: |
| 2028 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 2029 | swapchain_create_info.pNext = NULL; |
| 2030 | swapchain_create_info.flags = 0; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2031 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2032 | "called with NULL pointer"); |
| 2033 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2034 | NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2035 | pass = (err != VK_SUCCESS); |
| 2036 | ASSERT_TRUE(pass); |
| 2037 | m_errorMonitor->VerifyFound(); |
| 2038 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2039 | // TODO: Enhance swapchain layer so that |
| 2040 | // swapchain_create_info.queueFamilyIndexCount is checked against something? |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2041 | |
| 2042 | // Next, call with a queue family index that's too large: |
| 2043 | uint32_t queueFamilyIndex[2] = {100000, 0}; |
| 2044 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT; |
| 2045 | swapchain_create_info.queueFamilyIndexCount = 2; |
| 2046 | swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex; |
| 2047 | m_errorMonitor->SetDesiredFailureMsg( |
| 2048 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2049 | "called with a queueFamilyIndex that is too large"); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2050 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2051 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2052 | pass = (err != VK_SUCCESS); |
| 2053 | ASSERT_TRUE(pass); |
| 2054 | m_errorMonitor->VerifyFound(); |
| 2055 | |
| 2056 | // Next, call a queueFamilyIndexCount that's too small for CONCURRENT: |
| 2057 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT; |
| 2058 | swapchain_create_info.queueFamilyIndexCount = 1; |
| 2059 | m_errorMonitor->SetDesiredFailureMsg( |
| 2060 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2061 | "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or " |
| 2062 | "pCreateInfo->pQueueFamilyIndices)."); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2063 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2064 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2065 | pass = (err != VK_SUCCESS); |
| 2066 | ASSERT_TRUE(pass); |
| 2067 | m_errorMonitor->VerifyFound(); |
| 2068 | |
| 2069 | // Next, call with an invalid imageSharingMode: |
| 2070 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM; |
| 2071 | swapchain_create_info.queueFamilyIndexCount = 1; |
| 2072 | m_errorMonitor->SetDesiredFailureMsg( |
| 2073 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2074 | "called with a non-supported pCreateInfo->imageSharingMode (i.e."); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2075 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2076 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2077 | pass = (err != VK_SUCCESS); |
| 2078 | ASSERT_TRUE(pass); |
| 2079 | m_errorMonitor->VerifyFound(); |
| 2080 | // Fix for the future: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2081 | // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S |
| 2082 | // SUPPORTED |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2083 | swapchain_create_info.queueFamilyIndexCount = 0; |
| 2084 | queueFamilyIndex[0] = 0; |
| 2085 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 2086 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2087 | // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ... |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2088 | // Get the images from a swapchain: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2089 | // Acquire an image from a swapchain: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2090 | // Present an image to a swapchain: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2091 | // Destroy the swapchain: |
| 2092 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2093 | // TODOs: |
| 2094 | // |
| 2095 | // - Try destroying the device without first destroying the swapchain |
| 2096 | // |
| 2097 | // - Try destroying the device without first destroying the surface |
| 2098 | // |
| 2099 | // - Try destroying the surface without first destroying the swapchain |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2100 | |
| 2101 | // Destroy the surface: |
| 2102 | vkDestroySurfaceKHR(instance(), surface, NULL); |
| 2103 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2104 | // Tear down the window: |
| 2105 | xcb_destroy_window(connection, xcb_window); |
| 2106 | xcb_disconnect(connection); |
| 2107 | |
| 2108 | #else // VK_USE_PLATFORM_XCB_KHR |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2109 | return; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2110 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 2111 | } |
| 2112 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2113 | TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) { |
| 2114 | VkResult err; |
| 2115 | bool pass; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2116 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2117 | m_errorMonitor->SetDesiredFailureMsg( |
| 2118 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2119 | "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT"); |
| 2120 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2121 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2122 | |
| 2123 | // Create an image, allocate memory, free it, and then try to bind it |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2124 | VkImage image; |
| 2125 | VkDeviceMemory mem; |
| 2126 | VkMemoryRequirements mem_reqs; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2127 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2128 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2129 | const int32_t tex_width = 32; |
| 2130 | const int32_t tex_height = 32; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2131 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2132 | VkImageCreateInfo image_create_info = {}; |
| 2133 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2134 | image_create_info.pNext = NULL; |
| 2135 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2136 | image_create_info.format = tex_format; |
| 2137 | image_create_info.extent.width = tex_width; |
| 2138 | image_create_info.extent.height = tex_height; |
| 2139 | image_create_info.extent.depth = 1; |
| 2140 | image_create_info.mipLevels = 1; |
| 2141 | image_create_info.arrayLayers = 1; |
| 2142 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2143 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2144 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2145 | image_create_info.flags = 0; |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 2146 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2147 | VkMemoryAllocateInfo mem_alloc = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 2148 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2149 | mem_alloc.pNext = NULL; |
| 2150 | mem_alloc.allocationSize = 0; |
| 2151 | // Introduce failure, do NOT set memProps to |
| 2152 | // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
| 2153 | mem_alloc.memoryTypeIndex = 1; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2154 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2155 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2156 | ASSERT_VK_SUCCESS(err); |
| 2157 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2158 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2159 | |
Mark Lobodzinski | 2306535 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 2160 | mem_alloc.allocationSize = mem_reqs.size; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2161 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2162 | pass = |
| 2163 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, |
| 2164 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 2165 | if (!pass) { // If we can't find any unmappable memory this test doesn't |
| 2166 | // make sense |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2167 | vkDestroyImage(m_device->device(), image, NULL); |
Tony Barbour | 02fdc7d | 2015-08-04 16:13:01 -0600 | [diff] [blame] | 2168 | return; |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2169 | } |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 2170 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2171 | // allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2172 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2173 | ASSERT_VK_SUCCESS(err); |
| 2174 | |
| 2175 | // Try to bind free memory that has been freed |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 2176 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2177 | ASSERT_VK_SUCCESS(err); |
| 2178 | |
| 2179 | // Map memory as if to initialize the image |
| 2180 | void *mappedAddress = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2181 | err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, |
| 2182 | &mappedAddress); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2183 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2184 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2185 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2186 | vkDestroyImage(m_device->device(), image, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 2187 | vkFreeMemory(m_device->device(), mem, NULL); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2188 | } |
| 2189 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2190 | TEST_F(VkLayerTest, RebindMemory) { |
| 2191 | VkResult err; |
| 2192 | bool pass; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2193 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2194 | m_errorMonitor->SetDesiredFailureMsg( |
| 2195 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2196 | "which has already been bound to mem object"); |
| 2197 | |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2198 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2199 | |
| 2200 | // Create an image, allocate memory, free it, and then try to bind it |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2201 | VkImage image; |
| 2202 | VkDeviceMemory mem1; |
| 2203 | VkDeviceMemory mem2; |
| 2204 | VkMemoryRequirements mem_reqs; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2205 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2206 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2207 | const int32_t tex_width = 32; |
| 2208 | const int32_t tex_height = 32; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2209 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2210 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2211 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2212 | image_create_info.pNext = NULL; |
| 2213 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2214 | image_create_info.format = tex_format; |
| 2215 | image_create_info.extent.width = tex_width; |
| 2216 | image_create_info.extent.height = tex_height; |
| 2217 | image_create_info.extent.depth = 1; |
| 2218 | image_create_info.mipLevels = 1; |
| 2219 | image_create_info.arrayLayers = 1; |
| 2220 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2221 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2222 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2223 | image_create_info.flags = 0; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2224 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2225 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2226 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2227 | mem_alloc.pNext = NULL; |
| 2228 | mem_alloc.allocationSize = 0; |
| 2229 | mem_alloc.memoryTypeIndex = 0; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2230 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2231 | // Introduce failure, do NOT set memProps to |
| 2232 | // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2233 | mem_alloc.memoryTypeIndex = 1; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2234 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2235 | ASSERT_VK_SUCCESS(err); |
| 2236 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2237 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2238 | |
| 2239 | mem_alloc.allocationSize = mem_reqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2240 | pass = |
| 2241 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 2242 | ASSERT_TRUE(pass); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2243 | |
| 2244 | // allocate 2 memory objects |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2245 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2246 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2247 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2248 | ASSERT_VK_SUCCESS(err); |
| 2249 | |
| 2250 | // Bind first memory object to Image object |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 2251 | err = vkBindImageMemory(m_device->device(), image, mem1, 0); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2252 | ASSERT_VK_SUCCESS(err); |
| 2253 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2254 | // Introduce validation failure, try to bind a different memory object to |
| 2255 | // the same image object |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 2256 | err = vkBindImageMemory(m_device->device(), image, mem2, 0); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2257 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2258 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2259 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2260 | vkDestroyImage(m_device->device(), image, NULL); |
| 2261 | vkFreeMemory(m_device->device(), mem1, NULL); |
| 2262 | vkFreeMemory(m_device->device(), mem2, NULL); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2263 | } |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2264 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2265 | TEST_F(VkLayerTest, SubmitSignaledFence) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2266 | vk_testing::Fence testFence; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2267 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2268 | m_errorMonitor->SetDesiredFailureMsg( |
| 2269 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences " |
| 2270 | "must be reset before being submitted"); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 2271 | |
| 2272 | VkFenceCreateInfo fenceInfo = {}; |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2273 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 2274 | fenceInfo.pNext = NULL; |
| 2275 | fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2276 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2277 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2278 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 2279 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 2280 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2281 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2282 | m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 2283 | m_stencil_clear_color, NULL); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2284 | EndCommandBuffer(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2285 | |
| 2286 | testFence.init(*m_device, fenceInfo); |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 2287 | |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 2288 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 2289 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 2290 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 2291 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 2292 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 2293 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 2294 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2295 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 2296 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 2297 | submit_info.pSignalSemaphores = NULL; |
Courtney Goeltzenleuchter | 646b907 | 2015-10-20 18:04:07 -0600 | [diff] [blame] | 2298 | |
| 2299 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2300 | vkQueueWaitIdle(m_device->m_queue); |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 2301 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2302 | m_errorMonitor->VerifyFound(); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2303 | } |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2304 | // This is a positive test. We used to expect error in this case but spec now |
| 2305 | // allows it |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2306 | TEST_F(VkLayerTest, ResetUnsignaledFence) { |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2307 | m_errorMonitor->ExpectSuccess(); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2308 | vk_testing::Fence testFence; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 2309 | VkFenceCreateInfo fenceInfo = {}; |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2310 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 2311 | fenceInfo.pNext = NULL; |
| 2312 | |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2313 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2314 | testFence.init(*m_device, fenceInfo); |
Chia-I Wu | d9e8e82 | 2015-07-03 11:45:55 +0800 | [diff] [blame] | 2315 | VkFence fences[1] = {testFence.handle()}; |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2316 | VkResult result = vkResetFences(m_device->device(), 1, fences); |
| 2317 | ASSERT_VK_SUCCESS(result); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2318 | |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2319 | m_errorMonitor->VerifyNotFound(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2320 | } |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2321 | |
Chris Forbes | e70b7d3 | 2016-06-15 15:49:12 +1200 | [diff] [blame] | 2322 | #if 0 |
| 2323 | TEST_F(VkLayerTest, LongFenceChain) |
| 2324 | { |
| 2325 | m_errorMonitor->ExpectSuccess(); |
| 2326 | |
| 2327 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2328 | VkResult err; |
| 2329 | |
| 2330 | std::vector<VkFence> fences; |
| 2331 | |
| 2332 | const int chainLength = 32768; |
| 2333 | |
| 2334 | for (int i = 0; i < chainLength; i++) { |
| 2335 | VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 }; |
| 2336 | VkFence fence; |
| 2337 | err = vkCreateFence(m_device->device(), &fci, nullptr, &fence); |
| 2338 | ASSERT_VK_SUCCESS(err); |
| 2339 | |
| 2340 | fences.push_back(fence); |
| 2341 | |
| 2342 | VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, |
| 2343 | 0, nullptr, 0, nullptr }; |
| 2344 | err = vkQueueSubmit(m_device->m_queue, 1, &si, fence); |
| 2345 | ASSERT_VK_SUCCESS(err); |
| 2346 | |
| 2347 | } |
| 2348 | |
| 2349 | // BOOM, stack overflow. |
| 2350 | vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX); |
| 2351 | |
| 2352 | for (auto fence : fences) |
| 2353 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 2354 | |
| 2355 | m_errorMonitor->VerifyNotFound(); |
| 2356 | } |
| 2357 | #endif |
| 2358 | |
Chris Forbes | 18127d1 | 2016-06-08 16:52:28 +1200 | [diff] [blame] | 2359 | TEST_F(VkLayerTest, CommandBufferSimultaneousUseSync) |
| 2360 | { |
| 2361 | m_errorMonitor->ExpectSuccess(); |
| 2362 | |
| 2363 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2364 | VkResult err; |
| 2365 | |
| 2366 | // Record (empty!) command buffer that can be submitted multiple times |
| 2367 | // simultaneously. |
| 2368 | VkCommandBufferBeginInfo cbbi = { |
| 2369 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, |
| 2370 | VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr |
| 2371 | }; |
| 2372 | m_commandBuffer->BeginCommandBuffer(&cbbi); |
| 2373 | m_commandBuffer->EndCommandBuffer(); |
| 2374 | |
| 2375 | VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 }; |
| 2376 | VkFence fence; |
| 2377 | err = vkCreateFence(m_device->device(), &fci, nullptr, &fence); |
| 2378 | ASSERT_VK_SUCCESS(err); |
| 2379 | |
| 2380 | VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 }; |
| 2381 | VkSemaphore s1, s2; |
| 2382 | err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1); |
| 2383 | ASSERT_VK_SUCCESS(err); |
| 2384 | err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2); |
| 2385 | ASSERT_VK_SUCCESS(err); |
| 2386 | |
| 2387 | // Submit CB once signaling s1, with fence so we can roll forward to its retirement. |
| 2388 | VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, |
| 2389 | 1, &m_commandBuffer->handle(), 1, &s1 }; |
| 2390 | err = vkQueueSubmit(m_device->m_queue, 1, &si, fence); |
| 2391 | ASSERT_VK_SUCCESS(err); |
| 2392 | |
| 2393 | // Submit CB again, signaling s2. |
| 2394 | si.pSignalSemaphores = &s2; |
| 2395 | err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE); |
| 2396 | ASSERT_VK_SUCCESS(err); |
| 2397 | |
| 2398 | // Wait for fence. |
| 2399 | err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 2400 | ASSERT_VK_SUCCESS(err); |
| 2401 | |
| 2402 | // CB is still in flight from second submission, but semaphore s1 is no |
| 2403 | // longer in flight. delete it. |
| 2404 | vkDestroySemaphore(m_device->device(), s1, nullptr); |
| 2405 | |
| 2406 | m_errorMonitor->VerifyNotFound(); |
| 2407 | |
| 2408 | // Force device idle and clean up remaining objects |
| 2409 | vkDeviceWaitIdle(m_device->device()); |
| 2410 | vkDestroySemaphore(m_device->device(), s2, nullptr); |
| 2411 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 2412 | } |
| 2413 | |
Chris Forbes | 4e44c91 | 2016-06-16 10:20:00 +1200 | [diff] [blame] | 2414 | TEST_F(VkLayerTest, FenceCreateSignaledWaitHandling) |
| 2415 | { |
| 2416 | m_errorMonitor->ExpectSuccess(); |
| 2417 | |
| 2418 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2419 | VkResult err; |
| 2420 | |
| 2421 | // A fence created signaled |
| 2422 | VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT }; |
| 2423 | VkFence f1; |
| 2424 | err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1); |
| 2425 | ASSERT_VK_SUCCESS(err); |
| 2426 | |
| 2427 | // A fence created not |
| 2428 | VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 }; |
| 2429 | VkFence f2; |
| 2430 | err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2); |
| 2431 | ASSERT_VK_SUCCESS(err); |
| 2432 | |
| 2433 | // Submit the unsignaled fence |
| 2434 | VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, |
| 2435 | 0, nullptr, 0, nullptr }; |
| 2436 | err = vkQueueSubmit(m_device->m_queue, 1, &si, f2); |
| 2437 | |
| 2438 | // Wait on both fences, with signaled first. |
| 2439 | VkFence fences[] = { f1, f2 }; |
| 2440 | vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX); |
| 2441 | |
| 2442 | // Should have both retired! |
| 2443 | vkDestroyFence(m_device->device(), f1, nullptr); |
| 2444 | vkDestroyFence(m_device->device(), f2, nullptr); |
| 2445 | |
| 2446 | m_errorMonitor->VerifyNotFound(); |
| 2447 | } |
| 2448 | |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2449 | TEST_F(VkLayerTest, InvalidUsageBits) |
| 2450 | { |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2451 | TEST_DESCRIPTION( |
Karl Schultz | b5bc11e | 2016-05-04 08:36:08 -0600 | [diff] [blame] | 2452 | "Specify wrong usage for image then create conflicting view of image " |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2453 | "Initialize buffer with wrong usage then perform copy expecting errors " |
| 2454 | "from both the image and the buffer (2 calls)"); |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2455 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2456 | "Invalid usage flag for image "); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2457 | |
| 2458 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2459 | VkImageObj image(m_device); |
| 2460 | // Initialize image with USAGE_INPUT_ATTACHMENT |
Tobin Ehlis | 8b313c0 | 2016-05-25 15:01:52 -0600 | [diff] [blame] | 2461 | image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, |
Karl Schultz | b5bc11e | 2016-05-04 08:36:08 -0600 | [diff] [blame] | 2462 | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 2463 | ASSERT_TRUE(image.initialized()); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2464 | |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2465 | VkImageView dsv; |
| 2466 | VkImageViewCreateInfo dsvci = {}; |
| 2467 | dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 2468 | dsvci.image = image.handle(); |
| 2469 | dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 2470 | dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT; |
| 2471 | dsvci.subresourceRange.layerCount = 1; |
| 2472 | dsvci.subresourceRange.baseMipLevel = 0; |
| 2473 | dsvci.subresourceRange.levelCount = 1; |
| 2474 | dsvci.subresourceRange.aspectMask = |
| 2475 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2476 | |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2477 | // Create a view with depth / stencil aspect for image with different usage |
| 2478 | vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2479 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2480 | m_errorMonitor->VerifyFound(); |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2481 | |
| 2482 | // Initialize buffer with TRANSFER_DST usage |
| 2483 | vk_testing::Buffer buffer; |
| 2484 | VkMemoryPropertyFlags reqs = 0; |
| 2485 | buffer.init_as_dst(*m_device, 128 * 128, reqs); |
| 2486 | VkBufferImageCopy region = {}; |
| 2487 | region.bufferRowLength = 128; |
| 2488 | region.bufferImageHeight = 128; |
| 2489 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 2490 | region.imageSubresource.layerCount = 1; |
| 2491 | region.imageExtent.height = 16; |
| 2492 | region.imageExtent.width = 16; |
| 2493 | region.imageExtent.depth = 1; |
| 2494 | |
| 2495 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2496 | "Invalid usage flag for buffer "); |
| 2497 | // Buffer usage not set to TRANSFER_SRC and image usage not set to |
| 2498 | // TRANSFER_DST |
| 2499 | BeginCommandBuffer(); |
| 2500 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 2501 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 2502 | 1, ®ion); |
| 2503 | m_errorMonitor->VerifyFound(); |
| 2504 | |
| 2505 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2506 | "Invalid usage flag for image "); |
| 2507 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 2508 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 2509 | 1, ®ion); |
| 2510 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2511 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 2512 | #endif // MEM_TRACKER_TESTS |
| 2513 | |
Tobin Ehlis | 4bf96d1 | 2015-06-25 11:58:41 -0600 | [diff] [blame] | 2514 | #if OBJ_TRACKER_TESTS |
Mark Lobodzinski | fc5cc66 | 2016-05-02 17:17:41 -0600 | [diff] [blame] | 2515 | |
| 2516 | TEST_F(VkLayerTest, LeakAnObject) { |
| 2517 | VkResult err; |
| 2518 | |
| 2519 | TEST_DESCRIPTION( |
| 2520 | "Create a fence and destroy its device without first destroying the fence."); |
| 2521 | |
| 2522 | // Note that we have to create a new device since destroying the |
| 2523 | // framework's device causes Teardown() to fail and just calling Teardown |
| 2524 | // will destroy the errorMonitor. |
| 2525 | |
| 2526 | m_errorMonitor->SetDesiredFailureMsg( |
| 2527 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2528 | "OBJ ERROR : VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT object"); |
| 2529 | |
| 2530 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2531 | |
| 2532 | const std::vector<VkQueueFamilyProperties> queue_props = |
| 2533 | m_device->queue_props; |
| 2534 | std::vector<VkDeviceQueueCreateInfo> queue_info; |
| 2535 | queue_info.reserve(queue_props.size()); |
| 2536 | std::vector<std::vector<float>> queue_priorities; |
| 2537 | for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) { |
| 2538 | VkDeviceQueueCreateInfo qi = {}; |
| 2539 | qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; |
| 2540 | qi.pNext = NULL; |
| 2541 | qi.queueFamilyIndex = i; |
| 2542 | qi.queueCount = queue_props[i].queueCount; |
| 2543 | queue_priorities.emplace_back(qi.queueCount, 0.0f); |
| 2544 | qi.pQueuePriorities = queue_priorities[i].data(); |
| 2545 | queue_info.push_back(qi); |
| 2546 | } |
| 2547 | |
| 2548 | std::vector<const char *> device_layer_names; |
| 2549 | std::vector<const char *> device_extension_names; |
| 2550 | device_layer_names.push_back("VK_LAYER_GOOGLE_threading"); |
| 2551 | device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation"); |
| 2552 | device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker"); |
| 2553 | device_layer_names.push_back("VK_LAYER_LUNARG_core_validation"); |
| 2554 | device_layer_names.push_back("VK_LAYER_LUNARG_device_limits"); |
| 2555 | device_layer_names.push_back("VK_LAYER_LUNARG_image"); |
| 2556 | device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects"); |
| 2557 | |
| 2558 | // The sacrificial device object |
| 2559 | VkDevice testDevice; |
| 2560 | VkDeviceCreateInfo device_create_info = {}; |
| 2561 | auto features = m_device->phy().features(); |
| 2562 | device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; |
| 2563 | device_create_info.pNext = NULL; |
| 2564 | device_create_info.queueCreateInfoCount = queue_info.size(); |
| 2565 | device_create_info.pQueueCreateInfos = queue_info.data(); |
| 2566 | device_create_info.enabledLayerCount = device_layer_names.size(); |
| 2567 | device_create_info.ppEnabledLayerNames = device_layer_names.data(); |
| 2568 | device_create_info.pEnabledFeatures = &features; |
| 2569 | err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice); |
| 2570 | ASSERT_VK_SUCCESS(err); |
| 2571 | |
| 2572 | VkFence fence; |
| 2573 | VkFenceCreateInfo fence_create_info = {}; |
| 2574 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 2575 | fence_create_info.pNext = NULL; |
| 2576 | fence_create_info.flags = 0; |
| 2577 | err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence); |
| 2578 | ASSERT_VK_SUCCESS(err); |
| 2579 | |
| 2580 | // Induce failure by not calling vkDestroyFence |
| 2581 | vkDestroyDevice(testDevice, NULL); |
| 2582 | m_errorMonitor->VerifyFound(); |
| 2583 | } |
| 2584 | |
| 2585 | TEST_F(VkLayerTest, InvalidCommandPoolConsistency) { |
| 2586 | |
| 2587 | TEST_DESCRIPTION("Allocate command buffers from one command pool and " |
| 2588 | "attempt to delete them from another."); |
| 2589 | |
| 2590 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2591 | "FreeCommandBuffers is attempting to free Command Buffer"); |
| 2592 | |
| 2593 | VkCommandPool command_pool_one; |
| 2594 | VkCommandPool command_pool_two; |
| 2595 | |
| 2596 | VkCommandPoolCreateInfo pool_create_info{}; |
| 2597 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 2598 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 2599 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 2600 | |
| 2601 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 2602 | &command_pool_one); |
| 2603 | |
| 2604 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 2605 | &command_pool_two); |
| 2606 | |
| 2607 | VkCommandBuffer command_buffer[9]; |
| 2608 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 2609 | command_buffer_allocate_info.sType = |
| 2610 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 2611 | command_buffer_allocate_info.commandPool = command_pool_one; |
| 2612 | command_buffer_allocate_info.commandBufferCount = 9; |
| 2613 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 2614 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 2615 | command_buffer); |
| 2616 | |
| 2617 | vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, |
| 2618 | &command_buffer[3]); |
| 2619 | |
| 2620 | m_errorMonitor->VerifyFound(); |
| 2621 | |
| 2622 | vkDestroyCommandPool(m_device->device(), command_pool_one, NULL); |
| 2623 | vkDestroyCommandPool(m_device->device(), command_pool_two, NULL); |
| 2624 | } |
| 2625 | |
| 2626 | TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) { |
| 2627 | VkResult err; |
| 2628 | |
| 2629 | TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and " |
| 2630 | "attempt to delete them from another."); |
| 2631 | |
| 2632 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2633 | "FreeDescriptorSets is attempting to free descriptorSet"); |
| 2634 | |
| 2635 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2636 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 2637 | |
| 2638 | VkDescriptorPoolSize ds_type_count = {}; |
| 2639 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 2640 | ds_type_count.descriptorCount = 1; |
| 2641 | |
| 2642 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 2643 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 2644 | ds_pool_ci.pNext = NULL; |
| 2645 | ds_pool_ci.flags = 0; |
| 2646 | ds_pool_ci.maxSets = 1; |
| 2647 | ds_pool_ci.poolSizeCount = 1; |
| 2648 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 2649 | |
| 2650 | VkDescriptorPool ds_pool_one; |
| 2651 | err = |
| 2652 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one); |
| 2653 | ASSERT_VK_SUCCESS(err); |
| 2654 | |
| 2655 | // Create a second descriptor pool |
| 2656 | VkDescriptorPool ds_pool_two; |
| 2657 | err = |
| 2658 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two); |
| 2659 | ASSERT_VK_SUCCESS(err); |
| 2660 | |
| 2661 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 2662 | dsl_binding.binding = 0; |
| 2663 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 2664 | dsl_binding.descriptorCount = 1; |
| 2665 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 2666 | dsl_binding.pImmutableSamplers = NULL; |
| 2667 | |
| 2668 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 2669 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 2670 | ds_layout_ci.pNext = NULL; |
| 2671 | ds_layout_ci.bindingCount = 1; |
| 2672 | ds_layout_ci.pBindings = &dsl_binding; |
| 2673 | |
| 2674 | VkDescriptorSetLayout ds_layout; |
| 2675 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 2676 | &ds_layout); |
| 2677 | ASSERT_VK_SUCCESS(err); |
| 2678 | |
| 2679 | VkDescriptorSet descriptorSet; |
| 2680 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 2681 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 2682 | alloc_info.descriptorSetCount = 1; |
| 2683 | alloc_info.descriptorPool = ds_pool_one; |
| 2684 | alloc_info.pSetLayouts = &ds_layout; |
| 2685 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 2686 | &descriptorSet); |
| 2687 | ASSERT_VK_SUCCESS(err); |
| 2688 | |
| 2689 | err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet); |
| 2690 | |
| 2691 | m_errorMonitor->VerifyFound(); |
| 2692 | |
| 2693 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 2694 | vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL); |
| 2695 | vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL); |
| 2696 | } |
| 2697 | |
| 2698 | TEST_F(VkLayerTest, CreateUnknownObject) { |
| 2699 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2700 | "Invalid VkImage Object "); |
| 2701 | |
| 2702 | TEST_DESCRIPTION( |
| 2703 | "Pass an invalid image object handle into a Vulkan API call."); |
| 2704 | |
| 2705 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2706 | |
| 2707 | // Pass bogus handle into GetImageMemoryRequirements |
| 2708 | VkMemoryRequirements mem_reqs; |
| 2709 | uint64_t fakeImageHandle = 0xCADECADE; |
| 2710 | VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle); |
| 2711 | |
| 2712 | vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs); |
| 2713 | |
| 2714 | m_errorMonitor->VerifyFound(); |
| 2715 | } |
| 2716 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2717 | TEST_F(VkLayerTest, PipelineNotBound) { |
| 2718 | VkResult err; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2719 | |
Mark Lobodzinski | fc5cc66 | 2016-05-02 17:17:41 -0600 | [diff] [blame] | 2720 | TEST_DESCRIPTION( |
| 2721 | "Pass in an invalid pipeline object handle into a Vulkan API call."); |
| 2722 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2723 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2724 | "Invalid VkPipeline Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2725 | |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2726 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2727 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2728 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 2729 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2730 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 2731 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2732 | |
| 2733 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2734 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 2735 | ds_pool_ci.pNext = NULL; |
| 2736 | ds_pool_ci.maxSets = 1; |
| 2737 | ds_pool_ci.poolSizeCount = 1; |
| 2738 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2739 | |
| 2740 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2741 | err = |
| 2742 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2743 | ASSERT_VK_SUCCESS(err); |
| 2744 | |
| 2745 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2746 | dsl_binding.binding = 0; |
| 2747 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 2748 | dsl_binding.descriptorCount = 1; |
| 2749 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 2750 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2751 | |
| 2752 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2753 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 2754 | ds_layout_ci.pNext = NULL; |
| 2755 | ds_layout_ci.bindingCount = 1; |
| 2756 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2757 | |
| 2758 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2759 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 2760 | &ds_layout); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2761 | ASSERT_VK_SUCCESS(err); |
| 2762 | |
| 2763 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2764 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 2765 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 2766 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 2767 | alloc_info.descriptorPool = ds_pool; |
| 2768 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2769 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 2770 | &descriptorSet); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2771 | ASSERT_VK_SUCCESS(err); |
| 2772 | |
| 2773 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2774 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 2775 | pipeline_layout_ci.pNext = NULL; |
| 2776 | pipeline_layout_ci.setLayoutCount = 1; |
| 2777 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2778 | |
| 2779 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2780 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 2781 | &pipeline_layout); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2782 | ASSERT_VK_SUCCESS(err); |
| 2783 | |
Mark Young | ad77905 | 2016-01-06 14:26:04 -0700 | [diff] [blame] | 2784 | VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2785 | |
| 2786 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2787 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 2788 | VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2789 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2790 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2791 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2792 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 2793 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 2794 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2795 | } |
Mike Stroyan | 80fc6c3 | 2016-06-20 15:42:29 -0600 | [diff] [blame] | 2796 | |
Mark Lobodzinski | bc18576 | 2016-06-15 16:28:53 -0600 | [diff] [blame] | 2797 | TEST_F(VkLayerTest, BindImageInvalidMemoryType) { |
| 2798 | VkResult err; |
| 2799 | |
| 2800 | TEST_DESCRIPTION("Test validation check for an invalid memory type index " |
| 2801 | "during bind[Buffer|Image]Memory time"); |
| 2802 | |
Mark Lobodzinski | bc18576 | 2016-06-15 16:28:53 -0600 | [diff] [blame] | 2803 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2804 | |
| 2805 | // Create an image, allocate memory, set a bad typeIndex and then try to |
| 2806 | // bind it |
| 2807 | VkImage image; |
| 2808 | VkDeviceMemory mem; |
| 2809 | VkMemoryRequirements mem_reqs; |
| 2810 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2811 | const int32_t tex_width = 32; |
| 2812 | const int32_t tex_height = 32; |
| 2813 | |
| 2814 | VkImageCreateInfo image_create_info = {}; |
| 2815 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2816 | image_create_info.pNext = NULL; |
| 2817 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2818 | image_create_info.format = tex_format; |
| 2819 | image_create_info.extent.width = tex_width; |
| 2820 | image_create_info.extent.height = tex_height; |
| 2821 | image_create_info.extent.depth = 1; |
| 2822 | image_create_info.mipLevels = 1; |
| 2823 | image_create_info.arrayLayers = 1; |
| 2824 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2825 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 2826 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2827 | image_create_info.flags = 0; |
| 2828 | |
| 2829 | VkMemoryAllocateInfo mem_alloc = {}; |
| 2830 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2831 | mem_alloc.pNext = NULL; |
| 2832 | mem_alloc.allocationSize = 0; |
| 2833 | mem_alloc.memoryTypeIndex = 0; |
| 2834 | |
| 2835 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 2836 | ASSERT_VK_SUCCESS(err); |
| 2837 | |
| 2838 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 2839 | mem_alloc.allocationSize = mem_reqs.size; |
Mike Stroyan | 80fc6c3 | 2016-06-20 15:42:29 -0600 | [diff] [blame] | 2840 | |
| 2841 | // Introduce Failure, select invalid TypeIndex |
| 2842 | VkPhysicalDeviceMemoryProperties memory_info; |
| 2843 | |
| 2844 | vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info); |
| 2845 | unsigned int i; |
| 2846 | for (i = 0; i < memory_info.memoryTypeCount; i++) { |
| 2847 | if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) { |
| 2848 | mem_alloc.memoryTypeIndex = i; |
| 2849 | break; |
| 2850 | } |
| 2851 | } |
| 2852 | if (i >= memory_info.memoryTypeCount) { |
| 2853 | printf("No invalid memory type index could be found; skipped.\n"); |
| 2854 | vkDestroyImage(m_device->device(), image, NULL); |
| 2855 | return; |
| 2856 | } |
| 2857 | |
| 2858 | m_errorMonitor->SetDesiredFailureMsg( |
| 2859 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2860 | "for this object type are not compatible with the memory"); |
Mark Lobodzinski | bc18576 | 2016-06-15 16:28:53 -0600 | [diff] [blame] | 2861 | |
| 2862 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 2863 | ASSERT_VK_SUCCESS(err); |
| 2864 | |
| 2865 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 2866 | (void)err; |
| 2867 | |
| 2868 | m_errorMonitor->VerifyFound(); |
| 2869 | |
| 2870 | vkDestroyImage(m_device->device(), image, NULL); |
| 2871 | vkFreeMemory(m_device->device(), mem, NULL); |
| 2872 | } |
Mike Stroyan | 80fc6c3 | 2016-06-20 15:42:29 -0600 | [diff] [blame] | 2873 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2874 | TEST_F(VkLayerTest, BindInvalidMemory) { |
| 2875 | VkResult err; |
| 2876 | bool pass; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2877 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2878 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2879 | "Invalid VkDeviceMemory Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2880 | |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2881 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2882 | |
| 2883 | // Create an image, allocate memory, free it, and then try to bind it |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2884 | VkImage image; |
| 2885 | VkDeviceMemory mem; |
| 2886 | VkMemoryRequirements mem_reqs; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2887 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2888 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2889 | const int32_t tex_width = 32; |
| 2890 | const int32_t tex_height = 32; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2891 | |
| 2892 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2893 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2894 | image_create_info.pNext = NULL; |
| 2895 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2896 | image_create_info.format = tex_format; |
| 2897 | image_create_info.extent.width = tex_width; |
| 2898 | image_create_info.extent.height = tex_height; |
| 2899 | image_create_info.extent.depth = 1; |
| 2900 | image_create_info.mipLevels = 1; |
| 2901 | image_create_info.arrayLayers = 1; |
| 2902 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2903 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2904 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2905 | image_create_info.flags = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2906 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2907 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2908 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2909 | mem_alloc.pNext = NULL; |
| 2910 | mem_alloc.allocationSize = 0; |
| 2911 | mem_alloc.memoryTypeIndex = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2912 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2913 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2914 | ASSERT_VK_SUCCESS(err); |
| 2915 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2916 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2917 | |
| 2918 | mem_alloc.allocationSize = mem_reqs.size; |
| 2919 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2920 | pass = |
| 2921 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 2922 | ASSERT_TRUE(pass); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2923 | |
| 2924 | // allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2925 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2926 | ASSERT_VK_SUCCESS(err); |
| 2927 | |
| 2928 | // Introduce validation failure, free memory before binding |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2929 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2930 | |
| 2931 | // Try to bind free memory that has been freed |
| 2932 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 2933 | // This may very well return an error. |
| 2934 | (void)err; |
| 2935 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2936 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2937 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2938 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2939 | } |
| 2940 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2941 | TEST_F(VkLayerTest, BindMemoryToDestroyedObject) { |
| 2942 | VkResult err; |
| 2943 | bool pass; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2944 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2945 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2946 | "Invalid VkImage Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2947 | |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2948 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2949 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2950 | // Create an image object, allocate memory, destroy the object and then try |
| 2951 | // to bind it |
| 2952 | VkImage image; |
| 2953 | VkDeviceMemory mem; |
| 2954 | VkMemoryRequirements mem_reqs; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2955 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2956 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2957 | const int32_t tex_width = 32; |
| 2958 | const int32_t tex_height = 32; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2959 | |
| 2960 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2961 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2962 | image_create_info.pNext = NULL; |
| 2963 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2964 | image_create_info.format = tex_format; |
| 2965 | image_create_info.extent.width = tex_width; |
| 2966 | image_create_info.extent.height = tex_height; |
| 2967 | image_create_info.extent.depth = 1; |
| 2968 | image_create_info.mipLevels = 1; |
| 2969 | image_create_info.arrayLayers = 1; |
| 2970 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2971 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2972 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2973 | image_create_info.flags = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2974 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2975 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2976 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2977 | mem_alloc.pNext = NULL; |
| 2978 | mem_alloc.allocationSize = 0; |
| 2979 | mem_alloc.memoryTypeIndex = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2980 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2981 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2982 | ASSERT_VK_SUCCESS(err); |
| 2983 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2984 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2985 | |
| 2986 | mem_alloc.allocationSize = mem_reqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2987 | pass = |
| 2988 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 2989 | ASSERT_TRUE(pass); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2990 | |
| 2991 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2992 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2993 | ASSERT_VK_SUCCESS(err); |
| 2994 | |
| 2995 | // Introduce validation failure, destroy Image object before binding |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2996 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2997 | ASSERT_VK_SUCCESS(err); |
| 2998 | |
| 2999 | // Now Try to bind memory to this destroyed object |
| 3000 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 3001 | // This may very well return an error. |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3002 | (void)err; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 3003 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 3004 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 3005 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 3006 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 3007 | } |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 3008 | |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 3009 | #endif // OBJ_TRACKER_TESTS |
| 3010 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 3011 | #if DRAW_STATE_TESTS |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3012 | |
Chris Forbes | 48a5390 | 2016-06-30 11:46:27 +1200 | [diff] [blame] | 3013 | TEST_F(VkLayerTest, RenderPassInitialLayoutUndefined) { |
| 3014 | TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's " |
| 3015 | "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when " |
| 3016 | "the command buffer has prior knowledge of that " |
| 3017 | "attachment's layout."); |
| 3018 | |
| 3019 | m_errorMonitor->ExpectSuccess(); |
| 3020 | |
| 3021 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3022 | |
| 3023 | // A renderpass with one color attachment. |
| 3024 | VkAttachmentDescription attachment = { |
| 3025 | 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, |
| 3026 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_STORE, |
| 3027 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3028 | VK_IMAGE_LAYOUT_UNDEFINED, |
| 3029 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3030 | }; |
| 3031 | |
| 3032 | VkAttachmentReference att_ref = { |
| 3033 | 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3034 | }; |
| 3035 | |
| 3036 | VkSubpassDescription subpass = { |
| 3037 | 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, |
| 3038 | 1, &att_ref, nullptr, nullptr, 0, nullptr |
| 3039 | }; |
| 3040 | |
| 3041 | VkRenderPassCreateInfo rpci = { |
| 3042 | VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, |
| 3043 | 0, 1, &attachment, 1, &subpass, 0, nullptr |
| 3044 | }; |
| 3045 | |
| 3046 | VkRenderPass rp; |
| 3047 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp); |
| 3048 | ASSERT_VK_SUCCESS(err); |
| 3049 | |
| 3050 | // A compatible framebuffer. |
| 3051 | VkImageObj image(m_device); |
| 3052 | image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, |
| 3053 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, |
| 3054 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 3055 | ASSERT_TRUE(image.initialized()); |
| 3056 | |
| 3057 | VkImageViewCreateInfo ivci = { |
| 3058 | VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, nullptr, |
| 3059 | 0, image.handle(), VK_IMAGE_VIEW_TYPE_2D, VK_FORMAT_R8G8B8A8_UNORM, |
| 3060 | { |
| 3061 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3062 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3063 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3064 | VK_COMPONENT_SWIZZLE_IDENTITY |
| 3065 | }, |
| 3066 | { |
| 3067 | VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 |
| 3068 | }, |
| 3069 | }; |
| 3070 | VkImageView view; |
| 3071 | err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view); |
| 3072 | ASSERT_VK_SUCCESS(err); |
| 3073 | |
| 3074 | VkFramebufferCreateInfo fci = { |
| 3075 | VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, |
| 3076 | 0, rp, 1, &view, |
| 3077 | 32, 32, 1 |
| 3078 | }; |
| 3079 | VkFramebuffer fb; |
| 3080 | err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb); |
| 3081 | ASSERT_VK_SUCCESS(err); |
| 3082 | |
| 3083 | // Record a single command buffer which uses this renderpass twice. The |
| 3084 | // bug is triggered at the beginning of the second renderpass, when the |
| 3085 | // command buffer already has a layout recorded for the attachment. |
| 3086 | VkRenderPassBeginInfo rpbi = { |
| 3087 | VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, |
| 3088 | rp, fb, { 0, 0, 32, 32 }, |
| 3089 | 0, nullptr |
| 3090 | }; |
| 3091 | BeginCommandBuffer(); |
| 3092 | vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, |
| 3093 | VK_SUBPASS_CONTENTS_INLINE); |
| 3094 | vkCmdEndRenderPass(m_commandBuffer->handle()); |
| 3095 | vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, |
| 3096 | VK_SUBPASS_CONTENTS_INLINE); |
| 3097 | |
| 3098 | m_errorMonitor->VerifyNotFound(); |
| 3099 | |
| 3100 | vkCmdEndRenderPass(m_commandBuffer->handle()); |
| 3101 | EndCommandBuffer(); |
| 3102 | |
| 3103 | vkDestroyFramebuffer(m_device->device(), fb, nullptr); |
| 3104 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3105 | vkDestroyImageView(m_device->device(), view, nullptr); |
| 3106 | } |
| 3107 | |
Chris Forbes | 51bf7c9 | 2016-06-30 15:22:08 +1200 | [diff] [blame^] | 3108 | TEST_F(VkLayerTest, RenderPassSubpassZeroTransitionsApplied) { |
| 3109 | TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout " |
| 3110 | "transitions for the first subpass"); |
| 3111 | |
| 3112 | m_errorMonitor->ExpectSuccess(); |
| 3113 | |
| 3114 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3115 | |
| 3116 | // A renderpass with one color attachment. |
| 3117 | VkAttachmentDescription attachment = { |
| 3118 | 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, |
| 3119 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_STORE, |
| 3120 | VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, |
| 3121 | VK_IMAGE_LAYOUT_UNDEFINED, |
| 3122 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3123 | }; |
| 3124 | |
| 3125 | VkAttachmentReference att_ref = { |
| 3126 | 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL |
| 3127 | }; |
| 3128 | |
| 3129 | VkSubpassDescription subpass = { |
| 3130 | 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, |
| 3131 | 1, &att_ref, nullptr, nullptr, 0, nullptr |
| 3132 | }; |
| 3133 | |
| 3134 | VkSubpassDependency dep = { |
| 3135 | 0, 0, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3136 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3137 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 3138 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 3139 | VK_DEPENDENCY_BY_REGION_BIT |
| 3140 | }; |
| 3141 | |
| 3142 | VkRenderPassCreateInfo rpci = { |
| 3143 | VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, |
| 3144 | 0, 1, &attachment, 1, &subpass, 1, &dep |
| 3145 | }; |
| 3146 | |
| 3147 | VkResult err; |
| 3148 | VkRenderPass rp; |
| 3149 | err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp); |
| 3150 | ASSERT_VK_SUCCESS(err); |
| 3151 | |
| 3152 | // A compatible framebuffer. |
| 3153 | VkImageObj image(m_device); |
| 3154 | image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, |
| 3155 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, |
| 3156 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 3157 | ASSERT_TRUE(image.initialized()); |
| 3158 | |
| 3159 | VkImageViewCreateInfo ivci = { |
| 3160 | VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, nullptr, |
| 3161 | 0, image.handle(), VK_IMAGE_VIEW_TYPE_2D, VK_FORMAT_R8G8B8A8_UNORM, |
| 3162 | { |
| 3163 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3164 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3165 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 3166 | VK_COMPONENT_SWIZZLE_IDENTITY |
| 3167 | }, |
| 3168 | { |
| 3169 | VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 |
| 3170 | }, |
| 3171 | }; |
| 3172 | VkImageView view; |
| 3173 | err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view); |
| 3174 | ASSERT_VK_SUCCESS(err); |
| 3175 | |
| 3176 | VkFramebufferCreateInfo fci = { |
| 3177 | VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, |
| 3178 | 0, rp, 1, &view, |
| 3179 | 32, 32, 1 |
| 3180 | }; |
| 3181 | VkFramebuffer fb; |
| 3182 | err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb); |
| 3183 | ASSERT_VK_SUCCESS(err); |
| 3184 | |
| 3185 | // Record a single command buffer which issues a pipeline barrier w/ |
| 3186 | // image memory barrier for the attachment. This detects the previously |
| 3187 | // missing tracking of the subpass layout by throwing a validation error |
| 3188 | // if it doesn't occur. |
| 3189 | VkRenderPassBeginInfo rpbi = { |
| 3190 | VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, |
| 3191 | rp, fb, { 0, 0, 32, 32 }, |
| 3192 | 0, nullptr |
| 3193 | }; |
| 3194 | BeginCommandBuffer(); |
| 3195 | vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, |
| 3196 | VK_SUBPASS_CONTENTS_INLINE); |
| 3197 | |
| 3198 | VkImageMemoryBarrier imb = { |
| 3199 | VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, nullptr, |
| 3200 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 3201 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, |
| 3202 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3203 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
| 3204 | VK_QUEUE_FAMILY_IGNORED, VK_QUEUE_FAMILY_IGNORED, |
| 3205 | image.handle(), |
| 3206 | { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } |
| 3207 | }; |
| 3208 | vkCmdPipelineBarrier(m_commandBuffer->handle(), |
| 3209 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3210 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3211 | VK_DEPENDENCY_BY_REGION_BIT, |
| 3212 | 0, nullptr, 0, nullptr, 1, &imb); |
| 3213 | |
| 3214 | vkCmdEndRenderPass(m_commandBuffer->handle()); |
| 3215 | m_errorMonitor->VerifyNotFound(); |
| 3216 | EndCommandBuffer(); |
| 3217 | |
| 3218 | vkDestroyFramebuffer(m_device->device(), fb, nullptr); |
| 3219 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3220 | vkDestroyImageView(m_device->device(), view, nullptr); |
| 3221 | } |
| 3222 | |
Mark Lobodzinski | ce7eee7 | 2016-06-14 16:33:29 -0600 | [diff] [blame] | 3223 | // This is a positive test. No errors are expected. |
| 3224 | TEST_F(VkLayerTest, StencilLoadOp) { |
| 3225 | TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to " |
| 3226 | "CLEAR. stencil[Load|Store]Op used to be ignored."); |
| 3227 | VkResult result = VK_SUCCESS; |
| 3228 | VkImageFormatProperties formatProps; |
| 3229 | vkGetPhysicalDeviceImageFormatProperties( |
| 3230 | gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, |
| 3231 | VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 3232 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, |
| 3233 | 0, &formatProps); |
| 3234 | if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) { |
| 3235 | return; |
| 3236 | } |
| 3237 | |
| 3238 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3239 | VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT; |
| 3240 | m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt, |
| 3241 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 3242 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT); |
| 3243 | VkAttachmentDescription att = {}; |
| 3244 | VkAttachmentReference ref = {}; |
| 3245 | att.format = depth_stencil_fmt; |
| 3246 | att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 3247 | att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 3248 | att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 3249 | att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE; |
| 3250 | att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3251 | att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3252 | |
| 3253 | VkClearValue clear; |
| 3254 | clear.depthStencil.depth = 1.0; |
| 3255 | clear.depthStencil.stencil = 0; |
| 3256 | ref.attachment = 0; |
| 3257 | ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3258 | |
| 3259 | VkSubpassDescription subpass = {}; |
| 3260 | subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; |
| 3261 | subpass.flags = 0; |
| 3262 | subpass.inputAttachmentCount = 0; |
| 3263 | subpass.pInputAttachments = NULL; |
| 3264 | subpass.colorAttachmentCount = 0; |
| 3265 | subpass.pColorAttachments = NULL; |
| 3266 | subpass.pResolveAttachments = NULL; |
| 3267 | subpass.pDepthStencilAttachment = &ref; |
| 3268 | subpass.preserveAttachmentCount = 0; |
| 3269 | subpass.pPreserveAttachments = NULL; |
| 3270 | |
| 3271 | VkRenderPass rp; |
| 3272 | VkRenderPassCreateInfo rp_info = {}; |
| 3273 | rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 3274 | rp_info.attachmentCount = 1; |
| 3275 | rp_info.pAttachments = &att; |
| 3276 | rp_info.subpassCount = 1; |
| 3277 | rp_info.pSubpasses = &subpass; |
| 3278 | result = vkCreateRenderPass(device(), &rp_info, NULL, &rp); |
| 3279 | ASSERT_VK_SUCCESS(result); |
| 3280 | |
| 3281 | VkImageView *depthView = m_depthStencil->BindInfo(); |
| 3282 | VkFramebufferCreateInfo fb_info = {}; |
| 3283 | fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
| 3284 | fb_info.pNext = NULL; |
| 3285 | fb_info.renderPass = rp; |
| 3286 | fb_info.attachmentCount = 1; |
| 3287 | fb_info.pAttachments = depthView; |
| 3288 | fb_info.width = 100; |
| 3289 | fb_info.height = 100; |
| 3290 | fb_info.layers = 1; |
| 3291 | VkFramebuffer fb; |
| 3292 | result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3293 | ASSERT_VK_SUCCESS(result); |
| 3294 | |
| 3295 | |
| 3296 | VkRenderPassBeginInfo rpbinfo = {}; |
| 3297 | rpbinfo.clearValueCount = 1; |
| 3298 | rpbinfo.pClearValues = &clear; |
| 3299 | rpbinfo.pNext = NULL; |
| 3300 | rpbinfo.renderPass = rp; |
| 3301 | rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 3302 | rpbinfo.renderArea.extent.width = 100; |
| 3303 | rpbinfo.renderArea.extent.height = 100; |
| 3304 | rpbinfo.renderArea.offset.x = 0; |
| 3305 | rpbinfo.renderArea.offset.y = 0; |
| 3306 | rpbinfo.framebuffer = fb; |
| 3307 | |
| 3308 | VkFence fence = {}; |
| 3309 | VkFenceCreateInfo fence_ci = {}; |
| 3310 | fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3311 | fence_ci.pNext = nullptr; |
| 3312 | fence_ci.flags = 0; |
| 3313 | result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence); |
| 3314 | ASSERT_VK_SUCCESS(result); |
| 3315 | |
| 3316 | |
| 3317 | m_commandBuffer->BeginCommandBuffer(); |
| 3318 | m_commandBuffer->BeginRenderPass(rpbinfo); |
| 3319 | m_commandBuffer->EndRenderPass(); |
| 3320 | m_commandBuffer->EndCommandBuffer(); |
| 3321 | m_commandBuffer->QueueCommandBuffer(fence); |
| 3322 | |
| 3323 | VkImageObj destImage(m_device); |
| 3324 | destImage.init(100, 100, depth_stencil_fmt, |
| 3325 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 3326 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 3327 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 3328 | VkImageMemoryBarrier barrier = {}; |
| 3329 | VkImageSubresourceRange range; |
| 3330 | barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 3331 | barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | |
| 3332 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; |
| 3333 | barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | |
| 3334 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT; |
| 3335 | barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3336 | barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 3337 | barrier.image = m_depthStencil->handle(); |
| 3338 | range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3339 | range.baseMipLevel = 0; |
| 3340 | range.levelCount = 1; |
| 3341 | range.baseArrayLayer = 0; |
| 3342 | range.layerCount = 1; |
| 3343 | barrier.subresourceRange = range; |
| 3344 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 3345 | VkCommandBufferObj cmdbuf(m_device, m_commandPool); |
| 3346 | cmdbuf.BeginCommandBuffer(); |
| 3347 | cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3348 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, |
| 3349 | nullptr, 1, &barrier); |
| 3350 | barrier.srcAccessMask = 0; |
| 3351 | barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 3352 | barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; |
| 3353 | barrier.image = destImage.handle(); |
| 3354 | barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | |
| 3355 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; |
| 3356 | cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3357 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, |
| 3358 | nullptr, 1, &barrier); |
| 3359 | VkImageCopy cregion; |
| 3360 | cregion.srcSubresource.aspectMask = |
| 3361 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3362 | cregion.srcSubresource.mipLevel = 0; |
| 3363 | cregion.srcSubresource.baseArrayLayer = 0; |
| 3364 | cregion.srcSubresource.layerCount = 1; |
| 3365 | cregion.srcOffset.x = 0; |
| 3366 | cregion.srcOffset.y = 0; |
| 3367 | cregion.srcOffset.z = 0; |
| 3368 | cregion.dstSubresource.aspectMask = |
| 3369 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3370 | cregion.dstSubresource.mipLevel = 0; |
| 3371 | cregion.dstSubresource.baseArrayLayer = 0; |
| 3372 | cregion.dstSubresource.layerCount = 1; |
| 3373 | cregion.dstOffset.x = 0; |
| 3374 | cregion.dstOffset.y = 0; |
| 3375 | cregion.dstOffset.z = 0; |
| 3376 | cregion.extent.width = 100; |
| 3377 | cregion.extent.height = 100; |
| 3378 | cregion.extent.depth = 1; |
| 3379 | cmdbuf.CopyImage(m_depthStencil->handle(), |
| 3380 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(), |
| 3381 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion); |
| 3382 | cmdbuf.EndCommandBuffer(); |
| 3383 | |
| 3384 | VkSubmitInfo submit_info; |
| 3385 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3386 | submit_info.pNext = NULL; |
| 3387 | submit_info.waitSemaphoreCount = 0; |
| 3388 | submit_info.pWaitSemaphores = NULL; |
| 3389 | submit_info.pWaitDstStageMask = NULL; |
| 3390 | submit_info.commandBufferCount = 1; |
| 3391 | submit_info.pCommandBuffers = &cmdbuf.handle(); |
| 3392 | submit_info.signalSemaphoreCount = 0; |
| 3393 | submit_info.pSignalSemaphores = NULL; |
| 3394 | |
| 3395 | m_errorMonitor->ExpectSuccess(); |
| 3396 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3397 | m_errorMonitor->VerifyNotFound(); |
| 3398 | |
Mark Lobodzinski | d0440da | 2016-06-17 15:10:03 -0600 | [diff] [blame] | 3399 | vkQueueWaitIdle(m_device->m_queue); |
Mark Lobodzinski | ce7eee7 | 2016-06-14 16:33:29 -0600 | [diff] [blame] | 3400 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 3401 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3402 | vkDestroyFramebuffer(m_device->device(), fb, nullptr); |
| 3403 | } |
| 3404 | |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3405 | TEST_F(VkLayerTest, UnusedPreserveAttachment) { |
| 3406 | TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve " |
| 3407 | "attachment reference of VK_ATTACHMENT_UNUSED"); |
| 3408 | |
| 3409 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3410 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 3411 | |
| 3412 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3413 | "must not be VK_ATTACHMENT_UNUSED"); |
| 3414 | |
| 3415 | VkAttachmentReference color_attach = {}; |
| 3416 | color_attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 3417 | color_attach.attachment = 0; |
| 3418 | uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED; |
| 3419 | VkSubpassDescription subpass = {}; |
| 3420 | subpass.colorAttachmentCount = 1; |
| 3421 | subpass.pColorAttachments = &color_attach; |
| 3422 | subpass.preserveAttachmentCount = 1; |
| 3423 | subpass.pPreserveAttachments = &preserve_attachment; |
| 3424 | |
| 3425 | VkRenderPassCreateInfo rpci = {}; |
| 3426 | rpci.subpassCount = 1; |
| 3427 | rpci.pSubpasses = &subpass; |
| 3428 | rpci.attachmentCount = 1; |
| 3429 | VkAttachmentDescription attach_desc = {}; |
| 3430 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 3431 | rpci.pAttachments = &attach_desc; |
| 3432 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 3433 | VkRenderPass rp; |
Mark Lobodzinski | a4feeeb | 2016-06-17 12:00:46 -0600 | [diff] [blame] | 3434 | VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3435 | |
| 3436 | m_errorMonitor->VerifyFound(); |
| 3437 | |
Mark Lobodzinski | a4feeeb | 2016-06-17 12:00:46 -0600 | [diff] [blame] | 3438 | if (result == VK_SUCCESS) { |
| 3439 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 3440 | } |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3441 | } |
| 3442 | |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3443 | TEST_F(VkLayerTest, FramebufferCreateErrors) { |
| 3444 | TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n" |
| 3445 | " 1. Mismatch between fb & renderPass attachmentCount\n" |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 3446 | " 2. Use a color image as depthStencil attachment\n" |
Tobin Ehlis | 77d717c | 2016-06-22 14:19:19 -0600 | [diff] [blame] | 3447 | " 3. Mismatch fb & renderPass attachment formats\n" |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 3448 | " 4. Mismatch fb & renderPass attachment #samples\n" |
Tobin Ehlis | 27f2ae8 | 2016-06-23 07:36:57 -0600 | [diff] [blame] | 3449 | " 5. FB attachment w/ non-1 mip-levels\n" |
Tobin Ehlis | b1f303b | 2016-06-23 08:19:55 -0600 | [diff] [blame] | 3450 | " 6. FB attachment where dimensions don't match\n" |
Tobin Ehlis | 08d4b5e | 2016-06-23 08:52:39 -0600 | [diff] [blame] | 3451 | " 7. FB attachment w/o identity swizzle\n" |
| 3452 | " 8. FB dimensions exceed physical device limits\n"); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3453 | |
| 3454 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3455 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 3456 | |
| 3457 | m_errorMonitor->SetDesiredFailureMsg( |
| 3458 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3459 | "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 " |
| 3460 | "does not match attachmentCount of 1 of "); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3461 | |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3462 | // Create a renderPass with a single color attachment |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3463 | VkAttachmentReference attach = {}; |
| 3464 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 3465 | VkSubpassDescription subpass = {}; |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3466 | subpass.pColorAttachments = &attach; |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3467 | VkRenderPassCreateInfo rpci = {}; |
| 3468 | rpci.subpassCount = 1; |
| 3469 | rpci.pSubpasses = &subpass; |
| 3470 | rpci.attachmentCount = 1; |
| 3471 | VkAttachmentDescription attach_desc = {}; |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 3472 | attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM; |
Tobin Ehlis | 77d717c | 2016-06-22 14:19:19 -0600 | [diff] [blame] | 3473 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3474 | rpci.pAttachments = &attach_desc; |
| 3475 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 3476 | VkRenderPass rp; |
| 3477 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3478 | ASSERT_VK_SUCCESS(err); |
| 3479 | |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3480 | VkImageView ivs[2]; |
| 3481 | ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM); |
| 3482 | ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3483 | VkFramebufferCreateInfo fb_info = {}; |
| 3484 | fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
| 3485 | fb_info.pNext = NULL; |
| 3486 | fb_info.renderPass = rp; |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3487 | // Set mis-matching attachmentCount |
| 3488 | fb_info.attachmentCount = 2; |
| 3489 | fb_info.pAttachments = ivs; |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3490 | fb_info.width = 100; |
| 3491 | fb_info.height = 100; |
| 3492 | fb_info.layers = 1; |
| 3493 | |
| 3494 | VkFramebuffer fb; |
| 3495 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3496 | |
| 3497 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3498 | if (err == VK_SUCCESS) { |
| 3499 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3500 | } |
| 3501 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3502 | |
| 3503 | // Create a renderPass with a depth-stencil attachment created with |
| 3504 | // IMAGE_USAGE_COLOR_ATTACHMENT |
| 3505 | // Add our color attachment to pDepthStencilAttachment |
| 3506 | subpass.pDepthStencilAttachment = &attach; |
| 3507 | subpass.pColorAttachments = NULL; |
| 3508 | VkRenderPass rp_ds; |
| 3509 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds); |
| 3510 | ASSERT_VK_SUCCESS(err); |
| 3511 | // Set correct attachment count, but attachment has COLOR usage bit set |
| 3512 | fb_info.attachmentCount = 1; |
| 3513 | fb_info.renderPass = rp_ds; |
| 3514 | |
| 3515 | m_errorMonitor->SetDesiredFailureMsg( |
| 3516 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3517 | " conflicts with the image's IMAGE_USAGE flags "); |
| 3518 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3519 | |
| 3520 | m_errorMonitor->VerifyFound(); |
| 3521 | if (err == VK_SUCCESS) { |
| 3522 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3523 | } |
| 3524 | vkDestroyRenderPass(m_device->device(), rp_ds, NULL); |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 3525 | |
| 3526 | // Create new renderpass with alternate attachment format from fb |
| 3527 | attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 3528 | subpass.pDepthStencilAttachment = NULL; |
| 3529 | subpass.pColorAttachments = &attach; |
| 3530 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3531 | ASSERT_VK_SUCCESS(err); |
| 3532 | |
| 3533 | // Cause error due to mis-matched formats between rp & fb |
| 3534 | // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8 |
| 3535 | fb_info.renderPass = rp; |
| 3536 | m_errorMonitor->SetDesiredFailureMsg( |
| 3537 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3538 | " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match "); |
| 3539 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3540 | |
| 3541 | m_errorMonitor->VerifyFound(); |
| 3542 | if (err == VK_SUCCESS) { |
| 3543 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3544 | } |
Tobin Ehlis | 77d717c | 2016-06-22 14:19:19 -0600 | [diff] [blame] | 3545 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 3546 | |
| 3547 | // Create new renderpass with alternate sample count from fb |
| 3548 | attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 3549 | attach_desc.samples = VK_SAMPLE_COUNT_4_BIT; |
| 3550 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3551 | ASSERT_VK_SUCCESS(err); |
| 3552 | |
| 3553 | // Cause error due to mis-matched sample count between rp & fb |
| 3554 | fb_info.renderPass = rp; |
| 3555 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3556 | " has VK_SAMPLE_COUNT_1_BIT samples " |
| 3557 | "that do not match the " |
| 3558 | "VK_SAMPLE_COUNT_4_BIT "); |
| 3559 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3560 | |
| 3561 | m_errorMonitor->VerifyFound(); |
| 3562 | if (err == VK_SUCCESS) { |
| 3563 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3564 | } |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 3565 | |
| 3566 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 3567 | |
| 3568 | // Create a custom imageView with non-1 mip levels |
| 3569 | VkImageObj image(m_device); |
| 3570 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 3571 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 3572 | ASSERT_TRUE(image.initialized()); |
| 3573 | |
| 3574 | VkImageView view; |
| 3575 | VkImageViewCreateInfo ivci = {}; |
| 3576 | ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 3577 | ivci.image = image.handle(); |
| 3578 | ivci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 3579 | ivci.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 3580 | ivci.subresourceRange.layerCount = 1; |
| 3581 | ivci.subresourceRange.baseMipLevel = 0; |
| 3582 | // Set level count 2 (only 1 is allowed for FB attachment) |
| 3583 | ivci.subresourceRange.levelCount = 2; |
| 3584 | ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 3585 | err = vkCreateImageView(m_device->device(), &ivci, NULL, &view); |
| 3586 | ASSERT_VK_SUCCESS(err); |
| 3587 | // Re-create renderpass to have matching sample count |
| 3588 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
| 3589 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3590 | ASSERT_VK_SUCCESS(err); |
| 3591 | |
| 3592 | fb_info.renderPass = rp; |
| 3593 | fb_info.pAttachments = &view; |
| 3594 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3595 | " has mip levelCount of 2 but only "); |
| 3596 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3597 | |
| 3598 | m_errorMonitor->VerifyFound(); |
| 3599 | if (err == VK_SUCCESS) { |
| 3600 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3601 | } |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 3602 | vkDestroyImageView(m_device->device(), view, NULL); |
Tobin Ehlis | 27f2ae8 | 2016-06-23 07:36:57 -0600 | [diff] [blame] | 3603 | // Update view to original color buffer and grow FB dimensions too big |
| 3604 | fb_info.pAttachments = ivs; |
| 3605 | fb_info.height = 1024; |
| 3606 | fb_info.width = 1024; |
| 3607 | fb_info.layers = 2; |
| 3608 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3609 | " Attachment dimensions must be at " |
| 3610 | "least as large. "); |
| 3611 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3612 | |
| 3613 | m_errorMonitor->VerifyFound(); |
| 3614 | if (err == VK_SUCCESS) { |
| 3615 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3616 | } |
Tobin Ehlis | b1f303b | 2016-06-23 08:19:55 -0600 | [diff] [blame] | 3617 | // Create view attachment with non-identity swizzle |
| 3618 | ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 3619 | ivci.image = image.handle(); |
| 3620 | ivci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 3621 | ivci.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 3622 | ivci.subresourceRange.layerCount = 1; |
| 3623 | ivci.subresourceRange.baseMipLevel = 0; |
| 3624 | ivci.subresourceRange.levelCount = 1; |
| 3625 | ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 3626 | ivci.components.r = VK_COMPONENT_SWIZZLE_G; |
| 3627 | ivci.components.g = VK_COMPONENT_SWIZZLE_R; |
| 3628 | ivci.components.b = VK_COMPONENT_SWIZZLE_A; |
| 3629 | ivci.components.a = VK_COMPONENT_SWIZZLE_B; |
| 3630 | err = vkCreateImageView(m_device->device(), &ivci, NULL, &view); |
| 3631 | ASSERT_VK_SUCCESS(err); |
| 3632 | |
| 3633 | fb_info.pAttachments = &view; |
| 3634 | fb_info.height = 100; |
| 3635 | fb_info.width = 100; |
| 3636 | fb_info.layers = 1; |
| 3637 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3638 | " has non-identy swizzle. All " |
| 3639 | "framebuffer attachments must have " |
| 3640 | "been created with the identity " |
| 3641 | "swizzle. "); |
| 3642 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3643 | |
| 3644 | m_errorMonitor->VerifyFound(); |
| 3645 | if (err == VK_SUCCESS) { |
| 3646 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3647 | } |
| 3648 | vkDestroyImageView(m_device->device(), view, NULL); |
Tobin Ehlis | 08d4b5e | 2016-06-23 08:52:39 -0600 | [diff] [blame] | 3649 | // Request fb that exceeds max dimensions |
| 3650 | // reset attachment to color attachment |
| 3651 | fb_info.pAttachments = ivs; |
| 3652 | fb_info.width = m_device->props.limits.maxFramebufferWidth + 1; |
| 3653 | fb_info.height = m_device->props.limits.maxFramebufferHeight + 1; |
| 3654 | fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1; |
| 3655 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3656 | " Requested VkFramebufferCreateInfo " |
| 3657 | "dimensions exceed physical device " |
| 3658 | "limits. "); |
| 3659 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3660 | |
| 3661 | m_errorMonitor->VerifyFound(); |
| 3662 | if (err == VK_SUCCESS) { |
| 3663 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3664 | } |
Tobin Ehlis | 27f2ae8 | 2016-06-23 07:36:57 -0600 | [diff] [blame] | 3665 | |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 3666 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3667 | } |
| 3668 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3669 | // This is a positive test. No errors should be generated. |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3670 | TEST_F(VkLayerTest, WaitEventThenSet) { |
| 3671 | TEST_DESCRIPTION( |
| 3672 | "Wait on a event then set it after the wait has been submitted."); |
| 3673 | |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3674 | m_errorMonitor->ExpectSuccess(); |
| 3675 | |
| 3676 | VkEvent event; |
| 3677 | VkEventCreateInfo event_create_info{}; |
| 3678 | event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 3679 | vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event); |
| 3680 | |
| 3681 | VkCommandPool command_pool; |
| 3682 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3683 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3684 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3685 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3686 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3687 | &command_pool); |
| 3688 | |
| 3689 | VkCommandBuffer command_buffer; |
| 3690 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3691 | command_buffer_allocate_info.sType = |
| 3692 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3693 | command_buffer_allocate_info.commandPool = command_pool; |
| 3694 | command_buffer_allocate_info.commandBufferCount = 1; |
| 3695 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3696 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3697 | &command_buffer); |
| 3698 | |
| 3699 | VkQueue queue = VK_NULL_HANDLE; |
| 3700 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
Tony Barbour | fe302c0 | 2016-06-06 13:05:19 -0600 | [diff] [blame] | 3701 | 0, &queue); |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3702 | |
| 3703 | { |
| 3704 | VkCommandBufferBeginInfo begin_info{}; |
| 3705 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3706 | vkBeginCommandBuffer(command_buffer, &begin_info); |
| 3707 | |
| 3708 | vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, |
| 3709 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, |
| 3710 | nullptr, 0, nullptr); |
| 3711 | vkCmdResetEvent(command_buffer, event, |
| 3712 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 3713 | vkEndCommandBuffer(command_buffer); |
| 3714 | } |
| 3715 | { |
| 3716 | VkSubmitInfo submit_info{}; |
| 3717 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3718 | submit_info.commandBufferCount = 1; |
| 3719 | submit_info.pCommandBuffers = &command_buffer; |
| 3720 | submit_info.signalSemaphoreCount = 0; |
| 3721 | submit_info.pSignalSemaphores = nullptr; |
| 3722 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3723 | } |
| 3724 | { vkSetEvent(m_device->device(), event); } |
| 3725 | |
| 3726 | vkQueueWaitIdle(queue); |
| 3727 | |
| 3728 | vkDestroyEvent(m_device->device(), event, nullptr); |
| 3729 | vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer); |
| 3730 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3731 | |
| 3732 | m_errorMonitor->VerifyNotFound(); |
| 3733 | } |
Michael Lentine | 5627e69 | 2016-05-20 17:45:02 -0500 | [diff] [blame] | 3734 | // This is a positive test. No errors should be generated. |
| 3735 | TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) { |
| 3736 | TEST_DESCRIPTION( |
| 3737 | "Issue a query and copy from it on a second command buffer."); |
| 3738 | |
| 3739 | if ((m_device->queue_props.empty()) || |
| 3740 | (m_device->queue_props[0].queueCount < 2)) |
| 3741 | return; |
| 3742 | |
| 3743 | m_errorMonitor->ExpectSuccess(); |
| 3744 | |
| 3745 | VkQueryPool query_pool; |
| 3746 | VkQueryPoolCreateInfo query_pool_create_info{}; |
| 3747 | query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; |
| 3748 | query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP; |
| 3749 | query_pool_create_info.queryCount = 1; |
| 3750 | vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, |
| 3751 | &query_pool); |
| 3752 | |
| 3753 | VkCommandPool command_pool; |
| 3754 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3755 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3756 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3757 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3758 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3759 | &command_pool); |
| 3760 | |
| 3761 | VkCommandBuffer command_buffer[2]; |
| 3762 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3763 | command_buffer_allocate_info.sType = |
| 3764 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3765 | command_buffer_allocate_info.commandPool = command_pool; |
| 3766 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3767 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3768 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3769 | command_buffer); |
| 3770 | |
| 3771 | VkQueue queue = VK_NULL_HANDLE; |
| 3772 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3773 | 1, &queue); |
| 3774 | |
| 3775 | uint32_t qfi = 0; |
| 3776 | VkBufferCreateInfo buff_create_info = {}; |
| 3777 | buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 3778 | buff_create_info.size = 1024; |
| 3779 | buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT; |
| 3780 | buff_create_info.queueFamilyIndexCount = 1; |
| 3781 | buff_create_info.pQueueFamilyIndices = &qfi; |
| 3782 | |
| 3783 | VkResult err; |
| 3784 | VkBuffer buffer; |
| 3785 | err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer); |
| 3786 | ASSERT_VK_SUCCESS(err); |
| 3787 | VkMemoryAllocateInfo mem_alloc = {}; |
| 3788 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 3789 | mem_alloc.pNext = NULL; |
| 3790 | mem_alloc.allocationSize = 1024; |
| 3791 | mem_alloc.memoryTypeIndex = 0; |
| 3792 | |
| 3793 | VkMemoryRequirements memReqs; |
| 3794 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs); |
| 3795 | bool pass = |
| 3796 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0); |
| 3797 | if (!pass) { |
| 3798 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 3799 | return; |
| 3800 | } |
| 3801 | |
| 3802 | VkDeviceMemory mem; |
| 3803 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 3804 | ASSERT_VK_SUCCESS(err); |
| 3805 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 3806 | ASSERT_VK_SUCCESS(err); |
| 3807 | |
| 3808 | { |
| 3809 | VkCommandBufferBeginInfo begin_info{}; |
| 3810 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3811 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3812 | |
| 3813 | vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1); |
| 3814 | vkCmdWriteTimestamp(command_buffer[0], |
| 3815 | VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0); |
| 3816 | |
| 3817 | vkEndCommandBuffer(command_buffer[0]); |
| 3818 | |
| 3819 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3820 | |
| 3821 | vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, |
| 3822 | 0, 0, 0); |
| 3823 | |
| 3824 | vkEndCommandBuffer(command_buffer[1]); |
| 3825 | } |
| 3826 | { |
| 3827 | VkSubmitInfo submit_info{}; |
| 3828 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3829 | submit_info.commandBufferCount = 2; |
| 3830 | submit_info.pCommandBuffers = command_buffer; |
| 3831 | submit_info.signalSemaphoreCount = 0; |
| 3832 | submit_info.pSignalSemaphores = nullptr; |
| 3833 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3834 | } |
| 3835 | |
| 3836 | vkQueueWaitIdle(queue); |
| 3837 | |
| 3838 | vkDestroyQueryPool(m_device->device(), query_pool, nullptr); |
| 3839 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer); |
| 3840 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 3841 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 3842 | vkFreeMemory(m_device->device(), mem, NULL); |
Michael Lentine | 5627e69 | 2016-05-20 17:45:02 -0500 | [diff] [blame] | 3843 | |
| 3844 | m_errorMonitor->VerifyNotFound(); |
| 3845 | } |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3846 | |
| 3847 | TEST_F(VkLayerTest, ResetEventThenSet) { |
| 3848 | TEST_DESCRIPTION( |
| 3849 | "Reset an event then set it after the reset has been submitted."); |
| 3850 | |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3851 | m_errorMonitor->ExpectSuccess(); |
| 3852 | |
| 3853 | VkEvent event; |
| 3854 | VkEventCreateInfo event_create_info{}; |
| 3855 | event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 3856 | vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event); |
| 3857 | |
| 3858 | VkCommandPool command_pool; |
| 3859 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3860 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3861 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3862 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3863 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3864 | &command_pool); |
| 3865 | |
| 3866 | VkCommandBuffer command_buffer; |
| 3867 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3868 | command_buffer_allocate_info.sType = |
| 3869 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3870 | command_buffer_allocate_info.commandPool = command_pool; |
| 3871 | command_buffer_allocate_info.commandBufferCount = 1; |
| 3872 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3873 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3874 | &command_buffer); |
| 3875 | |
| 3876 | VkQueue queue = VK_NULL_HANDLE; |
| 3877 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
Tony Barbour | fe302c0 | 2016-06-06 13:05:19 -0600 | [diff] [blame] | 3878 | 0, &queue); |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3879 | |
| 3880 | { |
| 3881 | VkCommandBufferBeginInfo begin_info{}; |
| 3882 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3883 | vkBeginCommandBuffer(command_buffer, &begin_info); |
| 3884 | |
| 3885 | vkCmdResetEvent(command_buffer, event, |
| 3886 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 3887 | vkCmdWaitEvents(command_buffer, 1, &event, |
| 3888 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3889 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, |
| 3890 | nullptr, 0, nullptr); |
| 3891 | vkEndCommandBuffer(command_buffer); |
| 3892 | } |
| 3893 | { |
| 3894 | VkSubmitInfo submit_info{}; |
| 3895 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3896 | submit_info.commandBufferCount = 1; |
| 3897 | submit_info.pCommandBuffers = &command_buffer; |
| 3898 | submit_info.signalSemaphoreCount = 0; |
| 3899 | submit_info.pSignalSemaphores = nullptr; |
| 3900 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3901 | } |
| 3902 | { |
| 3903 | m_errorMonitor->SetDesiredFailureMsg( |
| 3904 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkSetEvent() on event " |
| 3905 | "0x1 that is already in use by a " |
| 3906 | "command buffer."); |
| 3907 | vkSetEvent(m_device->device(), event); |
| 3908 | m_errorMonitor->VerifyFound(); |
| 3909 | } |
| 3910 | |
| 3911 | vkQueueWaitIdle(queue); |
| 3912 | |
| 3913 | vkDestroyEvent(m_device->device(), event, nullptr); |
| 3914 | vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer); |
| 3915 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3916 | } |
| 3917 | |
| 3918 | // This is a positive test. No errors should be generated. |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3919 | TEST_F(VkLayerTest, TwoFencesThreeFrames) { |
| 3920 | TEST_DESCRIPTION("Two command buffers with two separate fences are each " |
| 3921 | "run through a Submit & WaitForFences cycle 3 times. This " |
| 3922 | "previously revealed a bug so running this positive test " |
| 3923 | "to prevent a regression."); |
| 3924 | m_errorMonitor->ExpectSuccess(); |
| 3925 | |
| 3926 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3927 | VkQueue queue = VK_NULL_HANDLE; |
| 3928 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3929 | 0, &queue); |
| 3930 | |
| 3931 | static const uint32_t NUM_OBJECTS = 2; |
| 3932 | static const uint32_t NUM_FRAMES = 3; |
| 3933 | VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {}; |
| 3934 | VkFence fences[NUM_OBJECTS] = {}; |
| 3935 | |
| 3936 | VkCommandPool cmd_pool; |
| 3937 | VkCommandPoolCreateInfo cmd_pool_ci = {}; |
| 3938 | cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3939 | cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3940 | cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3941 | VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, |
| 3942 | nullptr, &cmd_pool); |
| 3943 | ASSERT_VK_SUCCESS(err); |
| 3944 | |
| 3945 | VkCommandBufferAllocateInfo cmd_buf_info = {}; |
| 3946 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3947 | cmd_buf_info.commandPool = cmd_pool; |
| 3948 | cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3949 | cmd_buf_info.commandBufferCount = 1; |
| 3950 | |
| 3951 | VkFenceCreateInfo fence_ci = {}; |
| 3952 | fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3953 | fence_ci.pNext = nullptr; |
| 3954 | fence_ci.flags = 0; |
| 3955 | |
| 3956 | for (uint32_t i = 0; i < NUM_OBJECTS; ++i) { |
| 3957 | err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, |
| 3958 | &cmd_buffers[i]); |
| 3959 | ASSERT_VK_SUCCESS(err); |
| 3960 | err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]); |
| 3961 | ASSERT_VK_SUCCESS(err); |
| 3962 | } |
| 3963 | |
| 3964 | for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) { |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 3965 | for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) { |
| 3966 | // Create empty cmd buffer |
| 3967 | VkCommandBufferBeginInfo cmdBufBeginDesc = {}; |
| 3968 | cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3969 | |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 3970 | err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc); |
| 3971 | ASSERT_VK_SUCCESS(err); |
| 3972 | err = vkEndCommandBuffer(cmd_buffers[obj]); |
| 3973 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3974 | |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 3975 | VkSubmitInfo submit_info = {}; |
| 3976 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3977 | submit_info.commandBufferCount = 1; |
| 3978 | submit_info.pCommandBuffers = &cmd_buffers[obj]; |
| 3979 | // Submit cmd buffer and wait for fence |
| 3980 | err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]); |
| 3981 | ASSERT_VK_SUCCESS(err); |
| 3982 | err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, |
| 3983 | UINT64_MAX); |
| 3984 | ASSERT_VK_SUCCESS(err); |
| 3985 | err = vkResetFences(m_device->device(), 1, &fences[obj]); |
| 3986 | ASSERT_VK_SUCCESS(err); |
| 3987 | } |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3988 | } |
| 3989 | m_errorMonitor->VerifyNotFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 3990 | vkDestroyCommandPool(m_device->device(), cmd_pool, NULL); |
| 3991 | for (uint32_t i = 0; i < NUM_OBJECTS; ++i) { |
| 3992 | vkDestroyFence(m_device->device(), fences[i], nullptr); |
| 3993 | } |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3994 | } |
| 3995 | // This is a positive test. No errors should be generated. |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3996 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) { |
| 3997 | |
| 3998 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 3999 | "submitted on separate queues followed by a QueueWaitIdle."); |
| 4000 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 4001 | if ((m_device->queue_props.empty()) || |
| 4002 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 4003 | return; |
| 4004 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4005 | m_errorMonitor->ExpectSuccess(); |
| 4006 | |
| 4007 | VkSemaphore semaphore; |
| 4008 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4009 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4010 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4011 | &semaphore); |
| 4012 | |
| 4013 | VkCommandPool command_pool; |
| 4014 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4015 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4016 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4017 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4018 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4019 | &command_pool); |
| 4020 | |
| 4021 | VkCommandBuffer command_buffer[2]; |
| 4022 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4023 | command_buffer_allocate_info.sType = |
| 4024 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4025 | command_buffer_allocate_info.commandPool = command_pool; |
| 4026 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4027 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4028 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4029 | command_buffer); |
| 4030 | |
| 4031 | VkQueue queue = VK_NULL_HANDLE; |
| 4032 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4033 | 1, &queue); |
| 4034 | |
| 4035 | { |
| 4036 | VkCommandBufferBeginInfo begin_info{}; |
| 4037 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4038 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4039 | |
| 4040 | vkCmdPipelineBarrier(command_buffer[0], |
| 4041 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4042 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4043 | 0, nullptr, 0, nullptr); |
| 4044 | |
| 4045 | VkViewport viewport{}; |
| 4046 | viewport.maxDepth = 1.0f; |
| 4047 | viewport.minDepth = 0.0f; |
| 4048 | viewport.width = 512; |
| 4049 | viewport.height = 512; |
| 4050 | viewport.x = 0; |
| 4051 | viewport.y = 0; |
| 4052 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4053 | vkEndCommandBuffer(command_buffer[0]); |
| 4054 | } |
| 4055 | { |
| 4056 | VkCommandBufferBeginInfo begin_info{}; |
| 4057 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4058 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4059 | |
| 4060 | VkViewport viewport{}; |
| 4061 | viewport.maxDepth = 1.0f; |
| 4062 | viewport.minDepth = 0.0f; |
| 4063 | viewport.width = 512; |
| 4064 | viewport.height = 512; |
| 4065 | viewport.x = 0; |
| 4066 | viewport.y = 0; |
| 4067 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4068 | vkEndCommandBuffer(command_buffer[1]); |
| 4069 | } |
| 4070 | { |
| 4071 | VkSubmitInfo submit_info{}; |
| 4072 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4073 | submit_info.commandBufferCount = 1; |
| 4074 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4075 | submit_info.signalSemaphoreCount = 1; |
| 4076 | submit_info.pSignalSemaphores = &semaphore; |
| 4077 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4078 | } |
| 4079 | { |
| 4080 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4081 | VkSubmitInfo submit_info{}; |
| 4082 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4083 | submit_info.commandBufferCount = 1; |
| 4084 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4085 | submit_info.waitSemaphoreCount = 1; |
| 4086 | submit_info.pWaitSemaphores = &semaphore; |
| 4087 | submit_info.pWaitDstStageMask = flags; |
| 4088 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4089 | } |
| 4090 | |
| 4091 | vkQueueWaitIdle(m_device->m_queue); |
| 4092 | |
| 4093 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4094 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4095 | &command_buffer[0]); |
| 4096 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4097 | |
| 4098 | m_errorMonitor->VerifyNotFound(); |
| 4099 | } |
| 4100 | |
| 4101 | // This is a positive test. No errors should be generated. |
| 4102 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) { |
| 4103 | |
| 4104 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4105 | "submitted on separate queues, the second having a fence" |
| 4106 | "followed by a QueueWaitIdle."); |
| 4107 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 4108 | if ((m_device->queue_props.empty()) || |
| 4109 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 4110 | return; |
| 4111 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4112 | m_errorMonitor->ExpectSuccess(); |
| 4113 | |
| 4114 | VkFence fence; |
| 4115 | VkFenceCreateInfo fence_create_info{}; |
| 4116 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4117 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4118 | |
| 4119 | VkSemaphore semaphore; |
| 4120 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4121 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4122 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4123 | &semaphore); |
| 4124 | |
| 4125 | VkCommandPool command_pool; |
| 4126 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4127 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4128 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4129 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4130 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4131 | &command_pool); |
| 4132 | |
| 4133 | VkCommandBuffer command_buffer[2]; |
| 4134 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4135 | command_buffer_allocate_info.sType = |
| 4136 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4137 | command_buffer_allocate_info.commandPool = command_pool; |
| 4138 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4139 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4140 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4141 | command_buffer); |
| 4142 | |
| 4143 | VkQueue queue = VK_NULL_HANDLE; |
| 4144 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4145 | 1, &queue); |
| 4146 | |
| 4147 | { |
| 4148 | VkCommandBufferBeginInfo begin_info{}; |
| 4149 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4150 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4151 | |
| 4152 | vkCmdPipelineBarrier(command_buffer[0], |
| 4153 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4154 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4155 | 0, nullptr, 0, nullptr); |
| 4156 | |
| 4157 | VkViewport viewport{}; |
| 4158 | viewport.maxDepth = 1.0f; |
| 4159 | viewport.minDepth = 0.0f; |
| 4160 | viewport.width = 512; |
| 4161 | viewport.height = 512; |
| 4162 | viewport.x = 0; |
| 4163 | viewport.y = 0; |
| 4164 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4165 | vkEndCommandBuffer(command_buffer[0]); |
| 4166 | } |
| 4167 | { |
| 4168 | VkCommandBufferBeginInfo begin_info{}; |
| 4169 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4170 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4171 | |
| 4172 | VkViewport viewport{}; |
| 4173 | viewport.maxDepth = 1.0f; |
| 4174 | viewport.minDepth = 0.0f; |
| 4175 | viewport.width = 512; |
| 4176 | viewport.height = 512; |
| 4177 | viewport.x = 0; |
| 4178 | viewport.y = 0; |
| 4179 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4180 | vkEndCommandBuffer(command_buffer[1]); |
| 4181 | } |
| 4182 | { |
| 4183 | VkSubmitInfo submit_info{}; |
| 4184 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4185 | submit_info.commandBufferCount = 1; |
| 4186 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4187 | submit_info.signalSemaphoreCount = 1; |
| 4188 | submit_info.pSignalSemaphores = &semaphore; |
| 4189 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4190 | } |
| 4191 | { |
| 4192 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4193 | VkSubmitInfo submit_info{}; |
| 4194 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4195 | submit_info.commandBufferCount = 1; |
| 4196 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4197 | submit_info.waitSemaphoreCount = 1; |
| 4198 | submit_info.pWaitSemaphores = &semaphore; |
| 4199 | submit_info.pWaitDstStageMask = flags; |
| 4200 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4201 | } |
| 4202 | |
| 4203 | vkQueueWaitIdle(m_device->m_queue); |
| 4204 | |
| 4205 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4206 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4207 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4208 | &command_buffer[0]); |
| 4209 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4210 | |
| 4211 | m_errorMonitor->VerifyNotFound(); |
| 4212 | } |
| 4213 | |
| 4214 | // This is a positive test. No errors should be generated. |
| 4215 | TEST_F(VkLayerTest, |
| 4216 | TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) { |
| 4217 | |
| 4218 | TEST_DESCRIPTION( |
| 4219 | "Two command buffers, each in a separate QueueSubmit call " |
| 4220 | "submitted on separate queues, the second having a fence" |
| 4221 | "followed by two consecutive WaitForFences calls on the same fence."); |
| 4222 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 4223 | if ((m_device->queue_props.empty()) || |
| 4224 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 4225 | return; |
| 4226 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4227 | m_errorMonitor->ExpectSuccess(); |
| 4228 | |
| 4229 | VkFence fence; |
| 4230 | VkFenceCreateInfo fence_create_info{}; |
| 4231 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4232 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4233 | |
| 4234 | VkSemaphore semaphore; |
| 4235 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4236 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4237 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4238 | &semaphore); |
| 4239 | |
| 4240 | VkCommandPool command_pool; |
| 4241 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4242 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4243 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4244 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4245 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4246 | &command_pool); |
| 4247 | |
| 4248 | VkCommandBuffer command_buffer[2]; |
| 4249 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4250 | command_buffer_allocate_info.sType = |
| 4251 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4252 | command_buffer_allocate_info.commandPool = command_pool; |
| 4253 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4254 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4255 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4256 | command_buffer); |
| 4257 | |
| 4258 | VkQueue queue = VK_NULL_HANDLE; |
| 4259 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4260 | 1, &queue); |
| 4261 | |
| 4262 | { |
| 4263 | VkCommandBufferBeginInfo begin_info{}; |
| 4264 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4265 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4266 | |
| 4267 | vkCmdPipelineBarrier(command_buffer[0], |
| 4268 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4269 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4270 | 0, nullptr, 0, nullptr); |
| 4271 | |
| 4272 | VkViewport viewport{}; |
| 4273 | viewport.maxDepth = 1.0f; |
| 4274 | viewport.minDepth = 0.0f; |
| 4275 | viewport.width = 512; |
| 4276 | viewport.height = 512; |
| 4277 | viewport.x = 0; |
| 4278 | viewport.y = 0; |
| 4279 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4280 | vkEndCommandBuffer(command_buffer[0]); |
| 4281 | } |
| 4282 | { |
| 4283 | VkCommandBufferBeginInfo begin_info{}; |
| 4284 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4285 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4286 | |
| 4287 | VkViewport viewport{}; |
| 4288 | viewport.maxDepth = 1.0f; |
| 4289 | viewport.minDepth = 0.0f; |
| 4290 | viewport.width = 512; |
| 4291 | viewport.height = 512; |
| 4292 | viewport.x = 0; |
| 4293 | viewport.y = 0; |
| 4294 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4295 | vkEndCommandBuffer(command_buffer[1]); |
| 4296 | } |
| 4297 | { |
| 4298 | VkSubmitInfo submit_info{}; |
| 4299 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4300 | submit_info.commandBufferCount = 1; |
| 4301 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4302 | submit_info.signalSemaphoreCount = 1; |
| 4303 | submit_info.pSignalSemaphores = &semaphore; |
| 4304 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4305 | } |
| 4306 | { |
| 4307 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4308 | VkSubmitInfo submit_info{}; |
| 4309 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4310 | submit_info.commandBufferCount = 1; |
| 4311 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4312 | submit_info.waitSemaphoreCount = 1; |
| 4313 | submit_info.pWaitSemaphores = &semaphore; |
| 4314 | submit_info.pWaitDstStageMask = flags; |
| 4315 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4316 | } |
| 4317 | |
| 4318 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4319 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4320 | |
| 4321 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4322 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4323 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4324 | &command_buffer[0]); |
| 4325 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4326 | |
| 4327 | m_errorMonitor->VerifyNotFound(); |
| 4328 | } |
| 4329 | |
Chris Forbes | 0f8126b | 2016-06-20 17:48:22 +1200 | [diff] [blame] | 4330 | #if 0 |
| 4331 | TEST_F(VkLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) { |
| 4332 | if ((m_device->queue_props.empty()) || |
| 4333 | (m_device->queue_props[0].queueCount < 2)) { |
| 4334 | printf("Test requires two queues, skipping\n"); |
| 4335 | return; |
| 4336 | } |
| 4337 | |
| 4338 | VkResult err; |
| 4339 | |
| 4340 | m_errorMonitor->ExpectSuccess(); |
| 4341 | |
| 4342 | VkQueue q0 = m_device->m_queue; |
| 4343 | VkQueue q1 = nullptr; |
| 4344 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1); |
| 4345 | ASSERT_NE(q1, nullptr); |
| 4346 | |
| 4347 | // An (empty) command buffer. We must have work in the first submission -- |
| 4348 | // the layer treats unfenced work differently from fenced work. |
| 4349 | VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 }; |
| 4350 | VkCommandPool pool; |
| 4351 | err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool); |
| 4352 | ASSERT_VK_SUCCESS(err); |
| 4353 | VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, |
| 4354 | pool, VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 |
| 4355 | }; |
| 4356 | VkCommandBuffer cb; |
| 4357 | err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb); |
| 4358 | ASSERT_VK_SUCCESS(err); |
| 4359 | VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, |
| 4360 | 0, nullptr |
| 4361 | }; |
| 4362 | err = vkBeginCommandBuffer(cb, &cbbi); |
| 4363 | ASSERT_VK_SUCCESS(err); |
| 4364 | err = vkEndCommandBuffer(cb); |
| 4365 | ASSERT_VK_SUCCESS(err); |
| 4366 | |
| 4367 | // A semaphore |
| 4368 | VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 }; |
| 4369 | VkSemaphore s; |
| 4370 | err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s); |
| 4371 | ASSERT_VK_SUCCESS(err); |
| 4372 | |
| 4373 | // First submission, to q0 |
| 4374 | VkSubmitInfo s0 = { |
| 4375 | VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, |
| 4376 | 0, nullptr, nullptr, |
| 4377 | 1, &cb, |
| 4378 | 1, &s |
| 4379 | }; |
| 4380 | |
| 4381 | err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE); |
| 4382 | ASSERT_VK_SUCCESS(err); |
| 4383 | |
| 4384 | // Second submission, to q1, waiting on s |
| 4385 | VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is. |
| 4386 | VkSubmitInfo s1 = { |
| 4387 | VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, |
| 4388 | 1, &s, &waitmask, |
| 4389 | 0, nullptr, |
| 4390 | 0, nullptr |
| 4391 | }; |
| 4392 | |
| 4393 | err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE); |
| 4394 | ASSERT_VK_SUCCESS(err); |
| 4395 | |
| 4396 | // Wait for q0 idle |
| 4397 | err = vkQueueWaitIdle(q0); |
| 4398 | ASSERT_VK_SUCCESS(err); |
| 4399 | |
| 4400 | // Command buffer should have been completed (it was on q0); reset the pool. |
| 4401 | vkFreeCommandBuffers(m_device->device(), pool, 1, &cb); |
| 4402 | |
| 4403 | m_errorMonitor->VerifyNotFound(); |
| 4404 | |
| 4405 | // Force device completely idle and clean up resources |
| 4406 | vkDeviceWaitIdle(m_device->device()); |
| 4407 | vkDestroyCommandPool(m_device->device(), pool, nullptr); |
| 4408 | vkDestroySemaphore(m_device->device(), s, nullptr); |
| 4409 | } |
| 4410 | #endif |
| 4411 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4412 | // This is a positive test. No errors should be generated. |
| 4413 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) { |
| 4414 | |
| 4415 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4416 | "submitted on separate queues, the second having a fence, " |
| 4417 | "followed by a WaitForFences call."); |
| 4418 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 4419 | if ((m_device->queue_props.empty()) || |
| 4420 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 4421 | return; |
| 4422 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4423 | m_errorMonitor->ExpectSuccess(); |
| 4424 | |
| 4425 | VkFence fence; |
| 4426 | VkFenceCreateInfo fence_create_info{}; |
| 4427 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4428 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4429 | |
| 4430 | VkSemaphore semaphore; |
| 4431 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4432 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4433 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4434 | &semaphore); |
| 4435 | |
| 4436 | VkCommandPool command_pool; |
| 4437 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4438 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4439 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4440 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4441 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4442 | &command_pool); |
| 4443 | |
| 4444 | VkCommandBuffer command_buffer[2]; |
| 4445 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4446 | command_buffer_allocate_info.sType = |
| 4447 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4448 | command_buffer_allocate_info.commandPool = command_pool; |
| 4449 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4450 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4451 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4452 | command_buffer); |
| 4453 | |
| 4454 | VkQueue queue = VK_NULL_HANDLE; |
| 4455 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4456 | 1, &queue); |
| 4457 | |
| 4458 | |
| 4459 | { |
| 4460 | VkCommandBufferBeginInfo begin_info{}; |
| 4461 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4462 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4463 | |
| 4464 | vkCmdPipelineBarrier(command_buffer[0], |
| 4465 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4466 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4467 | 0, nullptr, 0, nullptr); |
| 4468 | |
| 4469 | VkViewport viewport{}; |
| 4470 | viewport.maxDepth = 1.0f; |
| 4471 | viewport.minDepth = 0.0f; |
| 4472 | viewport.width = 512; |
| 4473 | viewport.height = 512; |
| 4474 | viewport.x = 0; |
| 4475 | viewport.y = 0; |
| 4476 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4477 | vkEndCommandBuffer(command_buffer[0]); |
| 4478 | } |
| 4479 | { |
| 4480 | VkCommandBufferBeginInfo begin_info{}; |
| 4481 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4482 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4483 | |
| 4484 | VkViewport viewport{}; |
| 4485 | viewport.maxDepth = 1.0f; |
| 4486 | viewport.minDepth = 0.0f; |
| 4487 | viewport.width = 512; |
| 4488 | viewport.height = 512; |
| 4489 | viewport.x = 0; |
| 4490 | viewport.y = 0; |
| 4491 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4492 | vkEndCommandBuffer(command_buffer[1]); |
| 4493 | } |
| 4494 | { |
| 4495 | VkSubmitInfo submit_info{}; |
| 4496 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4497 | submit_info.commandBufferCount = 1; |
| 4498 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4499 | submit_info.signalSemaphoreCount = 1; |
| 4500 | submit_info.pSignalSemaphores = &semaphore; |
| 4501 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4502 | } |
| 4503 | { |
| 4504 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4505 | VkSubmitInfo submit_info{}; |
| 4506 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4507 | submit_info.commandBufferCount = 1; |
| 4508 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4509 | submit_info.waitSemaphoreCount = 1; |
| 4510 | submit_info.pWaitSemaphores = &semaphore; |
| 4511 | submit_info.pWaitDstStageMask = flags; |
| 4512 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4513 | } |
| 4514 | |
| 4515 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4516 | |
| 4517 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4518 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4519 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4520 | &command_buffer[0]); |
| 4521 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4522 | |
| 4523 | m_errorMonitor->VerifyNotFound(); |
| 4524 | } |
| 4525 | |
| 4526 | // This is a positive test. No errors should be generated. |
| 4527 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) { |
| 4528 | |
| 4529 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4530 | "on the same queue, sharing a signal/wait semaphore, the " |
| 4531 | "second having a fence, " |
| 4532 | "followed by a WaitForFences call."); |
| 4533 | |
| 4534 | m_errorMonitor->ExpectSuccess(); |
| 4535 | |
| 4536 | VkFence fence; |
| 4537 | VkFenceCreateInfo fence_create_info{}; |
| 4538 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4539 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4540 | |
| 4541 | VkSemaphore semaphore; |
| 4542 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4543 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4544 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4545 | &semaphore); |
| 4546 | |
| 4547 | VkCommandPool command_pool; |
| 4548 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4549 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4550 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4551 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4552 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4553 | &command_pool); |
| 4554 | |
| 4555 | VkCommandBuffer command_buffer[2]; |
| 4556 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4557 | command_buffer_allocate_info.sType = |
| 4558 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4559 | command_buffer_allocate_info.commandPool = command_pool; |
| 4560 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4561 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4562 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4563 | command_buffer); |
| 4564 | |
| 4565 | { |
| 4566 | VkCommandBufferBeginInfo begin_info{}; |
| 4567 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4568 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4569 | |
| 4570 | vkCmdPipelineBarrier(command_buffer[0], |
| 4571 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4572 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4573 | 0, nullptr, 0, nullptr); |
| 4574 | |
| 4575 | VkViewport viewport{}; |
| 4576 | viewport.maxDepth = 1.0f; |
| 4577 | viewport.minDepth = 0.0f; |
| 4578 | viewport.width = 512; |
| 4579 | viewport.height = 512; |
| 4580 | viewport.x = 0; |
| 4581 | viewport.y = 0; |
| 4582 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4583 | vkEndCommandBuffer(command_buffer[0]); |
| 4584 | } |
| 4585 | { |
| 4586 | VkCommandBufferBeginInfo begin_info{}; |
| 4587 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4588 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4589 | |
| 4590 | VkViewport viewport{}; |
| 4591 | viewport.maxDepth = 1.0f; |
| 4592 | viewport.minDepth = 0.0f; |
| 4593 | viewport.width = 512; |
| 4594 | viewport.height = 512; |
| 4595 | viewport.x = 0; |
| 4596 | viewport.y = 0; |
| 4597 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4598 | vkEndCommandBuffer(command_buffer[1]); |
| 4599 | } |
| 4600 | { |
| 4601 | VkSubmitInfo submit_info{}; |
| 4602 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4603 | submit_info.commandBufferCount = 1; |
| 4604 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4605 | submit_info.signalSemaphoreCount = 1; |
| 4606 | submit_info.pSignalSemaphores = &semaphore; |
| 4607 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4608 | } |
| 4609 | { |
| 4610 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4611 | VkSubmitInfo submit_info{}; |
| 4612 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4613 | submit_info.commandBufferCount = 1; |
| 4614 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4615 | submit_info.waitSemaphoreCount = 1; |
| 4616 | submit_info.pWaitSemaphores = &semaphore; |
| 4617 | submit_info.pWaitDstStageMask = flags; |
| 4618 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4619 | } |
| 4620 | |
| 4621 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4622 | |
| 4623 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4624 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4625 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4626 | &command_buffer[0]); |
| 4627 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4628 | |
| 4629 | m_errorMonitor->VerifyNotFound(); |
| 4630 | } |
| 4631 | |
| 4632 | // This is a positive test. No errors should be generated. |
| 4633 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) { |
| 4634 | |
| 4635 | TEST_DESCRIPTION( |
| 4636 | "Two command buffers, each in a separate QueueSubmit call " |
| 4637 | "on the same queue, no fences, followed by a third QueueSubmit with NO " |
| 4638 | "SubmitInfos but with a fence, followed by a WaitForFences call."); |
| 4639 | |
| 4640 | m_errorMonitor->ExpectSuccess(); |
| 4641 | |
| 4642 | VkFence fence; |
| 4643 | VkFenceCreateInfo fence_create_info{}; |
| 4644 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4645 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4646 | |
| 4647 | VkCommandPool command_pool; |
| 4648 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4649 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4650 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4651 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4652 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4653 | &command_pool); |
| 4654 | |
| 4655 | VkCommandBuffer command_buffer[2]; |
| 4656 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4657 | command_buffer_allocate_info.sType = |
| 4658 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4659 | command_buffer_allocate_info.commandPool = command_pool; |
| 4660 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4661 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4662 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4663 | command_buffer); |
| 4664 | |
| 4665 | { |
| 4666 | VkCommandBufferBeginInfo begin_info{}; |
| 4667 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4668 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4669 | |
| 4670 | vkCmdPipelineBarrier(command_buffer[0], |
| 4671 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4672 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4673 | 0, nullptr, 0, nullptr); |
| 4674 | |
| 4675 | VkViewport viewport{}; |
| 4676 | viewport.maxDepth = 1.0f; |
| 4677 | viewport.minDepth = 0.0f; |
| 4678 | viewport.width = 512; |
| 4679 | viewport.height = 512; |
| 4680 | viewport.x = 0; |
| 4681 | viewport.y = 0; |
| 4682 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4683 | vkEndCommandBuffer(command_buffer[0]); |
| 4684 | } |
| 4685 | { |
| 4686 | VkCommandBufferBeginInfo begin_info{}; |
| 4687 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4688 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4689 | |
| 4690 | VkViewport viewport{}; |
| 4691 | viewport.maxDepth = 1.0f; |
| 4692 | viewport.minDepth = 0.0f; |
| 4693 | viewport.width = 512; |
| 4694 | viewport.height = 512; |
| 4695 | viewport.x = 0; |
| 4696 | viewport.y = 0; |
| 4697 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4698 | vkEndCommandBuffer(command_buffer[1]); |
| 4699 | } |
| 4700 | { |
| 4701 | VkSubmitInfo submit_info{}; |
| 4702 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4703 | submit_info.commandBufferCount = 1; |
| 4704 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4705 | submit_info.signalSemaphoreCount = 0; |
| 4706 | submit_info.pSignalSemaphores = VK_NULL_HANDLE; |
| 4707 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4708 | } |
| 4709 | { |
| 4710 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4711 | VkSubmitInfo submit_info{}; |
| 4712 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4713 | submit_info.commandBufferCount = 1; |
| 4714 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4715 | submit_info.waitSemaphoreCount = 0; |
| 4716 | submit_info.pWaitSemaphores = VK_NULL_HANDLE; |
| 4717 | submit_info.pWaitDstStageMask = flags; |
| 4718 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4719 | } |
| 4720 | |
| 4721 | vkQueueSubmit(m_device->m_queue, 0, NULL, fence); |
| 4722 | |
Mike Stroyan | cd1c3e5 | 2016-06-21 09:20:01 -0600 | [diff] [blame] | 4723 | VkResult err = |
| 4724 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4725 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4726 | |
| 4727 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4728 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4729 | &command_buffer[0]); |
| 4730 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4731 | |
| 4732 | m_errorMonitor->VerifyNotFound(); |
| 4733 | } |
| 4734 | |
| 4735 | // This is a positive test. No errors should be generated. |
| 4736 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) { |
| 4737 | |
| 4738 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4739 | "on the same queue, the second having a fence, followed " |
| 4740 | "by a WaitForFences call."); |
| 4741 | |
| 4742 | m_errorMonitor->ExpectSuccess(); |
| 4743 | |
| 4744 | VkFence fence; |
| 4745 | VkFenceCreateInfo fence_create_info{}; |
| 4746 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4747 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4748 | |
| 4749 | VkCommandPool command_pool; |
| 4750 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4751 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4752 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4753 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4754 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4755 | &command_pool); |
| 4756 | |
| 4757 | VkCommandBuffer command_buffer[2]; |
| 4758 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4759 | command_buffer_allocate_info.sType = |
| 4760 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4761 | command_buffer_allocate_info.commandPool = command_pool; |
| 4762 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4763 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4764 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4765 | command_buffer); |
| 4766 | |
| 4767 | { |
| 4768 | VkCommandBufferBeginInfo begin_info{}; |
| 4769 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4770 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4771 | |
| 4772 | vkCmdPipelineBarrier(command_buffer[0], |
| 4773 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4774 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4775 | 0, nullptr, 0, nullptr); |
| 4776 | |
| 4777 | VkViewport viewport{}; |
| 4778 | viewport.maxDepth = 1.0f; |
| 4779 | viewport.minDepth = 0.0f; |
| 4780 | viewport.width = 512; |
| 4781 | viewport.height = 512; |
| 4782 | viewport.x = 0; |
| 4783 | viewport.y = 0; |
| 4784 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4785 | vkEndCommandBuffer(command_buffer[0]); |
| 4786 | } |
| 4787 | { |
| 4788 | VkCommandBufferBeginInfo begin_info{}; |
| 4789 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4790 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4791 | |
| 4792 | VkViewport viewport{}; |
| 4793 | viewport.maxDepth = 1.0f; |
| 4794 | viewport.minDepth = 0.0f; |
| 4795 | viewport.width = 512; |
| 4796 | viewport.height = 512; |
| 4797 | viewport.x = 0; |
| 4798 | viewport.y = 0; |
| 4799 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4800 | vkEndCommandBuffer(command_buffer[1]); |
| 4801 | } |
| 4802 | { |
| 4803 | VkSubmitInfo submit_info{}; |
| 4804 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4805 | submit_info.commandBufferCount = 1; |
| 4806 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4807 | submit_info.signalSemaphoreCount = 0; |
| 4808 | submit_info.pSignalSemaphores = VK_NULL_HANDLE; |
| 4809 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4810 | } |
| 4811 | { |
| 4812 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4813 | VkSubmitInfo submit_info{}; |
| 4814 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4815 | submit_info.commandBufferCount = 1; |
| 4816 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4817 | submit_info.waitSemaphoreCount = 0; |
| 4818 | submit_info.pWaitSemaphores = VK_NULL_HANDLE; |
| 4819 | submit_info.pWaitDstStageMask = flags; |
| 4820 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4821 | } |
| 4822 | |
| 4823 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4824 | |
| 4825 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4826 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4827 | &command_buffer[0]); |
| 4828 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4829 | |
| 4830 | m_errorMonitor->VerifyNotFound(); |
| 4831 | } |
| 4832 | |
| 4833 | // This is a positive test. No errors should be generated. |
| 4834 | TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) { |
| 4835 | |
| 4836 | TEST_DESCRIPTION( |
| 4837 | "Two command buffers each in a separate SubmitInfo sent in a single " |
| 4838 | "QueueSubmit call followed by a WaitForFences call."); |
| 4839 | |
| 4840 | m_errorMonitor->ExpectSuccess(); |
| 4841 | |
| 4842 | VkFence fence; |
| 4843 | VkFenceCreateInfo fence_create_info{}; |
| 4844 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4845 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4846 | |
| 4847 | VkSemaphore semaphore; |
| 4848 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4849 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4850 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4851 | &semaphore); |
| 4852 | |
| 4853 | VkCommandPool command_pool; |
| 4854 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4855 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4856 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4857 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4858 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4859 | &command_pool); |
| 4860 | |
| 4861 | VkCommandBuffer command_buffer[2]; |
| 4862 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4863 | command_buffer_allocate_info.sType = |
| 4864 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4865 | command_buffer_allocate_info.commandPool = command_pool; |
| 4866 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4867 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4868 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4869 | command_buffer); |
| 4870 | |
| 4871 | { |
| 4872 | VkCommandBufferBeginInfo begin_info{}; |
| 4873 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4874 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4875 | |
| 4876 | vkCmdPipelineBarrier(command_buffer[0], |
| 4877 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4878 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4879 | 0, nullptr, 0, nullptr); |
| 4880 | |
| 4881 | VkViewport viewport{}; |
| 4882 | viewport.maxDepth = 1.0f; |
| 4883 | viewport.minDepth = 0.0f; |
| 4884 | viewport.width = 512; |
| 4885 | viewport.height = 512; |
| 4886 | viewport.x = 0; |
| 4887 | viewport.y = 0; |
| 4888 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4889 | vkEndCommandBuffer(command_buffer[0]); |
| 4890 | } |
| 4891 | { |
| 4892 | VkCommandBufferBeginInfo begin_info{}; |
| 4893 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4894 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4895 | |
| 4896 | VkViewport viewport{}; |
| 4897 | viewport.maxDepth = 1.0f; |
| 4898 | viewport.minDepth = 0.0f; |
| 4899 | viewport.width = 512; |
| 4900 | viewport.height = 512; |
| 4901 | viewport.x = 0; |
| 4902 | viewport.y = 0; |
| 4903 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4904 | vkEndCommandBuffer(command_buffer[1]); |
| 4905 | } |
| 4906 | { |
| 4907 | VkSubmitInfo submit_info[2]; |
| 4908 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4909 | |
| 4910 | submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4911 | submit_info[0].pNext = NULL; |
| 4912 | submit_info[0].commandBufferCount = 1; |
| 4913 | submit_info[0].pCommandBuffers = &command_buffer[0]; |
| 4914 | submit_info[0].signalSemaphoreCount = 1; |
| 4915 | submit_info[0].pSignalSemaphores = &semaphore; |
| 4916 | submit_info[0].waitSemaphoreCount = 0; |
| 4917 | submit_info[0].pWaitSemaphores = NULL; |
| 4918 | submit_info[0].pWaitDstStageMask = 0; |
| 4919 | |
| 4920 | submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4921 | submit_info[1].pNext = NULL; |
| 4922 | submit_info[1].commandBufferCount = 1; |
| 4923 | submit_info[1].pCommandBuffers = &command_buffer[1]; |
| 4924 | submit_info[1].waitSemaphoreCount = 1; |
| 4925 | submit_info[1].pWaitSemaphores = &semaphore; |
| 4926 | submit_info[1].pWaitDstStageMask = flags; |
| 4927 | submit_info[1].signalSemaphoreCount = 0; |
| 4928 | submit_info[1].pSignalSemaphores = NULL; |
| 4929 | vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence); |
| 4930 | } |
| 4931 | |
| 4932 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4933 | |
| 4934 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4935 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4936 | &command_buffer[0]); |
| 4937 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 4938 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4939 | |
| 4940 | m_errorMonitor->VerifyNotFound(); |
| 4941 | } |
| 4942 | |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4943 | TEST_F(VkLayerTest, DynamicDepthBiasNotBound) { |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4944 | TEST_DESCRIPTION( |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4945 | "Run a simple draw calls to validate failure when Depth Bias dynamic " |
| 4946 | "state is required but not correctly bound."); |
| 4947 | |
| 4948 | // Dynamic depth bias |
| 4949 | m_errorMonitor->SetDesiredFailureMsg( |
| 4950 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4951 | "Dynamic depth bias state not set for this command buffer"); |
| 4952 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4953 | BsoFailDepthBias); |
| 4954 | m_errorMonitor->VerifyFound(); |
| 4955 | } |
| 4956 | |
| 4957 | TEST_F(VkLayerTest, DynamicLineWidthNotBound) { |
| 4958 | TEST_DESCRIPTION( |
| 4959 | "Run a simple draw calls to validate failure when Line Width dynamic " |
| 4960 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4961 | |
| 4962 | // Dynamic line width |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4963 | m_errorMonitor->SetDesiredFailureMsg( |
| 4964 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4965 | "Dynamic line width state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4966 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4967 | BsoFailLineWidth); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4968 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4969 | } |
| 4970 | |
| 4971 | TEST_F(VkLayerTest, DynamicViewportNotBound) { |
| 4972 | TEST_DESCRIPTION( |
| 4973 | "Run a simple draw calls to validate failure when Viewport dynamic " |
| 4974 | "state is required but not correctly bound."); |
| 4975 | |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4976 | // Dynamic viewport state |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4977 | m_errorMonitor->SetDesiredFailureMsg( |
| 4978 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4979 | "Dynamic viewport state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4980 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4981 | BsoFailViewport); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4982 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4983 | } |
| 4984 | |
| 4985 | TEST_F(VkLayerTest, DynamicScissorNotBound) { |
| 4986 | TEST_DESCRIPTION( |
| 4987 | "Run a simple draw calls to validate failure when Scissor dynamic " |
| 4988 | "state is required but not correctly bound."); |
| 4989 | |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4990 | // Dynamic scissor state |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4991 | m_errorMonitor->SetDesiredFailureMsg( |
| 4992 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4993 | "Dynamic scissor state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4994 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4995 | BsoFailScissor); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4996 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4997 | } |
| 4998 | |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 4999 | TEST_F(VkLayerTest, DynamiBlendConstantsNotBound) { |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5000 | TEST_DESCRIPTION( |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 5001 | "Run a simple draw calls to validate failure when Blend Constants " |
| 5002 | "dynamic state is required but not correctly bound."); |
| 5003 | // Dynamic blend constant state |
| 5004 | m_errorMonitor->SetDesiredFailureMsg( |
| 5005 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5006 | "Dynamic blend constants state not set for this command buffer"); |
| 5007 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5008 | BsoFailBlend); |
| 5009 | m_errorMonitor->VerifyFound(); |
| 5010 | } |
| 5011 | |
| 5012 | TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) { |
| 5013 | TEST_DESCRIPTION( |
| 5014 | "Run a simple draw calls to validate failure when Depth Bounds dynamic " |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5015 | "state is required but not correctly bound."); |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 5016 | if (!m_device->phy().features().depthBounds) { |
| 5017 | printf("Device does not support depthBounds test; skipped.\n"); |
| 5018 | return; |
| 5019 | } |
| 5020 | // Dynamic depth bounds |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5021 | m_errorMonitor->SetDesiredFailureMsg( |
| 5022 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5023 | "Dynamic depth bounds state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5024 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5025 | BsoFailDepthBounds); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5026 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5027 | } |
| 5028 | |
| 5029 | TEST_F(VkLayerTest, DynamicStencilReadNotBound) { |
| 5030 | TEST_DESCRIPTION( |
| 5031 | "Run a simple draw calls to validate failure when Stencil Read dynamic " |
| 5032 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5033 | // Dynamic stencil read mask |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5034 | m_errorMonitor->SetDesiredFailureMsg( |
| 5035 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5036 | "Dynamic stencil read mask state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5037 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5038 | BsoFailStencilReadMask); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5039 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5040 | } |
| 5041 | |
| 5042 | TEST_F(VkLayerTest, DynamicStencilWriteNotBound) { |
| 5043 | TEST_DESCRIPTION( |
| 5044 | "Run a simple draw calls to validate failure when Stencil Write dynamic" |
| 5045 | " state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5046 | // Dynamic stencil write mask |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5047 | m_errorMonitor->SetDesiredFailureMsg( |
| 5048 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5049 | "Dynamic stencil write mask state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5050 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5051 | BsoFailStencilWriteMask); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5052 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 5053 | } |
| 5054 | |
| 5055 | TEST_F(VkLayerTest, DynamicStencilRefNotBound) { |
| 5056 | TEST_DESCRIPTION( |
| 5057 | "Run a simple draw calls to validate failure when Stencil Ref dynamic " |
| 5058 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 5059 | // Dynamic stencil reference |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5060 | m_errorMonitor->SetDesiredFailureMsg( |
| 5061 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5062 | "Dynamic stencil reference state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5063 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 5064 | BsoFailStencilReference); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5065 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 963a404 | 2015-09-29 08:18:34 -0600 | [diff] [blame] | 5066 | } |
| 5067 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5068 | TEST_F(VkLayerTest, CommandBufferTwoSubmits) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5069 | m_errorMonitor->SetDesiredFailureMsg( |
| 5070 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5071 | "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has " |
| 5072 | "been submitted"); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5073 | |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5074 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5075 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5076 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5077 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5078 | // We luck out b/c by default the framework creates CB w/ the |
| 5079 | // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5080 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5081 | m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 5082 | m_stencil_clear_color, NULL); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5083 | EndCommandBuffer(); |
| 5084 | |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5085 | // Bypass framework since it does the waits automatically |
| 5086 | VkResult err = VK_SUCCESS; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 5087 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 5088 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 5089 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 5090 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 5091 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 5092 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 5093 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5094 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 5095 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 5096 | submit_info.pSignalSemaphores = NULL; |
| 5097 | |
Chris Forbes | 40028e2 | 2016-06-13 09:59:34 +1200 | [diff] [blame] | 5098 | err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5099 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5100 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5101 | // Cause validation error by re-submitting cmd buffer that should only be |
| 5102 | // submitted once |
Chris Forbes | 40028e2 | 2016-06-13 09:59:34 +1200 | [diff] [blame] | 5103 | err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5104 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5105 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 5106 | } |
| 5107 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5108 | TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) { |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5109 | // Initiate Draw w/o a PSO bound |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5110 | VkResult err; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5111 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 5112 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5113 | "Unable to allocate 1 descriptors of " |
| 5114 | "type " |
| 5115 | "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5116 | |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5117 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5118 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5119 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5120 | // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer |
| 5121 | // descriptor from it |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 5122 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5123 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 5124 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5125 | |
| 5126 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5127 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5128 | ds_pool_ci.pNext = NULL; |
| 5129 | ds_pool_ci.flags = 0; |
| 5130 | ds_pool_ci.maxSets = 1; |
| 5131 | ds_pool_ci.poolSizeCount = 1; |
| 5132 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5133 | |
| 5134 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5135 | err = |
| 5136 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5137 | ASSERT_VK_SUCCESS(err); |
| 5138 | |
| 5139 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5140 | dsl_binding.binding = 0; |
| 5141 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5142 | dsl_binding.descriptorCount = 1; |
| 5143 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5144 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5145 | |
| 5146 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5147 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5148 | ds_layout_ci.pNext = NULL; |
| 5149 | ds_layout_ci.bindingCount = 1; |
| 5150 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5151 | |
| 5152 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5153 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5154 | &ds_layout); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5155 | ASSERT_VK_SUCCESS(err); |
| 5156 | |
| 5157 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5158 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5159 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5160 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 5161 | alloc_info.descriptorPool = ds_pool; |
| 5162 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5163 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5164 | &descriptorSet); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5165 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5166 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5167 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 5168 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5169 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 5170 | } |
| 5171 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5172 | TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) { |
| 5173 | VkResult err; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5174 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5175 | m_errorMonitor->SetDesiredFailureMsg( |
| 5176 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5177 | "It is invalid to call vkFreeDescriptorSets() with a pool created " |
| 5178 | "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5179 | |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5180 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5181 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5182 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 5183 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5184 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5185 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5186 | |
| 5187 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5188 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5189 | ds_pool_ci.pNext = NULL; |
| 5190 | ds_pool_ci.maxSets = 1; |
| 5191 | ds_pool_ci.poolSizeCount = 1; |
| 5192 | ds_pool_ci.flags = 0; |
| 5193 | // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means |
| 5194 | // app can only call vkResetDescriptorPool on this pool.; |
| 5195 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5196 | |
| 5197 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5198 | err = |
| 5199 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5200 | ASSERT_VK_SUCCESS(err); |
| 5201 | |
| 5202 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5203 | dsl_binding.binding = 0; |
| 5204 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5205 | dsl_binding.descriptorCount = 1; |
| 5206 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5207 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5208 | |
| 5209 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5210 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5211 | ds_layout_ci.pNext = NULL; |
| 5212 | ds_layout_ci.bindingCount = 1; |
| 5213 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5214 | |
| 5215 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5216 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5217 | &ds_layout); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5218 | ASSERT_VK_SUCCESS(err); |
| 5219 | |
| 5220 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5221 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5222 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5223 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 5224 | alloc_info.descriptorPool = ds_pool; |
| 5225 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5226 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5227 | &descriptorSet); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5228 | ASSERT_VK_SUCCESS(err); |
| 5229 | |
| 5230 | err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5231 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5232 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 5233 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5234 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 5235 | } |
| 5236 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5237 | TEST_F(VkLayerTest, InvalidDescriptorPool) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5238 | // Attempt to clear Descriptor Pool with bad object. |
| 5239 | // ObjectTracker should catch this. |
| 5240 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5241 | "Invalid VkDescriptorPool Object 0xbaad6001"); |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5242 | uint64_t fake_pool_handle = 0xbaad6001; |
| 5243 | VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle); |
| 5244 | vkResetDescriptorPool(device(), bad_pool, 0); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5245 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5246 | } |
| 5247 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5248 | TEST_F(VkLayerTest, InvalidDescriptorSet) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5249 | // Attempt to bind an invalid Descriptor Set to a valid Command Buffer |
| 5250 | // ObjectTracker should catch this. |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5251 | // Create a valid cmd buffer |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5252 | // call vkCmdBindDescriptorSets w/ false Descriptor Set |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5253 | |
| 5254 | uint64_t fake_set_handle = 0xbaad6001; |
| 5255 | VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5256 | VkResult err; |
| 5257 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5258 | "Invalid VkDescriptorSet Object 0xbaad6001"); |
| 5259 | |
| 5260 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5261 | |
| 5262 | VkDescriptorSetLayoutBinding layout_bindings[1] = {}; |
| 5263 | layout_bindings[0].binding = 0; |
| 5264 | layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5265 | layout_bindings[0].descriptorCount = 1; |
| 5266 | layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; |
| 5267 | layout_bindings[0].pImmutableSamplers = NULL; |
| 5268 | |
| 5269 | VkDescriptorSetLayout descriptor_set_layout; |
| 5270 | VkDescriptorSetLayoutCreateInfo dslci = {}; |
| 5271 | dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5272 | dslci.pNext = NULL; |
| 5273 | dslci.bindingCount = 1; |
| 5274 | dslci.pBindings = layout_bindings; |
| 5275 | err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout); |
Karl Schultz | 5cb2111 | 2016-04-21 17:17:40 -0600 | [diff] [blame] | 5276 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5277 | |
| 5278 | VkPipelineLayout pipeline_layout; |
| 5279 | VkPipelineLayoutCreateInfo plci = {}; |
| 5280 | plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5281 | plci.pNext = NULL; |
| 5282 | plci.setLayoutCount = 1; |
| 5283 | plci.pSetLayouts = &descriptor_set_layout; |
| 5284 | err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout); |
Karl Schultz | 5cb2111 | 2016-04-21 17:17:40 -0600 | [diff] [blame] | 5285 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5286 | |
| 5287 | BeginCommandBuffer(); |
| 5288 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5289 | pipeline_layout, 0, 1, &bad_set, 0, NULL); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5290 | m_errorMonitor->VerifyFound(); |
| 5291 | EndCommandBuffer(); |
| 5292 | vkDestroyPipelineLayout(device(), pipeline_layout, NULL); |
| 5293 | vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5294 | } |
| 5295 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5296 | TEST_F(VkLayerTest, InvalidDescriptorSetLayout) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5297 | // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout. |
| 5298 | // ObjectTracker should catch this. |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5299 | uint64_t fake_layout_handle = 0xbaad6001; |
| 5300 | VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5301 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5302 | "Invalid VkDescriptorSetLayout Object 0xbaad6001"); |
| 5303 | |
| 5304 | VkPipelineLayout pipeline_layout; |
| 5305 | VkPipelineLayoutCreateInfo plci = {}; |
| 5306 | plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5307 | plci.pNext = NULL; |
| 5308 | plci.setLayoutCount = 1; |
| 5309 | plci.pSetLayouts = &bad_layout; |
| 5310 | vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout); |
| 5311 | |
| 5312 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5313 | } |
| 5314 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5315 | TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) { |
| 5316 | TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec " |
| 5317 | "1) A uniform buffer update must have a valid buffer index." |
| 5318 | "2) When using an array of descriptors in a single WriteDescriptor," |
| 5319 | " the descriptor types and stageflags must all be the same." |
| 5320 | "3) Immutable Sampler state must match across descriptors"); |
| 5321 | |
| 5322 | const char *invalid_BufferInfo_ErrorMessage = |
| 5323 | "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, " |
| 5324 | "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or " |
| 5325 | "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL"; |
| 5326 | const char *stateFlag_ErrorMessage = |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5327 | "Attempting write update to descriptor set "; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5328 | const char *immutable_ErrorMessage = |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5329 | "Attempting write update to descriptor set "; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5330 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5331 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage); |
| 5332 | |
| 5333 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5334 | VkDescriptorPoolSize ds_type_count[4] = {}; |
| 5335 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5336 | ds_type_count[0].descriptorCount = 1; |
| 5337 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 5338 | ds_type_count[1].descriptorCount = 1; |
| 5339 | ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 5340 | ds_type_count[2].descriptorCount = 1; |
| 5341 | ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 5342 | ds_type_count[3].descriptorCount = 1; |
| 5343 | |
| 5344 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 5345 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5346 | ds_pool_ci.maxSets = 1; |
| 5347 | ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize); |
| 5348 | ds_pool_ci.pPoolSizes = ds_type_count; |
| 5349 | |
| 5350 | VkDescriptorPool ds_pool; |
| 5351 | VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 5352 | ASSERT_VK_SUCCESS(err); |
| 5353 | |
Mark Mueller | b989672 | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5354 | VkDescriptorSetLayoutBinding layout_binding[3] = {}; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5355 | layout_binding[0].binding = 0; |
| 5356 | layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5357 | layout_binding[0].descriptorCount = 1; |
| 5358 | layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 5359 | layout_binding[0].pImmutableSamplers = NULL; |
| 5360 | |
| 5361 | layout_binding[1].binding = 1; |
| 5362 | layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 5363 | layout_binding[1].descriptorCount = 1; |
| 5364 | layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; |
| 5365 | layout_binding[1].pImmutableSamplers = NULL; |
| 5366 | |
| 5367 | VkSamplerCreateInfo sampler_ci = {}; |
| 5368 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 5369 | sampler_ci.pNext = NULL; |
| 5370 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 5371 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 5372 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 5373 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 5374 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 5375 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 5376 | sampler_ci.mipLodBias = 1.0; |
| 5377 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 5378 | sampler_ci.maxAnisotropy = 1; |
| 5379 | sampler_ci.compareEnable = VK_FALSE; |
| 5380 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 5381 | sampler_ci.minLod = 1.0; |
| 5382 | sampler_ci.maxLod = 1.0; |
| 5383 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 5384 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
| 5385 | VkSampler sampler; |
| 5386 | |
| 5387 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
| 5388 | ASSERT_VK_SUCCESS(err); |
| 5389 | |
| 5390 | layout_binding[2].binding = 2; |
| 5391 | layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 5392 | layout_binding[2].descriptorCount = 1; |
| 5393 | layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; |
| 5394 | layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler); |
| 5395 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5396 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 5397 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5398 | ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding); |
| 5399 | ds_layout_ci.pBindings = layout_binding; |
| 5400 | VkDescriptorSetLayout ds_layout; |
| 5401 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout); |
| 5402 | ASSERT_VK_SUCCESS(err); |
| 5403 | |
| 5404 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 5405 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 5406 | alloc_info.descriptorSetCount = 1; |
| 5407 | alloc_info.descriptorPool = ds_pool; |
| 5408 | alloc_info.pSetLayouts = &ds_layout; |
| 5409 | VkDescriptorSet descriptorSet; |
| 5410 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet); |
| 5411 | ASSERT_VK_SUCCESS(err); |
| 5412 | |
| 5413 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 5414 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5415 | pipeline_layout_ci.pNext = NULL; |
| 5416 | pipeline_layout_ci.setLayoutCount = 1; |
| 5417 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 5418 | |
| 5419 | VkPipelineLayout pipeline_layout; |
| 5420 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout); |
| 5421 | ASSERT_VK_SUCCESS(err); |
| 5422 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5423 | VkWriteDescriptorSet descriptor_write = {}; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5424 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5425 | descriptor_write.dstSet = descriptorSet; |
| 5426 | descriptor_write.dstBinding = 0; |
| 5427 | descriptor_write.descriptorCount = 1; |
| 5428 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5429 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5430 | // 1) The uniform buffer is intentionally invalid here |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5431 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5432 | m_errorMonitor->VerifyFound(); |
| 5433 | |
| 5434 | // Create a buffer to update the descriptor with |
| 5435 | uint32_t qfi = 0; |
| 5436 | VkBufferCreateInfo buffCI = {}; |
| 5437 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 5438 | buffCI.size = 1024; |
| 5439 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 5440 | buffCI.queueFamilyIndexCount = 1; |
| 5441 | buffCI.pQueueFamilyIndices = &qfi; |
| 5442 | |
| 5443 | VkBuffer dyub; |
| 5444 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 5445 | ASSERT_VK_SUCCESS(err); |
| 5446 | VkDescriptorBufferInfo buffInfo = {}; |
| 5447 | buffInfo.buffer = dyub; |
| 5448 | buffInfo.offset = 0; |
| 5449 | buffInfo.range = 1024; |
| 5450 | |
| 5451 | descriptor_write.pBufferInfo = &buffInfo; |
| 5452 | descriptor_write.descriptorCount = 2; |
| 5453 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5454 | // 2) The stateFlags don't match between the first and second descriptor |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5455 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage); |
| 5456 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5457 | m_errorMonitor->VerifyFound(); |
| 5458 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5459 | // 3) The second descriptor has a null_ptr pImmutableSamplers and |
| 5460 | // the third descriptor contains an immutable sampler |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5461 | descriptor_write.dstBinding = 1; |
| 5462 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5463 | |
| 5464 | |
| 5465 | // Make pImageInfo index non-null to avoid complaints of it missing |
| 5466 | VkDescriptorImageInfo imageInfo = {}; |
| 5467 | imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 5468 | descriptor_write.pImageInfo = &imageInfo; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5469 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage); |
| 5470 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5471 | m_errorMonitor->VerifyFound(); |
| 5472 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5473 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
| 5474 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 5475 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5476 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5477 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 5478 | } |
| 5479 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5480 | TEST_F(VkLayerTest, InvalidPipeline) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5481 | // Attempt to bind an invalid Pipeline to a valid Command Buffer |
| 5482 | // ObjectTracker should catch this. |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5483 | // Create a valid cmd buffer |
| 5484 | // call vkCmdBindPipeline w/ false Pipeline |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5485 | uint64_t fake_pipeline_handle = 0xbaad6001; |
| 5486 | VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5487 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5488 | "Invalid VkPipeline Object 0xbaad6001"); |
| 5489 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5490 | BeginCommandBuffer(); |
| 5491 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 5492 | VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline); |
| 5493 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 5494 | // Now issue a draw call with no pipeline bound |
| 5495 | m_errorMonitor->SetDesiredFailureMsg( |
| 5496 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5497 | "At Draw/Dispatch time no valid VkPipeline is bound!"); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 5498 | |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 5499 | BeginCommandBuffer(); |
| 5500 | Draw(1, 0, 0, 0); |
| 5501 | m_errorMonitor->VerifyFound(); |
| 5502 | // Finally same check once more but with Dispatch/Compute |
| 5503 | m_errorMonitor->SetDesiredFailureMsg( |
| 5504 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5505 | "At Draw/Dispatch time no valid VkPipeline is bound!"); |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 5506 | BeginCommandBuffer(); |
| 5507 | vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0); |
| 5508 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5509 | } |
| 5510 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5511 | TEST_F(VkLayerTest, DescriptorSetNotUpdated) { |
| 5512 | // Create and update CommandBuffer then call QueueSubmit w/o calling End on |
| 5513 | // CommandBuffer |
| 5514 | VkResult err; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5515 | |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 5516 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5517 | " bound but it was never updated. "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5518 | |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5519 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 5520 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5521 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 5522 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5523 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5524 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5525 | |
| 5526 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5527 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5528 | ds_pool_ci.pNext = NULL; |
| 5529 | ds_pool_ci.maxSets = 1; |
| 5530 | ds_pool_ci.poolSizeCount = 1; |
| 5531 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 5532 | |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5533 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5534 | err = |
| 5535 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5536 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5537 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5538 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5539 | dsl_binding.binding = 0; |
| 5540 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5541 | dsl_binding.descriptorCount = 1; |
| 5542 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5543 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5544 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5545 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5546 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5547 | ds_layout_ci.pNext = NULL; |
| 5548 | ds_layout_ci.bindingCount = 1; |
| 5549 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5550 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5551 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5552 | &ds_layout); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5553 | ASSERT_VK_SUCCESS(err); |
| 5554 | |
| 5555 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5556 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5557 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5558 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 5559 | alloc_info.descriptorPool = ds_pool; |
| 5560 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5561 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5562 | &descriptorSet); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5563 | ASSERT_VK_SUCCESS(err); |
| 5564 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5565 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5566 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5567 | pipeline_layout_ci.pNext = NULL; |
| 5568 | pipeline_layout_ci.setLayoutCount = 1; |
| 5569 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5570 | |
| 5571 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5572 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5573 | &pipeline_layout); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5574 | ASSERT_VK_SUCCESS(err); |
| 5575 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5576 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 5577 | VK_SHADER_STAGE_VERTEX_BIT, this); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5578 | // 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] | 5579 | // on more devices |
| 5580 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 5581 | VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5582 | |
Tony Barbour | c95e4ac | 2015-08-04 17:05:26 -0600 | [diff] [blame] | 5583 | VkPipelineObj pipe(m_device); |
| 5584 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 5585 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 5586 | pipe.AddColorAttachment(); |
Tony Barbour | c95e4ac | 2015-08-04 17:05:26 -0600 | [diff] [blame] | 5587 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 5588 | |
| 5589 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5590 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 5591 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 5592 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5593 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5594 | 1, &descriptorSet, 0, NULL); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5595 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5596 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 5597 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 5598 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5599 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5600 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 5601 | } |
| 5602 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5603 | TEST_F(VkLayerTest, InvalidBufferViewObject) { |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5604 | // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5605 | VkResult err; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5606 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5607 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5608 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer " |
| 5609 | "descriptor with invalid buffer view"); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5610 | |
| 5611 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5612 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5613 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5614 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5615 | |
| 5616 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5617 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5618 | ds_pool_ci.pNext = NULL; |
| 5619 | ds_pool_ci.maxSets = 1; |
| 5620 | ds_pool_ci.poolSizeCount = 1; |
| 5621 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5622 | |
| 5623 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5624 | err = |
| 5625 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5626 | ASSERT_VK_SUCCESS(err); |
| 5627 | |
| 5628 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5629 | dsl_binding.binding = 0; |
| 5630 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5631 | dsl_binding.descriptorCount = 1; |
| 5632 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5633 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5634 | |
| 5635 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5636 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5637 | ds_layout_ci.pNext = NULL; |
| 5638 | ds_layout_ci.bindingCount = 1; |
| 5639 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5640 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5641 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5642 | &ds_layout); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5643 | ASSERT_VK_SUCCESS(err); |
| 5644 | |
| 5645 | VkDescriptorSet descriptorSet; |
| 5646 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5647 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5648 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5649 | alloc_info.descriptorPool = ds_pool; |
| 5650 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5651 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5652 | &descriptorSet); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5653 | ASSERT_VK_SUCCESS(err); |
| 5654 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5655 | VkBufferView view = |
| 5656 | (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5657 | VkWriteDescriptorSet descriptor_write; |
| 5658 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 5659 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5660 | descriptor_write.dstSet = descriptorSet; |
| 5661 | descriptor_write.dstBinding = 0; |
| 5662 | descriptor_write.descriptorCount = 1; |
| 5663 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5664 | descriptor_write.pTexelBufferView = &view; |
| 5665 | |
| 5666 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5667 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5668 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5669 | |
| 5670 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5671 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 5672 | } |
| 5673 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5674 | TEST_F(VkLayerTest, InvalidDynamicOffsetCases) { |
| 5675 | // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error |
| 5676 | // cases: |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5677 | // 1. No dynamicOffset supplied |
| 5678 | // 2. Too many dynamicOffsets supplied |
| 5679 | // 3. Dynamic offset oversteps buffer being updated |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5680 | VkResult err; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 5681 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5682 | " requires 1 dynamicOffsets, but only " |
| 5683 | "0 dynamicOffsets are left in " |
| 5684 | "pDynamicOffsets "); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5685 | |
| 5686 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5687 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5688 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5689 | |
| 5690 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5691 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 5692 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5693 | |
| 5694 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5695 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5696 | ds_pool_ci.pNext = NULL; |
| 5697 | ds_pool_ci.maxSets = 1; |
| 5698 | ds_pool_ci.poolSizeCount = 1; |
| 5699 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5700 | |
| 5701 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5702 | err = |
| 5703 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5704 | ASSERT_VK_SUCCESS(err); |
| 5705 | |
| 5706 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5707 | dsl_binding.binding = 0; |
| 5708 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 5709 | dsl_binding.descriptorCount = 1; |
| 5710 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5711 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5712 | |
| 5713 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5714 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5715 | ds_layout_ci.pNext = NULL; |
| 5716 | ds_layout_ci.bindingCount = 1; |
| 5717 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5718 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5719 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5720 | &ds_layout); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5721 | ASSERT_VK_SUCCESS(err); |
| 5722 | |
| 5723 | VkDescriptorSet descriptorSet; |
| 5724 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5725 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5726 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5727 | alloc_info.descriptorPool = ds_pool; |
| 5728 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5729 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5730 | &descriptorSet); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5731 | ASSERT_VK_SUCCESS(err); |
| 5732 | |
| 5733 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5734 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5735 | pipeline_layout_ci.pNext = NULL; |
| 5736 | pipeline_layout_ci.setLayoutCount = 1; |
| 5737 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5738 | |
| 5739 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5740 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5741 | &pipeline_layout); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5742 | ASSERT_VK_SUCCESS(err); |
| 5743 | |
| 5744 | // Create a buffer to update the descriptor with |
| 5745 | uint32_t qfi = 0; |
| 5746 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5747 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 5748 | buffCI.size = 1024; |
| 5749 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 5750 | buffCI.queueFamilyIndexCount = 1; |
| 5751 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5752 | |
| 5753 | VkBuffer dyub; |
| 5754 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 5755 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5756 | // Allocate memory and bind to buffer so we can make it to the appropriate |
| 5757 | // error |
| 5758 | VkMemoryAllocateInfo mem_alloc = {}; |
| 5759 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 5760 | mem_alloc.pNext = NULL; |
| 5761 | mem_alloc.allocationSize = 1024; |
Chris Forbes | b6116cc | 2016-05-08 11:39:59 +1200 | [diff] [blame] | 5762 | mem_alloc.memoryTypeIndex = 0; |
| 5763 | |
| 5764 | VkMemoryRequirements memReqs; |
| 5765 | vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs); |
| 5766 | bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, |
| 5767 | 0); |
| 5768 | if (!pass) { |
| 5769 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
| 5770 | return; |
| 5771 | } |
| 5772 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5773 | VkDeviceMemory mem; |
| 5774 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 5775 | ASSERT_VK_SUCCESS(err); |
| 5776 | err = vkBindBufferMemory(m_device->device(), dyub, mem, 0); |
| 5777 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5778 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 5779 | VkDescriptorBufferInfo buffInfo = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5780 | buffInfo.buffer = dyub; |
| 5781 | buffInfo.offset = 0; |
| 5782 | buffInfo.range = 1024; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5783 | |
| 5784 | VkWriteDescriptorSet descriptor_write; |
| 5785 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 5786 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5787 | descriptor_write.dstSet = descriptorSet; |
| 5788 | descriptor_write.dstBinding = 0; |
| 5789 | descriptor_write.descriptorCount = 1; |
| 5790 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 5791 | descriptor_write.pBufferInfo = &buffInfo; |
| 5792 | |
| 5793 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5794 | |
| 5795 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5796 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5797 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5798 | 1, &descriptorSet, 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5799 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5800 | uint32_t pDynOff[2] = {512, 756}; |
| 5801 | // 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] | 5802 | m_errorMonitor->SetDesiredFailureMsg( |
| 5803 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5804 | "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5805 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5806 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5807 | 1, &descriptorSet, 2, pDynOff); |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5808 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5809 | // Finally cause error due to dynamicOffset being too big |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5810 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5811 | " dynamic offset 512 combined with " |
| 5812 | "offset 0 and range 1024 that " |
| 5813 | "oversteps the buffer size of 1024"); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5814 | // Create PSO to be used for draw-time errors below |
| 5815 | char const *vsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5816 | "#version 450\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5817 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 5818 | "out gl_PerVertex { \n" |
| 5819 | " vec4 gl_Position;\n" |
| 5820 | "};\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5821 | "void main(){\n" |
| 5822 | " gl_Position = vec4(1);\n" |
| 5823 | "}\n"; |
| 5824 | char const *fsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5825 | "#version 450\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5826 | "\n" |
| 5827 | "layout(location=0) out vec4 x;\n" |
| 5828 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 5829 | "void main(){\n" |
| 5830 | " x = vec4(bar.y);\n" |
| 5831 | "}\n"; |
| 5832 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 5833 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 5834 | VkPipelineObj pipe(m_device); |
| 5835 | pipe.AddShader(&vs); |
| 5836 | pipe.AddShader(&fs); |
| 5837 | pipe.AddColorAttachment(); |
| 5838 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 5839 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5840 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 5841 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 5842 | // This update should succeed, but offset size of 512 will overstep buffer |
| 5843 | // /w range 1024 & size 1024 |
| 5844 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5845 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5846 | 1, &descriptorSet, 1, pDynOff); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5847 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5848 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5849 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5850 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
Tobin Ehlis | 512098e | 2016-05-05 09:06:12 -0600 | [diff] [blame] | 5851 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5852 | |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5853 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 5854 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5855 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 5856 | } |
| 5857 | |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5858 | TEST_F(VkLayerTest, InvalidPushConstants) { |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5859 | VkResult err; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5860 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5861 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5862 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5863 | |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5864 | VkPipelineLayout pipeline_layout; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5865 | VkPushConstantRange pc_range = {}; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5866 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 5867 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5868 | pipeline_layout_ci.pushConstantRangeCount = 1; |
| 5869 | pipeline_layout_ci.pPushConstantRanges = &pc_range; |
| 5870 | |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5871 | // |
| 5872 | // Check for invalid push constant ranges in pipeline layouts. |
| 5873 | // |
| 5874 | struct PipelineLayoutTestCase { |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5875 | VkPushConstantRange const range; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5876 | char const *msg; |
| 5877 | }; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5878 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5879 | const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4; |
| 5880 | const std::array<PipelineLayoutTestCase, 10> range_tests = {{ |
| 5881 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, |
| 5882 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5883 | "size 0."}, |
| 5884 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1}, |
| 5885 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5886 | "size 1."}, |
| 5887 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1}, |
| 5888 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5889 | "size 1."}, |
| 5890 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0}, |
| 5891 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5892 | "size 0."}, |
| 5893 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4}, |
| 5894 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5895 | "offset 1. Offset must"}, |
| 5896 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big}, |
| 5897 | "vkCreatePipelineLayout() call has push constants index 0 " |
| 5898 | "with offset "}, |
| 5899 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big}, |
| 5900 | "vkCreatePipelineLayout() call has push constants " |
| 5901 | "index 0 with offset "}, |
| 5902 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0}, |
| 5903 | "vkCreatePipelineLayout() call has push constants index 0 " |
| 5904 | "with offset "}, |
| 5905 | {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020}, |
| 5906 | "vkCreatePipelineLayout() call has push " |
| 5907 | "constants index 0 with offset "}, |
| 5908 | {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0}, |
| 5909 | "vkCreatePipelineLayout() call has push " |
| 5910 | "constants index 0 with offset "}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5911 | }}; |
| 5912 | |
| 5913 | // Check for invalid offset and size |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5914 | for (const auto &iter : range_tests) { |
| 5915 | pc_range = iter.range; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5916 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5917 | iter.msg); |
| 5918 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 5919 | NULL, &pipeline_layout); |
| 5920 | m_errorMonitor->VerifyFound(); |
| 5921 | if (VK_SUCCESS == err) { |
| 5922 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5923 | } |
| 5924 | } |
| 5925 | |
| 5926 | // Check for invalid stage flag |
| 5927 | pc_range.offset = 0; |
| 5928 | pc_range.size = 16; |
| 5929 | pc_range.stageFlags = 0; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5930 | m_errorMonitor->SetDesiredFailureMsg( |
| 5931 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5932 | "vkCreatePipelineLayout() call has no stageFlags set."); |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5933 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5934 | &pipeline_layout); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5935 | m_errorMonitor->VerifyFound(); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5936 | if (VK_SUCCESS == err) { |
| 5937 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5938 | } |
| 5939 | |
| 5940 | // Check for overlapping ranges |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5941 | const uint32_t ranges_per_test = 5; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5942 | struct OverlappingRangeTestCase { |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5943 | VkPushConstantRange const ranges[ranges_per_test]; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5944 | char const *msg; |
| 5945 | }; |
| 5946 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5947 | const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5948 | {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5949 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5950 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5951 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5952 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5953 | "vkCreatePipelineLayout() call has push constants with overlapping " |
| 5954 | "ranges: 0:[0, 4), 1:[0, 4)"}, |
| 5955 | { |
| 5956 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5957 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5958 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5959 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 5960 | {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}}, |
| 5961 | "vkCreatePipelineLayout() call has push constants with " |
| 5962 | "overlapping " |
| 5963 | "ranges: 3:[12, 20), 4:[16, 20)", |
| 5964 | }, |
| 5965 | { |
| 5966 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5967 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 5968 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5969 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5970 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5971 | "vkCreatePipelineLayout() call has push constants with " |
| 5972 | "overlapping " |
| 5973 | "ranges: 0:[16, 20), 1:[12, 20)", |
| 5974 | }, |
| 5975 | { |
| 5976 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5977 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5978 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5979 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 5980 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5981 | "vkCreatePipelineLayout() call has push constants with " |
| 5982 | "overlapping " |
| 5983 | "ranges: 0:[16, 20), 3:[12, 20)", |
| 5984 | }, |
| 5985 | { |
| 5986 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5987 | {VK_SHADER_STAGE_VERTEX_BIT, 32, 4}, |
| 5988 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 96}, |
| 5989 | {VK_SHADER_STAGE_VERTEX_BIT, 40, 8}, |
| 5990 | {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}}, |
| 5991 | "vkCreatePipelineLayout() call has push constants with " |
| 5992 | "overlapping " |
| 5993 | "ranges: 0:[16, 20), 2:[4, 100)", |
| 5994 | }}}; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5995 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5996 | for (const auto &iter : overlapping_range_tests) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5997 | pipeline_layout_ci.pPushConstantRanges = iter.ranges; |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5998 | pipeline_layout_ci.pushConstantRangeCount = ranges_per_test; |
| 5999 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6000 | iter.msg); |
| 6001 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 6002 | NULL, &pipeline_layout); |
| 6003 | m_errorMonitor->VerifyFound(); |
| 6004 | if (VK_SUCCESS == err) { |
| 6005 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6006 | } |
| 6007 | } |
| 6008 | |
| 6009 | // 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] | 6010 | const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = |
| 6011 | {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6012 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 6013 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 6014 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 4}, |
| 6015 | {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}}, |
| 6016 | ""}, |
| 6017 | {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24}, |
| 6018 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 4}, |
| 6019 | {VK_SHADER_STAGE_VERTEX_BIT, 64, 8}, |
| 6020 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 16}, |
| 6021 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 6022 | ""}}}; |
| 6023 | for (const auto &iter : overlapping_range_tests_pos) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6024 | pipeline_layout_ci.pPushConstantRanges = iter.ranges; |
| 6025 | m_errorMonitor->ExpectSuccess(); |
| 6026 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 6027 | NULL, &pipeline_layout); |
| 6028 | m_errorMonitor->VerifyNotFound(); |
| 6029 | if (VK_SUCCESS == err) { |
| 6030 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6031 | } |
| 6032 | } |
| 6033 | |
| 6034 | // |
| 6035 | // CmdPushConstants tests |
| 6036 | // |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6037 | const uint8_t dummy_values[100] = {}; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6038 | |
| 6039 | // 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] | 6040 | const std::array<PipelineLayoutTestCase, 16> cmd_range_tests = {{ |
| 6041 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, |
| 6042 | "vkCmdPushConstants() call has push constants with size 0. Size " |
| 6043 | "must be greater than zero and a multiple of 4."}, |
| 6044 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1}, |
| 6045 | "vkCmdPushConstants() call has push constants with size 1. Size " |
| 6046 | "must be greater than zero and a multiple of 4."}, |
| 6047 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1}, |
| 6048 | "vkCmdPushConstants() call has push constants with size 1. Size " |
| 6049 | "must be greater than zero and a multiple of 4."}, |
| 6050 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0}, |
| 6051 | "vkCmdPushConstants() call has push constants with offset 1. " |
| 6052 | "Offset must be a multiple of 4."}, |
| 6053 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4}, |
| 6054 | "vkCmdPushConstants() call has push constants with offset 1. " |
| 6055 | "Offset must be a multiple of 4."}, |
| 6056 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20}, |
| 6057 | "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = " |
| 6058 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6059 | {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8}, |
| 6060 | "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = " |
| 6061 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6062 | {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8}, |
| 6063 | "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = " |
| 6064 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6065 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80}, |
| 6066 | "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = " |
| 6067 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6068 | {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4}, |
| 6069 | "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in " |
| 6070 | "any of the ranges in pipeline layout"}, |
| 6071 | {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, |
| 6072 | 0, 16}, |
| 6073 | "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in " |
| 6074 | "any of the ranges in pipeline layout"}, |
| 6075 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6076 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6077 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6078 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6079 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6080 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6081 | {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6082 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6083 | {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6084 | "vkCmdPushConstants() call has push constants with offset "}, |
| 6085 | }}; |
| 6086 | |
| 6087 | // Two ranges for testing robustness |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6088 | const VkPushConstantRange pc_range2[] = { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6089 | {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6090 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6091 | }; |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6092 | pipeline_layout_ci.pushConstantRangeCount = |
| 6093 | sizeof(pc_range2) / sizeof(VkPushConstantRange); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6094 | pipeline_layout_ci.pPushConstantRanges = pc_range2; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6095 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6096 | &pipeline_layout); |
| 6097 | ASSERT_VK_SUCCESS(err); |
| 6098 | BeginCommandBuffer(); |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6099 | for (const auto &iter : cmd_range_tests) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6100 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6101 | iter.msg); |
| 6102 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6103 | iter.range.stageFlags, iter.range.offset, |
| 6104 | iter.range.size, dummy_values); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6105 | m_errorMonitor->VerifyFound(); |
| 6106 | } |
| 6107 | |
| 6108 | // Check for invalid stage flag |
| 6109 | m_errorMonitor->SetDesiredFailureMsg( |
| 6110 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6111 | "vkCmdPushConstants() call has no stageFlags set."); |
| 6112 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6113 | 0, 16, dummy_values); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6114 | m_errorMonitor->VerifyFound(); |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6115 | EndCommandBuffer(); |
| 6116 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
| 6117 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 6118 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 6119 | // overlapping range tests with cmd |
| 6120 | const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{ |
| 6121 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20}, |
| 6122 | "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = " |
| 6123 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6124 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 6125 | "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = " |
| 6126 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6127 | {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16}, |
| 6128 | "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = " |
| 6129 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 6130 | }}; |
| 6131 | const VkPushConstantRange pc_range3[] = { |
| 6132 | {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, |
| 6133 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
| 6134 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6135 | {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, |
| 6136 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, |
| 6137 | {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, |
| 6138 | {VK_SHADER_STAGE_VERTEX_BIT, 56, 28}, |
| 6139 | }; |
| 6140 | pipeline_layout_ci.pushConstantRangeCount = |
| 6141 | sizeof(pc_range3) / sizeof(VkPushConstantRange); |
| 6142 | pipeline_layout_ci.pPushConstantRanges = pc_range3; |
| 6143 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6144 | &pipeline_layout); |
| 6145 | ASSERT_VK_SUCCESS(err); |
| 6146 | BeginCommandBuffer(); |
| 6147 | for (const auto &iter : cmd_overlap_tests) { |
| 6148 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6149 | iter.msg); |
| 6150 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
| 6151 | iter.range.stageFlags, iter.range.offset, |
| 6152 | iter.range.size, dummy_values); |
| 6153 | m_errorMonitor->VerifyFound(); |
| 6154 | } |
| 6155 | EndCommandBuffer(); |
| 6156 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
| 6157 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6158 | |
| 6159 | // positive overlapping range tests with cmd |
| 6160 | const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{ |
| 6161 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""}, |
| 6162 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""}, |
| 6163 | {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""}, |
| 6164 | {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""}, |
| 6165 | }}; |
| 6166 | const VkPushConstantRange pc_range4[] = { |
| 6167 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 64}, |
| 6168 | {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, |
| 6169 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
| 6170 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 6171 | {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, |
| 6172 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, |
| 6173 | {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, |
| 6174 | {VK_SHADER_STAGE_VERTEX_BIT, 56, 28}, |
| 6175 | }; |
| 6176 | pipeline_layout_ci.pushConstantRangeCount = |
| 6177 | sizeof(pc_range4) / sizeof(VkPushConstantRange); |
| 6178 | pipeline_layout_ci.pPushConstantRanges = pc_range4; |
| 6179 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6180 | &pipeline_layout); |
| 6181 | ASSERT_VK_SUCCESS(err); |
| 6182 | BeginCommandBuffer(); |
| 6183 | for (const auto &iter : cmd_overlap_tests_pos) { |
| 6184 | m_errorMonitor->ExpectSuccess(); |
| 6185 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
| 6186 | iter.range.stageFlags, iter.range.offset, |
| 6187 | iter.range.size, dummy_values); |
| 6188 | m_errorMonitor->VerifyNotFound(); |
| 6189 | } |
| 6190 | EndCommandBuffer(); |
| 6191 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 6192 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6193 | } |
| 6194 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6195 | TEST_F(VkLayerTest, DescriptorSetCompatibility) { |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6196 | // Test various desriptorSet errors with bad binding combinations |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6197 | VkResult err; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6198 | |
| 6199 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6200 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 6201 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 6202 | |
Mike Stroyan | b8a6100 | 2016-06-20 16:00:28 -0600 | [diff] [blame] | 6203 | const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM; |
| 6204 | VkImageTiling tiling; |
| 6205 | VkFormatProperties format_properties; |
| 6206 | vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties); |
| 6207 | if (format_properties.linearTilingFeatures & |
| 6208 | VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) { |
| 6209 | tiling = VK_IMAGE_TILING_LINEAR; |
| 6210 | } else if (format_properties.optimalTilingFeatures & |
| 6211 | VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) { |
| 6212 | tiling = VK_IMAGE_TILING_OPTIMAL; |
| 6213 | } else { |
| 6214 | printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; " |
| 6215 | "skipped.\n"); |
| 6216 | return; |
| 6217 | } |
| 6218 | |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6219 | static const uint32_t NUM_DESCRIPTOR_TYPES = 5; |
| 6220 | VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6221 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6222 | ds_type_count[0].descriptorCount = 10; |
| 6223 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 6224 | ds_type_count[1].descriptorCount = 2; |
| 6225 | ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
| 6226 | ds_type_count[2].descriptorCount = 2; |
| 6227 | ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 6228 | ds_type_count[3].descriptorCount = 5; |
| 6229 | // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT |
| 6230 | // type |
| 6231 | // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 6232 | ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
| 6233 | ds_type_count[4].descriptorCount = 2; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6234 | |
| 6235 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6236 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6237 | ds_pool_ci.pNext = NULL; |
| 6238 | ds_pool_ci.maxSets = 5; |
| 6239 | ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES; |
| 6240 | ds_pool_ci.pPoolSizes = ds_type_count; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6241 | |
| 6242 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6243 | err = |
| 6244 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6245 | ASSERT_VK_SUCCESS(err); |
| 6246 | |
| 6247 | static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2; |
| 6248 | VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6249 | dsl_binding[0].binding = 0; |
| 6250 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6251 | dsl_binding[0].descriptorCount = 5; |
| 6252 | dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 6253 | dsl_binding[0].pImmutableSamplers = NULL; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6254 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6255 | // Create layout identical to set0 layout but w/ different stageFlags |
| 6256 | VkDescriptorSetLayoutBinding dsl_fs_stage_only = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6257 | dsl_fs_stage_only.binding = 0; |
| 6258 | dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6259 | dsl_fs_stage_only.descriptorCount = 5; |
| 6260 | dsl_fs_stage_only.stageFlags = |
| 6261 | VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at |
| 6262 | // bind time |
| 6263 | dsl_fs_stage_only.pImmutableSamplers = NULL; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6264 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6265 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6266 | ds_layout_ci.pNext = NULL; |
| 6267 | ds_layout_ci.bindingCount = 1; |
| 6268 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6269 | static const uint32_t NUM_LAYOUTS = 4; |
| 6270 | VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6271 | VkDescriptorSetLayout ds_layout_fs_only = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6272 | // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only |
| 6273 | // layout for error case |
| 6274 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6275 | &ds_layout[0]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6276 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 6277 | ds_layout_ci.pBindings = &dsl_fs_stage_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6278 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6279 | &ds_layout_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6280 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6281 | dsl_binding[0].binding = 0; |
| 6282 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6283 | dsl_binding[0].descriptorCount = 2; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 6284 | dsl_binding[1].binding = 1; |
| 6285 | dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
| 6286 | dsl_binding[1].descriptorCount = 2; |
| 6287 | dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL; |
| 6288 | dsl_binding[1].pImmutableSamplers = NULL; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 6289 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6290 | ds_layout_ci.bindingCount = 2; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6291 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6292 | &ds_layout[1]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6293 | ASSERT_VK_SUCCESS(err); |
| 6294 | dsl_binding[0].binding = 0; |
| 6295 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6296 | dsl_binding[0].descriptorCount = 5; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6297 | ds_layout_ci.bindingCount = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6298 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6299 | &ds_layout[2]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6300 | ASSERT_VK_SUCCESS(err); |
| 6301 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6302 | dsl_binding[0].descriptorCount = 2; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6303 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6304 | &ds_layout[3]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6305 | ASSERT_VK_SUCCESS(err); |
| 6306 | |
| 6307 | static const uint32_t NUM_SETS = 4; |
| 6308 | VkDescriptorSet descriptorSet[NUM_SETS] = {}; |
| 6309 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6310 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6311 | alloc_info.descriptorSetCount = NUM_LAYOUTS; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6312 | alloc_info.descriptorPool = ds_pool; |
| 6313 | alloc_info.pSetLayouts = ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6314 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6315 | descriptorSet); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6316 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6317 | VkDescriptorSet ds0_fs_only = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6318 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6319 | alloc_info.pSetLayouts = &ds_layout_fs_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6320 | err = |
| 6321 | vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6322 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6323 | |
| 6324 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6325 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6326 | pipeline_layout_ci.pNext = NULL; |
| 6327 | pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS; |
| 6328 | pipeline_layout_ci.pSetLayouts = ds_layout; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6329 | |
| 6330 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6331 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6332 | &pipeline_layout); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6333 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6334 | // Create pipelineLayout with only one setLayout |
| 6335 | pipeline_layout_ci.setLayoutCount = 1; |
| 6336 | VkPipelineLayout single_pipe_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6337 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6338 | &single_pipe_layout); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6339 | ASSERT_VK_SUCCESS(err); |
| 6340 | // Create pipelineLayout with 2 descriptor setLayout at index 0 |
| 6341 | pipeline_layout_ci.pSetLayouts = &ds_layout[3]; |
| 6342 | VkPipelineLayout pipe_layout_one_desc; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6343 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6344 | &pipe_layout_one_desc); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6345 | ASSERT_VK_SUCCESS(err); |
| 6346 | // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0 |
| 6347 | pipeline_layout_ci.pSetLayouts = &ds_layout[2]; |
| 6348 | VkPipelineLayout pipe_layout_five_samp; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6349 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6350 | &pipe_layout_five_samp); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6351 | ASSERT_VK_SUCCESS(err); |
| 6352 | // Create pipelineLayout with UB type, but stageFlags for FS only |
| 6353 | pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only; |
| 6354 | VkPipelineLayout pipe_layout_fs_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6355 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6356 | &pipe_layout_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6357 | ASSERT_VK_SUCCESS(err); |
| 6358 | // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine |
| 6359 | VkDescriptorSetLayout pl_bad_s0[2] = {}; |
| 6360 | pl_bad_s0[0] = ds_layout_fs_only; |
| 6361 | pl_bad_s0[1] = ds_layout[1]; |
| 6362 | pipeline_layout_ci.setLayoutCount = 2; |
| 6363 | pipeline_layout_ci.pSetLayouts = pl_bad_s0; |
| 6364 | VkPipelineLayout pipe_layout_bad_set0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6365 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6366 | &pipe_layout_bad_set0); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6367 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6368 | |
| 6369 | // Create a buffer to update the descriptor with |
| 6370 | uint32_t qfi = 0; |
| 6371 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6372 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 6373 | buffCI.size = 1024; |
| 6374 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 6375 | buffCI.queueFamilyIndexCount = 1; |
| 6376 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6377 | |
| 6378 | VkBuffer dyub; |
| 6379 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 6380 | ASSERT_VK_SUCCESS(err); |
| 6381 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 6382 | static const uint32_t NUM_BUFFS = 5; |
| 6383 | VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6384 | for (uint32_t i = 0; i < NUM_BUFFS; ++i) { |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6385 | buffInfo[i].buffer = dyub; |
| 6386 | buffInfo[i].offset = 0; |
| 6387 | buffInfo[i].range = 1024; |
| 6388 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6389 | VkImage image; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6390 | const int32_t tex_width = 32; |
| 6391 | const int32_t tex_height = 32; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6392 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6393 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 6394 | image_create_info.pNext = NULL; |
| 6395 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 6396 | image_create_info.format = tex_format; |
| 6397 | image_create_info.extent.width = tex_width; |
| 6398 | image_create_info.extent.height = tex_height; |
| 6399 | image_create_info.extent.depth = 1; |
| 6400 | image_create_info.mipLevels = 1; |
| 6401 | image_create_info.arrayLayers = 1; |
| 6402 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | b8a6100 | 2016-06-20 16:00:28 -0600 | [diff] [blame] | 6403 | image_create_info.tiling = tiling; |
| 6404 | image_create_info.usage = |
| 6405 | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6406 | image_create_info.flags = 0; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6407 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 6408 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6409 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6410 | VkMemoryRequirements memReqs; |
| 6411 | VkDeviceMemory imageMem; |
| 6412 | bool pass; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 6413 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6414 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 6415 | memAlloc.pNext = NULL; |
| 6416 | memAlloc.allocationSize = 0; |
| 6417 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 6418 | vkGetImageMemoryRequirements(m_device->device(), image, &memReqs); |
| 6419 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6420 | pass = |
| 6421 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 6422 | ASSERT_TRUE(pass); |
| 6423 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem); |
| 6424 | ASSERT_VK_SUCCESS(err); |
| 6425 | err = vkBindImageMemory(m_device->device(), image, imageMem, 0); |
| 6426 | ASSERT_VK_SUCCESS(err); |
| 6427 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6428 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6429 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 6430 | image_view_create_info.image = image; |
| 6431 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 6432 | image_view_create_info.format = tex_format; |
| 6433 | image_view_create_info.subresourceRange.layerCount = 1; |
| 6434 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 6435 | image_view_create_info.subresourceRange.levelCount = 1; |
| 6436 | image_view_create_info.subresourceRange.aspectMask = |
| 6437 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6438 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6439 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6440 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 6441 | &view); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6442 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6443 | VkDescriptorImageInfo imageInfo[4] = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6444 | imageInfo[0].imageView = view; |
| 6445 | imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 6446 | imageInfo[1].imageView = view; |
| 6447 | imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6448 | imageInfo[2].imageView = view; |
| 6449 | imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 6450 | imageInfo[3].imageView = view; |
| 6451 | imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6452 | |
| 6453 | static const uint32_t NUM_SET_UPDATES = 3; |
| 6454 | VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {}; |
| 6455 | descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 6456 | descriptor_write[0].dstSet = descriptorSet[0]; |
| 6457 | descriptor_write[0].dstBinding = 0; |
| 6458 | descriptor_write[0].descriptorCount = 5; |
| 6459 | descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6460 | descriptor_write[0].pBufferInfo = buffInfo; |
| 6461 | descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 6462 | descriptor_write[1].dstSet = descriptorSet[1]; |
| 6463 | descriptor_write[1].dstBinding = 0; |
| 6464 | descriptor_write[1].descriptorCount = 2; |
| 6465 | descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 6466 | descriptor_write[1].pImageInfo = imageInfo; |
| 6467 | descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 6468 | descriptor_write[2].dstSet = descriptorSet[1]; |
| 6469 | descriptor_write[2].dstBinding = 1; |
| 6470 | descriptor_write[2].descriptorCount = 2; |
| 6471 | descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6472 | descriptor_write[2].pImageInfo = &imageInfo[2]; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6473 | |
| 6474 | vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6475 | |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6476 | // Create PSO to be used for draw-time errors below |
| 6477 | char const *vsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 6478 | "#version 450\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6479 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 6480 | "out gl_PerVertex {\n" |
| 6481 | " vec4 gl_Position;\n" |
| 6482 | "};\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6483 | "void main(){\n" |
| 6484 | " gl_Position = vec4(1);\n" |
| 6485 | "}\n"; |
| 6486 | char const *fsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 6487 | "#version 450\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6488 | "\n" |
| 6489 | "layout(location=0) out vec4 x;\n" |
| 6490 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 6491 | "void main(){\n" |
| 6492 | " x = vec4(bar.y);\n" |
| 6493 | "}\n"; |
| 6494 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6495 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6496 | VkPipelineObj pipe(m_device); |
| 6497 | pipe.AddShader(&vs); |
| 6498 | pipe.AddShader(&fs); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6499 | pipe.AddColorAttachment(); |
| 6500 | pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass()); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6501 | |
| 6502 | BeginCommandBuffer(); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6503 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6504 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 6505 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 6506 | // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding |
| 6507 | // of PSO |
| 6508 | // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of |
| 6509 | // cmd_pipeline.c |
| 6510 | // due to the fact that cmd_alloc_dset_data() has not been called in |
| 6511 | // cmd_bind_graphics_pipeline() |
| 6512 | // TODO : Want to cause various binding incompatibility issues here to test |
| 6513 | // DrawState |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6514 | // First cause various verify_layout_compatibility() fails |
| 6515 | // Second disturb early and late sets and verify INFO msgs |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6516 | // verify_set_layout_compatibility fail cases: |
| 6517 | // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6518 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6519 | " due to: invalid VkPipelineLayout "); |
| 6520 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6521 | VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6522 | (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, |
| 6523 | &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6524 | m_errorMonitor->VerifyFound(); |
| 6525 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6526 | // 2. layoutIndex exceeds # of layouts in layout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6527 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6528 | " attempting to bind set to index 1"); |
| 6529 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6530 | VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, |
| 6531 | 0, 2, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6532 | m_errorMonitor->VerifyFound(); |
| 6533 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6534 | vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6535 | // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5 |
| 6536 | // descriptors |
| 6537 | m_errorMonitor->SetDesiredFailureMsg( |
| 6538 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 6539 | " has 2 descriptors, but DescriptorSetLayout "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6540 | vkCmdBindDescriptorSets( |
| 6541 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6542 | pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6543 | m_errorMonitor->VerifyFound(); |
| 6544 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6545 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL); |
| 6546 | // 4. same # of descriptors but mismatch in type |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6547 | m_errorMonitor->SetDesiredFailureMsg( |
| 6548 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 6549 | " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6550 | vkCmdBindDescriptorSets( |
| 6551 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6552 | pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6553 | m_errorMonitor->VerifyFound(); |
| 6554 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6555 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL); |
| 6556 | // 5. same # of descriptors but mismatch in stageFlags |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6557 | m_errorMonitor->SetDesiredFailureMsg( |
| 6558 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 6559 | " has stageFlags 16 but binding 0 for DescriptorSetLayout "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6560 | vkCmdBindDescriptorSets( |
| 6561 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6562 | pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6563 | m_errorMonitor->VerifyFound(); |
| 6564 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6565 | // Cause INFO messages due to disturbing previously bound Sets |
| 6566 | // First bind sets 0 & 1 |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6567 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6568 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6569 | 2, &descriptorSet[0], 0, NULL); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6570 | // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6571 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 6572 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6573 | " previously bound as set #0 was disturbed "); |
| 6574 | vkCmdBindDescriptorSets( |
| 6575 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6576 | pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6577 | m_errorMonitor->VerifyFound(); |
| 6578 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6579 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6580 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6581 | 2, &descriptorSet[0], 0, NULL); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6582 | // 2. Disturb set after last bound set |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 6583 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6584 | " newly bound as set #0 so set #1 and " |
| 6585 | "any subsequent sets were disturbed "); |
| 6586 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6587 | VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6588 | pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6589 | m_errorMonitor->VerifyFound(); |
| 6590 | |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6591 | // Cause draw-time errors due to PSO incompatibilities |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6592 | // 1. Error due to not binding required set (we actually use same code as |
| 6593 | // above to disturb set0) |
| 6594 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6595 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6596 | 2, &descriptorSet[0], 0, NULL); |
| 6597 | vkCmdBindDescriptorSets( |
| 6598 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6599 | pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL); |
| 6600 | m_errorMonitor->SetDesiredFailureMsg( |
| 6601 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6602 | " uses set #0 but that set is not bound."); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6603 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6604 | m_errorMonitor->VerifyFound(); |
| 6605 | |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6606 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6607 | // 2. Error due to bound set not being compatible with PSO's |
| 6608 | // VkPipelineLayout (diff stageFlags in this case) |
| 6609 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6610 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6611 | 2, &descriptorSet[0], 0, NULL); |
| 6612 | m_errorMonitor->SetDesiredFailureMsg( |
| 6613 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6614 | " bound as set #0 is not compatible with "); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6615 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6616 | m_errorMonitor->VerifyFound(); |
| 6617 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6618 | // Remaining clean-up |
| 6619 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6620 | for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) { |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6621 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL); |
| 6622 | } |
| 6623 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL); |
Tobin Ehlis | 9bfd449 | 2016-05-05 15:09:11 -0600 | [diff] [blame] | 6624 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only); |
| 6625 | vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6626 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6627 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6628 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 6629 | vkFreeMemory(m_device->device(), imageMem, NULL); |
| 6630 | vkDestroyImage(m_device->device(), image, NULL); |
| 6631 | vkDestroyImageView(m_device->device(), view, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6632 | } |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6633 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6634 | TEST_F(VkLayerTest, NoBeginCommandBuffer) { |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6635 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6636 | m_errorMonitor->SetDesiredFailureMsg( |
| 6637 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6638 | "You must call vkBeginCommandBuffer() before this call to "); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6639 | |
| 6640 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6641 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6642 | // Call EndCommandBuffer() w/o calling BeginCommandBuffer() |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6643 | vkEndCommandBuffer(commandBuffer.GetBufferHandle()); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6644 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6645 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6646 | } |
| 6647 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6648 | TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) { |
| 6649 | VkResult err; |
| 6650 | VkCommandBuffer draw_cmd; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6651 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6652 | m_errorMonitor->SetDesiredFailureMsg( |
| 6653 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 61b36f3 | 2015-12-16 08:19:42 -0700 | [diff] [blame] | 6654 | " must specify a valid renderpass parameter."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6655 | |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6656 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6657 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6658 | VkCommandBufferAllocateInfo cmd = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6659 | cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6660 | cmd.pNext = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6661 | cmd.commandPool = m_commandPool; |
| 6662 | cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6663 | cmd.commandBufferCount = 1; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6664 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6665 | err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 6666 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6667 | |
| 6668 | // Force the failure by not setting the Renderpass and Framebuffer fields |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6669 | VkCommandBufferBeginInfo cmd_buf_info = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6670 | VkCommandBufferInheritanceInfo cmd_buf_hinfo = {}; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6671 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6672 | cmd_buf_info.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6673 | cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | |
| 6674 | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6675 | cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo; |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6676 | |
| 6677 | // The error should be caught by validation of the BeginCommandBuffer call |
| 6678 | vkBeginCommandBuffer(draw_cmd, &cmd_buf_info); |
| 6679 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6680 | m_errorMonitor->VerifyFound(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6681 | vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6682 | } |
| 6683 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6684 | TEST_F(VkLayerTest, CommandBufferResetErrors) { |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6685 | // Cause error due to Begin while recording CB |
| 6686 | // Then cause 2 errors for attempting to reset CB w/o having |
| 6687 | // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from |
| 6688 | // which CBs were allocated. Note that this bit is off by default. |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 6689 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6690 | "Cannot call Begin on CB"); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6691 | |
| 6692 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6693 | |
| 6694 | // Calls AllocateCommandBuffers |
| 6695 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
| 6696 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6697 | // Force the failure by setting the Renderpass and Framebuffer fields with |
| 6698 | // (fake) data |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6699 | VkCommandBufferBeginInfo cmd_buf_info = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6700 | VkCommandBufferInheritanceInfo cmd_buf_hinfo = {}; |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6701 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 6702 | cmd_buf_info.pNext = NULL; |
| 6703 | cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6704 | cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo; |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6705 | |
| 6706 | // Begin CB to transition to recording state |
| 6707 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
| 6708 | // Can't re-begin. This should trigger error |
| 6709 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6710 | m_errorMonitor->VerifyFound(); |
| 6711 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6712 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6713 | "Attempt to reset command buffer "); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6714 | VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test |
| 6715 | // Reset attempt will trigger error due to incorrect CommandPool state |
| 6716 | vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6717 | m_errorMonitor->VerifyFound(); |
| 6718 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6719 | m_errorMonitor->SetDesiredFailureMsg( |
| 6720 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6721 | " attempts to implicitly reset cmdBuffer created from "); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6722 | // Transition CB to RECORDED state |
| 6723 | vkEndCommandBuffer(commandBuffer.GetBufferHandle()); |
| 6724 | // Now attempting to Begin will implicitly reset, which triggers error |
| 6725 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6726 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6727 | } |
| 6728 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6729 | TEST_F(VkLayerTest, InvalidPipelineCreateState) { |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6730 | // Attempt to Create Gfx Pipeline w/o a VS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6731 | VkResult err; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6732 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6733 | m_errorMonitor->SetDesiredFailureMsg( |
| 6734 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6735 | "Invalid Pipeline CreateInfo State: Vtx Shader required"); |
| 6736 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6737 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 6738 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 6739 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6740 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6741 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6742 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6743 | |
| 6744 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6745 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6746 | ds_pool_ci.pNext = NULL; |
| 6747 | ds_pool_ci.maxSets = 1; |
| 6748 | ds_pool_ci.poolSizeCount = 1; |
| 6749 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 6750 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6751 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6752 | err = |
| 6753 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6754 | ASSERT_VK_SUCCESS(err); |
| 6755 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6756 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6757 | dsl_binding.binding = 0; |
| 6758 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6759 | dsl_binding.descriptorCount = 1; |
| 6760 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 6761 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6762 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6763 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6764 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6765 | ds_layout_ci.pNext = NULL; |
| 6766 | ds_layout_ci.bindingCount = 1; |
| 6767 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6768 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6769 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6770 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6771 | &ds_layout); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6772 | ASSERT_VK_SUCCESS(err); |
| 6773 | |
| 6774 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6775 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6776 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6777 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6778 | alloc_info.descriptorPool = ds_pool; |
| 6779 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6780 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6781 | &descriptorSet); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6782 | ASSERT_VK_SUCCESS(err); |
| 6783 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6784 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6785 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6786 | pipeline_layout_ci.setLayoutCount = 1; |
| 6787 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6788 | |
| 6789 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6790 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6791 | &pipeline_layout); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6792 | ASSERT_VK_SUCCESS(err); |
| 6793 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6794 | VkViewport vp = {}; // Just need dummy vp to point to |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6795 | VkRect2D sc = {}; // dummy scissor to point to |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6796 | |
| 6797 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6798 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 6799 | vp_state_ci.scissorCount = 1; |
| 6800 | vp_state_ci.pScissors = ≻ |
| 6801 | vp_state_ci.viewportCount = 1; |
| 6802 | vp_state_ci.pViewports = &vp; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6803 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6804 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 6805 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 6806 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 6807 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 6808 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 6809 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 6810 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 6811 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 6812 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6813 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6814 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6815 | gp_ci.pViewportState = &vp_state_ci; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6816 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6817 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6818 | gp_ci.layout = pipeline_layout; |
| 6819 | gp_ci.renderPass = renderPass(); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6820 | |
| 6821 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6822 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 6823 | pc_ci.initialDataSize = 0; |
| 6824 | pc_ci.pInitialData = 0; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6825 | |
| 6826 | VkPipeline pipeline; |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 6827 | VkPipelineCache pipelineCache; |
| 6828 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6829 | err = |
| 6830 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 6831 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6832 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6833 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6834 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6835 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 6836 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6837 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6838 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6839 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6840 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6841 | } |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6842 | /*// TODO : This test should be good, but needs Tess support in compiler to run |
| 6843 | TEST_F(VkLayerTest, InvalidPatchControlPoints) |
| 6844 | { |
| 6845 | // Attempt to Create Gfx Pipeline w/o a VS |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6846 | VkResult err; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6847 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 6848 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6849 | "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH |
| 6850 | primitive "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6851 | |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6852 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6853 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6854 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6855 | VkDescriptorPoolSize ds_type_count = {}; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6856 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6857 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6858 | |
| 6859 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 6860 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6861 | ds_pool_ci.pNext = NULL; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6862 | ds_pool_ci.poolSizeCount = 1; |
| 6863 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6864 | |
| 6865 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6866 | err = vkCreateDescriptorPool(m_device->device(), |
| 6867 | 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] | 6868 | ASSERT_VK_SUCCESS(err); |
| 6869 | |
| 6870 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6871 | dsl_binding.binding = 0; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6872 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | 0212448 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 6873 | dsl_binding.descriptorCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6874 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 6875 | dsl_binding.pImmutableSamplers = NULL; |
| 6876 | |
| 6877 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6878 | ds_layout_ci.sType = |
| 6879 | VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6880 | ds_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6881 | ds_layout_ci.bindingCount = 1; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 6882 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6883 | |
| 6884 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6885 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6886 | &ds_layout); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6887 | ASSERT_VK_SUCCESS(err); |
| 6888 | |
| 6889 | VkDescriptorSet descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6890 | err = vkAllocateDescriptorSets(m_device->device(), ds_pool, |
| 6891 | VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6892 | ASSERT_VK_SUCCESS(err); |
| 6893 | |
| 6894 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6895 | pipeline_layout_ci.sType = |
| 6896 | VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6897 | pipeline_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6898 | pipeline_layout_ci.setLayoutCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6899 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 6900 | |
| 6901 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6902 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6903 | &pipeline_layout); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6904 | ASSERT_VK_SUCCESS(err); |
| 6905 | |
| 6906 | VkPipelineShaderStageCreateInfo shaderStages[3]; |
| 6907 | memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 6908 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6909 | VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, |
| 6910 | this); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6911 | // 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] | 6912 | VkShaderObj |
| 6913 | tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, |
| 6914 | this); |
| 6915 | VkShaderObj |
| 6916 | te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, |
| 6917 | this); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6918 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6919 | shaderStages[0].sType = |
| 6920 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 6921 | shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6922 | shaderStages[0].shader = vs.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6923 | shaderStages[1].sType = |
| 6924 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 6925 | shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6926 | shaderStages[1].shader = tc.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6927 | shaderStages[2].sType = |
| 6928 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 6929 | shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6930 | shaderStages[2].shader = te.handle(); |
| 6931 | |
| 6932 | VkPipelineInputAssemblyStateCreateInfo iaCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6933 | iaCI.sType = |
| 6934 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
Chia-I Wu | 515eb8f | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6935 | iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6936 | |
| 6937 | VkPipelineTessellationStateCreateInfo tsCI = {}; |
| 6938 | tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO; |
| 6939 | tsCI.patchControlPoints = 0; // This will cause an error |
| 6940 | |
| 6941 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 6942 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6943 | gp_ci.pNext = NULL; |
| 6944 | gp_ci.stageCount = 3; |
| 6945 | gp_ci.pStages = shaderStages; |
| 6946 | gp_ci.pVertexInputState = NULL; |
| 6947 | gp_ci.pInputAssemblyState = &iaCI; |
| 6948 | gp_ci.pTessellationState = &tsCI; |
| 6949 | gp_ci.pViewportState = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6950 | gp_ci.pRasterizationState = NULL; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6951 | gp_ci.pMultisampleState = NULL; |
| 6952 | gp_ci.pDepthStencilState = NULL; |
| 6953 | gp_ci.pColorBlendState = NULL; |
| 6954 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6955 | gp_ci.layout = pipeline_layout; |
| 6956 | gp_ci.renderPass = renderPass(); |
| 6957 | |
| 6958 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 6959 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 6960 | pc_ci.pNext = NULL; |
| 6961 | pc_ci.initialSize = 0; |
| 6962 | pc_ci.initialData = 0; |
| 6963 | pc_ci.maxSize = 0; |
| 6964 | |
| 6965 | VkPipeline pipeline; |
| 6966 | VkPipelineCache pipelineCache; |
| 6967 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6968 | err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, |
| 6969 | &pipelineCache); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6970 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6971 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6972 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6973 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6974 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 6975 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6976 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6977 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6978 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6979 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6980 | } |
| 6981 | */ |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6982 | // Set scissor and viewport counts to different numbers |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6983 | TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6984 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6985 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6986 | m_errorMonitor->SetDesiredFailureMsg( |
| 6987 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6988 | "Gfx Pipeline viewport count (1) must match scissor count (0)."); |
| 6989 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6990 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6991 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6992 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6993 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6994 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6995 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6996 | |
| 6997 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6998 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6999 | ds_pool_ci.maxSets = 1; |
| 7000 | ds_pool_ci.poolSizeCount = 1; |
| 7001 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7002 | |
| 7003 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7004 | err = |
| 7005 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7006 | ASSERT_VK_SUCCESS(err); |
| 7007 | |
| 7008 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7009 | dsl_binding.binding = 0; |
| 7010 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7011 | dsl_binding.descriptorCount = 1; |
| 7012 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7013 | |
| 7014 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7015 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7016 | ds_layout_ci.bindingCount = 1; |
| 7017 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7018 | |
| 7019 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7020 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7021 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7022 | ASSERT_VK_SUCCESS(err); |
| 7023 | |
| 7024 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7025 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 7026 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7027 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 7028 | alloc_info.descriptorPool = ds_pool; |
| 7029 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7030 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7031 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7032 | ASSERT_VK_SUCCESS(err); |
| 7033 | |
| 7034 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7035 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7036 | pipeline_layout_ci.setLayoutCount = 1; |
| 7037 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7038 | |
| 7039 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7040 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7041 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7042 | ASSERT_VK_SUCCESS(err); |
| 7043 | |
| 7044 | VkViewport vp = {}; // Just need dummy vp to point to |
| 7045 | |
| 7046 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7047 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7048 | vp_state_ci.scissorCount = 0; |
| 7049 | vp_state_ci.viewportCount = 1; // Count mismatch should cause error |
| 7050 | vp_state_ci.pViewports = &vp; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7051 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 7052 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 7053 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7054 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 7055 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 7056 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 7057 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 7058 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 7059 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 7060 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 7061 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7062 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7063 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7064 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7065 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7066 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7067 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 7068 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7069 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 7070 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 7071 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7072 | |
| 7073 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7074 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7075 | gp_ci.stageCount = 2; |
| 7076 | gp_ci.pStages = shaderStages; |
| 7077 | gp_ci.pViewportState = &vp_state_ci; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 7078 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7079 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7080 | gp_ci.layout = pipeline_layout; |
| 7081 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7082 | |
| 7083 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7084 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7085 | |
| 7086 | VkPipeline pipeline; |
| 7087 | VkPipelineCache pipelineCache; |
| 7088 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7089 | err = |
| 7090 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7091 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7092 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7093 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7094 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7095 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7096 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7097 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7098 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7099 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7100 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7101 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7102 | // Don't set viewport state in PSO. This is an error b/c we always need this |
| 7103 | // state |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7104 | // 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] | 7105 | TEST_F(VkLayerTest, PSOViewportStateNotSet) { |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7106 | // Attempt to Create Gfx Pipeline w/o a VS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7107 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7108 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7109 | m_errorMonitor->SetDesiredFailureMsg( |
| 7110 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7111 | "Gfx Pipeline pViewportState is null. Even if "); |
| 7112 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7113 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7114 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7115 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7116 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7117 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7118 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7119 | |
| 7120 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7121 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7122 | ds_pool_ci.maxSets = 1; |
| 7123 | ds_pool_ci.poolSizeCount = 1; |
| 7124 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7125 | |
| 7126 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7127 | err = |
| 7128 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7129 | ASSERT_VK_SUCCESS(err); |
| 7130 | |
| 7131 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7132 | dsl_binding.binding = 0; |
| 7133 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7134 | dsl_binding.descriptorCount = 1; |
| 7135 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7136 | |
| 7137 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7138 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7139 | ds_layout_ci.bindingCount = 1; |
| 7140 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7141 | |
| 7142 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7143 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7144 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7145 | ASSERT_VK_SUCCESS(err); |
| 7146 | |
| 7147 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7148 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 7149 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7150 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 7151 | alloc_info.descriptorPool = ds_pool; |
| 7152 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7153 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7154 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7155 | ASSERT_VK_SUCCESS(err); |
| 7156 | |
| 7157 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7158 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7159 | pipeline_layout_ci.setLayoutCount = 1; |
| 7160 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7161 | |
| 7162 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7163 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7164 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7165 | ASSERT_VK_SUCCESS(err); |
| 7166 | |
| 7167 | VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR; |
| 7168 | // Set scissor as dynamic to avoid second error |
| 7169 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7170 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 7171 | dyn_state_ci.dynamicStateCount = 1; |
| 7172 | dyn_state_ci.pDynamicStates = &sc_state; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7173 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 7174 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7175 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7176 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7177 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7178 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7179 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7180 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 7181 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7182 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 7183 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 7184 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7185 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 7186 | |
| 7187 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 7188 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7189 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 7190 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 7191 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 7192 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 7193 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 7194 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 7195 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7196 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7197 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7198 | gp_ci.stageCount = 2; |
| 7199 | gp_ci.pStages = shaderStages; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 7200 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7201 | gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state |
| 7202 | // should cause validation error |
| 7203 | gp_ci.pDynamicState = &dyn_state_ci; |
| 7204 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7205 | gp_ci.layout = pipeline_layout; |
| 7206 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7207 | |
| 7208 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7209 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7210 | |
| 7211 | VkPipeline pipeline; |
| 7212 | VkPipelineCache pipelineCache; |
| 7213 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7214 | err = |
| 7215 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7216 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7217 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7218 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7219 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7220 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7221 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7222 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7223 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7224 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7225 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7226 | } |
| 7227 | // Create PSO w/o non-zero viewportCount but no viewport data |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7228 | // Then run second test where dynamic scissor count doesn't match PSO scissor |
| 7229 | // count |
| 7230 | TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) { |
| 7231 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7232 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7233 | m_errorMonitor->SetDesiredFailureMsg( |
| 7234 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7235 | "Gfx Pipeline viewportCount is 1, but pViewports is NULL. "); |
| 7236 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7237 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7238 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7239 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7240 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7241 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7242 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7243 | |
| 7244 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7245 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7246 | ds_pool_ci.maxSets = 1; |
| 7247 | ds_pool_ci.poolSizeCount = 1; |
| 7248 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7249 | |
| 7250 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7251 | err = |
| 7252 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7253 | ASSERT_VK_SUCCESS(err); |
| 7254 | |
| 7255 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7256 | dsl_binding.binding = 0; |
| 7257 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7258 | dsl_binding.descriptorCount = 1; |
| 7259 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7260 | |
| 7261 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7262 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7263 | ds_layout_ci.bindingCount = 1; |
| 7264 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7265 | |
| 7266 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7267 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7268 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7269 | ASSERT_VK_SUCCESS(err); |
| 7270 | |
| 7271 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7272 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 7273 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7274 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 7275 | alloc_info.descriptorPool = ds_pool; |
| 7276 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7277 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7278 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7279 | ASSERT_VK_SUCCESS(err); |
| 7280 | |
| 7281 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7282 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7283 | pipeline_layout_ci.setLayoutCount = 1; |
| 7284 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7285 | |
| 7286 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7287 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7288 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7289 | ASSERT_VK_SUCCESS(err); |
| 7290 | |
| 7291 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7292 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7293 | vp_state_ci.viewportCount = 1; |
| 7294 | vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error |
| 7295 | vp_state_ci.scissorCount = 1; |
| 7296 | vp_state_ci.pScissors = |
| 7297 | NULL; // Scissor is dynamic (below) so this won't cause error |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7298 | |
| 7299 | VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR; |
| 7300 | // Set scissor as dynamic to avoid that error |
| 7301 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7302 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 7303 | dyn_state_ci.dynamicStateCount = 1; |
| 7304 | dyn_state_ci.pDynamicStates = &sc_state; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7305 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 7306 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7307 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7308 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7309 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7310 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7311 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7312 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 7313 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7314 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 7315 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 7316 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7317 | |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7318 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 7319 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 7320 | vi_ci.pNext = nullptr; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7321 | vi_ci.vertexBindingDescriptionCount = 0; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7322 | vi_ci.pVertexBindingDescriptions = nullptr; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7323 | vi_ci.vertexAttributeDescriptionCount = 0; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7324 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 7325 | |
| 7326 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 7327 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 7328 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 7329 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7330 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7331 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7332 | rs_ci.pNext = nullptr; |
| 7333 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 7334 | VkPipelineColorBlendAttachmentState att = {}; |
| 7335 | att.blendEnable = VK_FALSE; |
| 7336 | att.colorWriteMask = 0xf; |
| 7337 | |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7338 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 7339 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 7340 | cb_ci.pNext = nullptr; |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 7341 | cb_ci.attachmentCount = 1; |
| 7342 | cb_ci.pAttachments = &att; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7343 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7344 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7345 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7346 | gp_ci.stageCount = 2; |
| 7347 | gp_ci.pStages = shaderStages; |
| 7348 | gp_ci.pVertexInputState = &vi_ci; |
| 7349 | gp_ci.pInputAssemblyState = &ia_ci; |
| 7350 | gp_ci.pViewportState = &vp_state_ci; |
| 7351 | gp_ci.pRasterizationState = &rs_ci; |
| 7352 | gp_ci.pColorBlendState = &cb_ci; |
| 7353 | gp_ci.pDynamicState = &dyn_state_ci; |
| 7354 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7355 | gp_ci.layout = pipeline_layout; |
| 7356 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7357 | |
| 7358 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7359 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7360 | |
| 7361 | VkPipeline pipeline; |
| 7362 | VkPipelineCache pipelineCache; |
| 7363 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7364 | err = |
| 7365 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7366 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7367 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7368 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7369 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7370 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7371 | |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7372 | // 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] | 7373 | // First need to successfully create the PSO from above by setting |
| 7374 | // pViewports |
| 7375 | m_errorMonitor->SetDesiredFailureMsg( |
| 7376 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7377 | "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO " |
| 7378 | "scissorCount is 1. These counts must match."); |
| 7379 | |
| 7380 | VkViewport vp = {}; // Just need dummy vp to point to |
| 7381 | vp_state_ci.pViewports = &vp; |
| 7382 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7383 | &gp_ci, NULL, &pipeline); |
| 7384 | ASSERT_VK_SUCCESS(err); |
| 7385 | BeginCommandBuffer(); |
| 7386 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7387 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 7388 | VkRect2D scissors[2] = {}; // don't care about data |
| 7389 | // Count of 2 doesn't match PSO count of 1 |
| 7390 | vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors); |
| 7391 | Draw(1, 0, 0, 0); |
| 7392 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7393 | m_errorMonitor->VerifyFound(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7394 | |
| 7395 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7396 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7397 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7398 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7399 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7400 | } |
| 7401 | // Create PSO w/o non-zero scissorCount but no scissor data |
| 7402 | // Then run second test where dynamic viewportCount doesn't match PSO |
| 7403 | // viewportCount |
| 7404 | TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) { |
| 7405 | VkResult err; |
| 7406 | |
| 7407 | m_errorMonitor->SetDesiredFailureMsg( |
| 7408 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7409 | "Gfx Pipeline scissorCount is 1, but pScissors is NULL. "); |
| 7410 | |
| 7411 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7412 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7413 | |
| 7414 | VkDescriptorPoolSize ds_type_count = {}; |
| 7415 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7416 | ds_type_count.descriptorCount = 1; |
| 7417 | |
| 7418 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 7419 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7420 | ds_pool_ci.maxSets = 1; |
| 7421 | ds_pool_ci.poolSizeCount = 1; |
| 7422 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 7423 | |
| 7424 | VkDescriptorPool ds_pool; |
| 7425 | err = |
| 7426 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 7427 | ASSERT_VK_SUCCESS(err); |
| 7428 | |
| 7429 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 7430 | dsl_binding.binding = 0; |
| 7431 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7432 | dsl_binding.descriptorCount = 1; |
| 7433 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7434 | |
| 7435 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 7436 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7437 | ds_layout_ci.bindingCount = 1; |
| 7438 | ds_layout_ci.pBindings = &dsl_binding; |
| 7439 | |
| 7440 | VkDescriptorSetLayout ds_layout; |
| 7441 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7442 | &ds_layout); |
| 7443 | ASSERT_VK_SUCCESS(err); |
| 7444 | |
| 7445 | VkDescriptorSet descriptorSet; |
| 7446 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 7447 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 7448 | alloc_info.descriptorSetCount = 1; |
| 7449 | alloc_info.descriptorPool = ds_pool; |
| 7450 | alloc_info.pSetLayouts = &ds_layout; |
| 7451 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7452 | &descriptorSet); |
| 7453 | ASSERT_VK_SUCCESS(err); |
| 7454 | |
| 7455 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 7456 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7457 | pipeline_layout_ci.setLayoutCount = 1; |
| 7458 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 7459 | |
| 7460 | VkPipelineLayout pipeline_layout; |
| 7461 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7462 | &pipeline_layout); |
| 7463 | ASSERT_VK_SUCCESS(err); |
| 7464 | |
| 7465 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 7466 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7467 | vp_state_ci.scissorCount = 1; |
| 7468 | vp_state_ci.pScissors = |
| 7469 | NULL; // Null scissor w/ count of 1 should cause error |
| 7470 | vp_state_ci.viewportCount = 1; |
| 7471 | vp_state_ci.pViewports = |
| 7472 | NULL; // vp is dynamic (below) so this won't cause error |
| 7473 | |
| 7474 | VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT; |
| 7475 | // Set scissor as dynamic to avoid that error |
| 7476 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
| 7477 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 7478 | dyn_state_ci.dynamicStateCount = 1; |
| 7479 | dyn_state_ci.pDynamicStates = &vp_state; |
| 7480 | |
| 7481 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
| 7482 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 7483 | |
| 7484 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7485 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7486 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7487 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 7488 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7489 | // but add it to be able to run on more devices |
| 7490 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 7491 | shaderStages[1] = fs.GetStageCreateInfo(); |
| 7492 | |
| 7493 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 7494 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 7495 | vi_ci.pNext = nullptr; |
| 7496 | vi_ci.vertexBindingDescriptionCount = 0; |
| 7497 | vi_ci.pVertexBindingDescriptions = nullptr; |
| 7498 | vi_ci.vertexAttributeDescriptionCount = 0; |
| 7499 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 7500 | |
| 7501 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 7502 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 7503 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 7504 | |
| 7505 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
| 7506 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7507 | rs_ci.pNext = nullptr; |
| 7508 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 7509 | VkPipelineColorBlendAttachmentState att = {}; |
| 7510 | att.blendEnable = VK_FALSE; |
| 7511 | att.colorWriteMask = 0xf; |
| 7512 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7513 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 7514 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 7515 | cb_ci.pNext = nullptr; |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 7516 | cb_ci.attachmentCount = 1; |
| 7517 | cb_ci.pAttachments = &att; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7518 | |
| 7519 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 7520 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7521 | gp_ci.stageCount = 2; |
| 7522 | gp_ci.pStages = shaderStages; |
| 7523 | gp_ci.pVertexInputState = &vi_ci; |
| 7524 | gp_ci.pInputAssemblyState = &ia_ci; |
| 7525 | gp_ci.pViewportState = &vp_state_ci; |
| 7526 | gp_ci.pRasterizationState = &rs_ci; |
| 7527 | gp_ci.pColorBlendState = &cb_ci; |
| 7528 | gp_ci.pDynamicState = &dyn_state_ci; |
| 7529 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7530 | gp_ci.layout = pipeline_layout; |
| 7531 | gp_ci.renderPass = renderPass(); |
| 7532 | |
| 7533 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 7534 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 7535 | |
| 7536 | VkPipeline pipeline; |
| 7537 | VkPipelineCache pipelineCache; |
| 7538 | |
| 7539 | err = |
| 7540 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7541 | ASSERT_VK_SUCCESS(err); |
| 7542 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7543 | &gp_ci, NULL, &pipeline); |
| 7544 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7545 | m_errorMonitor->VerifyFound(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7546 | |
| 7547 | // Now hit second fail case where we set scissor w/ different count than PSO |
| 7548 | // First need to successfully create the PSO from above by setting |
| 7549 | // pViewports |
| 7550 | m_errorMonitor->SetDesiredFailureMsg( |
| 7551 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7552 | "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO " |
| 7553 | "viewportCount is 1. These counts must match."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7554 | |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7555 | VkRect2D sc = {}; // Just need dummy vp to point to |
| 7556 | vp_state_ci.pScissors = ≻ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7557 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7558 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7559 | ASSERT_VK_SUCCESS(err); |
| 7560 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7561 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7562 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7563 | VkViewport viewports[2] = {}; // don't care about data |
| 7564 | // Count of 2 doesn't match PSO count of 1 |
Jon Ashburn | 19d3bf1 | 2015-12-30 14:06:55 -0700 | [diff] [blame] | 7565 | vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7566 | Draw(1, 0, 0, 0); |
| 7567 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7568 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7569 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7570 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7571 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7572 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7573 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7574 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7575 | } |
| 7576 | |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7577 | TEST_F(VkLayerTest, PSOLineWidthInvalid) { |
| 7578 | VkResult err; |
| 7579 | |
| 7580 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7581 | "Attempt to set lineWidth to -1"); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7582 | |
| 7583 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7584 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7585 | |
| 7586 | VkDescriptorPoolSize ds_type_count = {}; |
| 7587 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7588 | ds_type_count.descriptorCount = 1; |
| 7589 | |
| 7590 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 7591 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7592 | ds_pool_ci.maxSets = 1; |
| 7593 | ds_pool_ci.poolSizeCount = 1; |
| 7594 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 7595 | |
| 7596 | VkDescriptorPool ds_pool; |
| 7597 | err = |
| 7598 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 7599 | ASSERT_VK_SUCCESS(err); |
| 7600 | |
| 7601 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 7602 | dsl_binding.binding = 0; |
| 7603 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7604 | dsl_binding.descriptorCount = 1; |
| 7605 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7606 | |
| 7607 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 7608 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7609 | ds_layout_ci.bindingCount = 1; |
| 7610 | ds_layout_ci.pBindings = &dsl_binding; |
| 7611 | |
| 7612 | VkDescriptorSetLayout ds_layout; |
| 7613 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7614 | &ds_layout); |
| 7615 | ASSERT_VK_SUCCESS(err); |
| 7616 | |
| 7617 | VkDescriptorSet descriptorSet; |
| 7618 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 7619 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 7620 | alloc_info.descriptorSetCount = 1; |
| 7621 | alloc_info.descriptorPool = ds_pool; |
| 7622 | alloc_info.pSetLayouts = &ds_layout; |
| 7623 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7624 | &descriptorSet); |
| 7625 | ASSERT_VK_SUCCESS(err); |
| 7626 | |
| 7627 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 7628 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7629 | pipeline_layout_ci.setLayoutCount = 1; |
| 7630 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 7631 | |
| 7632 | VkPipelineLayout pipeline_layout; |
| 7633 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7634 | &pipeline_layout); |
| 7635 | ASSERT_VK_SUCCESS(err); |
| 7636 | |
| 7637 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 7638 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7639 | vp_state_ci.scissorCount = 1; |
| 7640 | vp_state_ci.pScissors = NULL; |
| 7641 | vp_state_ci.viewportCount = 1; |
| 7642 | vp_state_ci.pViewports = NULL; |
| 7643 | |
| 7644 | VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, |
| 7645 | VK_DYNAMIC_STATE_SCISSOR, |
| 7646 | VK_DYNAMIC_STATE_LINE_WIDTH}; |
| 7647 | // Set scissor as dynamic to avoid that error |
| 7648 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
| 7649 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 7650 | dyn_state_ci.dynamicStateCount = 2; |
| 7651 | dyn_state_ci.pDynamicStates = dynamic_states; |
| 7652 | |
| 7653 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
| 7654 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 7655 | |
| 7656 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7657 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7658 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7659 | VK_SHADER_STAGE_FRAGMENT_BIT, |
| 7660 | this); // TODO - We shouldn't need a fragment shader |
| 7661 | // but add it to be able to run on more devices |
| 7662 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 7663 | shaderStages[1] = fs.GetStageCreateInfo(); |
| 7664 | |
| 7665 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 7666 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 7667 | vi_ci.pNext = nullptr; |
| 7668 | vi_ci.vertexBindingDescriptionCount = 0; |
| 7669 | vi_ci.pVertexBindingDescriptions = nullptr; |
| 7670 | vi_ci.vertexAttributeDescriptionCount = 0; |
| 7671 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 7672 | |
| 7673 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 7674 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 7675 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 7676 | |
| 7677 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
| 7678 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7679 | rs_ci.pNext = nullptr; |
| 7680 | |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7681 | // Check too low (line width of -1.0f). |
| 7682 | rs_ci.lineWidth = -1.0f; |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7683 | |
| 7684 | VkPipelineColorBlendAttachmentState att = {}; |
| 7685 | att.blendEnable = VK_FALSE; |
| 7686 | att.colorWriteMask = 0xf; |
| 7687 | |
| 7688 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 7689 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 7690 | cb_ci.pNext = nullptr; |
| 7691 | cb_ci.attachmentCount = 1; |
| 7692 | cb_ci.pAttachments = &att; |
| 7693 | |
| 7694 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 7695 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7696 | gp_ci.stageCount = 2; |
| 7697 | gp_ci.pStages = shaderStages; |
| 7698 | gp_ci.pVertexInputState = &vi_ci; |
| 7699 | gp_ci.pInputAssemblyState = &ia_ci; |
| 7700 | gp_ci.pViewportState = &vp_state_ci; |
| 7701 | gp_ci.pRasterizationState = &rs_ci; |
| 7702 | gp_ci.pColorBlendState = &cb_ci; |
| 7703 | gp_ci.pDynamicState = &dyn_state_ci; |
| 7704 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7705 | gp_ci.layout = pipeline_layout; |
| 7706 | gp_ci.renderPass = renderPass(); |
| 7707 | |
| 7708 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 7709 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 7710 | |
| 7711 | VkPipeline pipeline; |
| 7712 | VkPipelineCache pipelineCache; |
| 7713 | |
| 7714 | err = |
| 7715 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7716 | ASSERT_VK_SUCCESS(err); |
| 7717 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7718 | &gp_ci, NULL, &pipeline); |
| 7719 | |
| 7720 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7721 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7722 | |
| 7723 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7724 | "Attempt to set lineWidth to 65536"); |
| 7725 | |
| 7726 | // Check too high (line width of 65536.0f). |
| 7727 | rs_ci.lineWidth = 65536.0f; |
| 7728 | |
| 7729 | err = |
| 7730 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7731 | ASSERT_VK_SUCCESS(err); |
| 7732 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7733 | &gp_ci, NULL, &pipeline); |
| 7734 | |
| 7735 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7736 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7737 | |
| 7738 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7739 | "Attempt to set lineWidth to -1"); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7740 | |
| 7741 | dyn_state_ci.dynamicStateCount = 3; |
| 7742 | |
| 7743 | rs_ci.lineWidth = 1.0f; |
| 7744 | |
| 7745 | err = |
| 7746 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7747 | ASSERT_VK_SUCCESS(err); |
| 7748 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7749 | &gp_ci, NULL, &pipeline); |
| 7750 | BeginCommandBuffer(); |
| 7751 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7752 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 7753 | |
| 7754 | // Check too low with dynamic setting. |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7755 | vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7756 | m_errorMonitor->VerifyFound(); |
| 7757 | |
| 7758 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7759 | "Attempt to set lineWidth to 65536"); |
| 7760 | |
| 7761 | // Check too high with dynamic setting. |
| 7762 | vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f); |
| 7763 | m_errorMonitor->VerifyFound(); |
| 7764 | EndCommandBuffer(); |
| 7765 | |
| 7766 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7767 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7768 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7769 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7770 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7771 | } |
| 7772 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7773 | TEST_F(VkLayerTest, NullRenderPass) { |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7774 | // Bind a NULL RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7775 | m_errorMonitor->SetDesiredFailureMsg( |
| 7776 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7777 | "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()"); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7778 | |
| 7779 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7780 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7781 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 7782 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7783 | // Don't care about RenderPass handle b/c error should be flagged before |
| 7784 | // that |
| 7785 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, |
| 7786 | VK_SUBPASS_CONTENTS_INLINE); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7787 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7788 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7789 | } |
| 7790 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7791 | TEST_F(VkLayerTest, RenderPassWithinRenderPass) { |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7792 | // Bind a BeginRenderPass within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7793 | m_errorMonitor->SetDesiredFailureMsg( |
| 7794 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7795 | "It is invalid to issue this call inside an active render pass"); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7796 | |
| 7797 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7798 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7799 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 7800 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7801 | // Just create a dummy Renderpass that's non-NULL so we can get to the |
| 7802 | // proper error |
Chris Forbes | 38ae7c4 | 2016-06-21 20:51:44 +1200 | [diff] [blame] | 7803 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7804 | VK_SUBPASS_CONTENTS_INLINE); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7805 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7806 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 7807 | } |
| 7808 | |
Chris Forbes | 2eeabe3 | 2016-06-21 20:52:34 +1200 | [diff] [blame] | 7809 | TEST_F(VkLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) { |
| 7810 | m_errorMonitor->ExpectSuccess(); |
| 7811 | |
| 7812 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7813 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7814 | |
| 7815 | BeginCommandBuffer(); // framework implicitly begins the renderpass. |
| 7816 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // end implicit. |
| 7817 | |
| 7818 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, |
| 7819 | VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS); |
| 7820 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 7821 | m_errorMonitor->VerifyNotFound(); |
| 7822 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, |
| 7823 | VK_SUBPASS_CONTENTS_INLINE); |
| 7824 | m_errorMonitor->VerifyNotFound(); |
| 7825 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 7826 | m_errorMonitor->VerifyNotFound(); |
| 7827 | |
| 7828 | m_commandBuffer->EndCommandBuffer(); |
| 7829 | m_errorMonitor->VerifyNotFound(); |
| 7830 | } |
| 7831 | |
Tobin Ehlis | 5a1c033 | 2016-05-31 13:59:26 -0600 | [diff] [blame] | 7832 | TEST_F(VkLayerTest, RenderPassClearOpMismatch) { |
| 7833 | TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than" |
| 7834 | "the number of renderPass attachments that use loadOp" |
| 7835 | "VK_ATTACHMENT_LOAD_OP_CLEAR."); |
| 7836 | |
| 7837 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7838 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7839 | |
| 7840 | // Create a renderPass with a single attachment that uses loadOp CLEAR |
| 7841 | VkAttachmentReference attach = {}; |
| 7842 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 7843 | VkSubpassDescription subpass = {}; |
| 7844 | subpass.inputAttachmentCount = 1; |
| 7845 | subpass.pInputAttachments = &attach; |
| 7846 | VkRenderPassCreateInfo rpci = {}; |
| 7847 | rpci.subpassCount = 1; |
| 7848 | rpci.pSubpasses = &subpass; |
| 7849 | rpci.attachmentCount = 1; |
| 7850 | VkAttachmentDescription attach_desc = {}; |
| 7851 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 7852 | // Set loadOp to CLEAR |
| 7853 | attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 7854 | rpci.pAttachments = &attach_desc; |
| 7855 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 7856 | VkRenderPass rp; |
| 7857 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 7858 | |
| 7859 | VkCommandBufferInheritanceInfo hinfo = {}; |
| 7860 | hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; |
| 7861 | hinfo.renderPass = VK_NULL_HANDLE; |
| 7862 | hinfo.subpass = 0; |
| 7863 | hinfo.framebuffer = VK_NULL_HANDLE; |
| 7864 | hinfo.occlusionQueryEnable = VK_FALSE; |
| 7865 | hinfo.queryFlags = 0; |
| 7866 | hinfo.pipelineStatistics = 0; |
| 7867 | VkCommandBufferBeginInfo info = {}; |
| 7868 | info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
| 7869 | info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 7870 | info.pInheritanceInfo = &hinfo; |
| 7871 | |
| 7872 | vkBeginCommandBuffer(m_commandBuffer->handle(), &info); |
| 7873 | VkRenderPassBeginInfo rp_begin = {}; |
| 7874 | rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 7875 | rp_begin.pNext = NULL; |
| 7876 | rp_begin.renderPass = renderPass(); |
| 7877 | rp_begin.framebuffer = framebuffer(); |
| 7878 | rp_begin.clearValueCount = 0; // Should be 1 |
| 7879 | |
| 7880 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7881 | " has a clearValueCount of 0 but the " |
| 7882 | "actual number of attachments in " |
| 7883 | "renderPass "); |
| 7884 | |
| 7885 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, |
| 7886 | VK_SUBPASS_CONTENTS_INLINE); |
| 7887 | |
| 7888 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 5c70ebd | 2016-06-09 13:45:00 -0600 | [diff] [blame] | 7889 | |
| 7890 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 5a1c033 | 2016-05-31 13:59:26 -0600 | [diff] [blame] | 7891 | } |
| 7892 | |
Cody Northrop | 3bb4d96 | 2016-05-09 16:15:57 -0600 | [diff] [blame] | 7893 | TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) { |
| 7894 | |
| 7895 | TEST_DESCRIPTION("End a command buffer with an active render pass"); |
| 7896 | |
| 7897 | m_errorMonitor->SetDesiredFailureMsg( |
| 7898 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7899 | "It is invalid to issue this call inside an active render pass"); |
| 7900 | |
| 7901 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7902 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7903 | |
| 7904 | // The framework's BeginCommandBuffer calls CreateRenderPass |
| 7905 | BeginCommandBuffer(); |
| 7906 | |
| 7907 | // Call directly into vkEndCommandBuffer instead of the |
| 7908 | // the framework's EndCommandBuffer, which inserts a |
| 7909 | // vkEndRenderPass |
| 7910 | vkEndCommandBuffer(m_commandBuffer->GetBufferHandle()); |
| 7911 | |
| 7912 | m_errorMonitor->VerifyFound(); |
| 7913 | |
| 7914 | // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY |
| 7915 | // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT |
| 7916 | } |
| 7917 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7918 | TEST_F(VkLayerTest, FillBufferWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7919 | // Call CmdFillBuffer within an active renderpass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7920 | m_errorMonitor->SetDesiredFailureMsg( |
| 7921 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7922 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7923 | |
| 7924 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7925 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7926 | |
| 7927 | // Renderpass is started here |
| 7928 | BeginCommandBuffer(); |
| 7929 | |
| 7930 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7931 | vk_testing::Buffer dstBuffer; |
| 7932 | dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7933 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7934 | m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7935 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7936 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7937 | } |
| 7938 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7939 | TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7940 | // Call CmdUpdateBuffer within an active renderpass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7941 | m_errorMonitor->SetDesiredFailureMsg( |
| 7942 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7943 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7944 | |
| 7945 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7946 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7947 | |
| 7948 | // Renderpass is started here |
| 7949 | BeginCommandBuffer(); |
| 7950 | |
| 7951 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7952 | vk_testing::Buffer dstBuffer; |
| 7953 | dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7954 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7955 | VkDeviceSize dstOffset = 0; |
| 7956 | VkDeviceSize dataSize = 1024; |
| 7957 | const uint32_t *pData = NULL; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7958 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7959 | vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), |
| 7960 | dstOffset, dataSize, pData); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7961 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7962 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7963 | } |
| 7964 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7965 | TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7966 | // Call CmdClearColorImage within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7967 | m_errorMonitor->SetDesiredFailureMsg( |
| 7968 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7969 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7970 | |
| 7971 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7972 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7973 | |
| 7974 | // Renderpass is started here |
| 7975 | BeginCommandBuffer(); |
| 7976 | |
Michael Lentine | 0a369f6 | 2016-02-03 16:51:46 -0600 | [diff] [blame] | 7977 | VkClearColorValue clear_color; |
| 7978 | memset(clear_color.uint32, 0, sizeof(uint32_t) * 4); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7979 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 7980 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 7981 | const int32_t tex_width = 32; |
| 7982 | const int32_t tex_height = 32; |
| 7983 | VkImageCreateInfo image_create_info = {}; |
| 7984 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 7985 | image_create_info.pNext = NULL; |
| 7986 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 7987 | image_create_info.format = tex_format; |
| 7988 | image_create_info.extent.width = tex_width; |
| 7989 | image_create_info.extent.height = tex_height; |
| 7990 | image_create_info.extent.depth = 1; |
| 7991 | image_create_info.mipLevels = 1; |
| 7992 | image_create_info.arrayLayers = 1; |
| 7993 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 7994 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 7995 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7996 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7997 | vk_testing::Image dstImage; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7998 | dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 7999 | reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8000 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8001 | const VkImageSubresourceRange range = vk_testing::Image::subresource_range( |
| 8002 | image_create_info, VK_IMAGE_ASPECT_COLOR_BIT); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8003 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8004 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), |
| 8005 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8006 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8007 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8008 | } |
| 8009 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8010 | TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8011 | // Call CmdClearDepthStencilImage within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8012 | m_errorMonitor->SetDesiredFailureMsg( |
| 8013 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8014 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8015 | |
| 8016 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8017 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8018 | |
| 8019 | // Renderpass is started here |
| 8020 | BeginCommandBuffer(); |
| 8021 | |
| 8022 | VkClearDepthStencilValue clear_value = {0}; |
Dustin Graves | a2e5c94 | 2016-02-11 18:28:06 -0700 | [diff] [blame] | 8023 | VkMemoryPropertyFlags reqs = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8024 | VkImageCreateInfo image_create_info = vk_testing::Image::create_info(); |
| 8025 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 8026 | image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 8027 | image_create_info.extent.width = 64; |
| 8028 | image_create_info.extent.height = 64; |
| 8029 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 8030 | image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8031 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8032 | vk_testing::Image dstImage; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8033 | dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 8034 | reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8035 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8036 | const VkImageSubresourceRange range = vk_testing::Image::subresource_range( |
| 8037 | image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8038 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8039 | vkCmdClearDepthStencilImage( |
| 8040 | m_commandBuffer->GetBufferHandle(), dstImage.handle(), |
| 8041 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, |
| 8042 | &range); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8043 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8044 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8045 | } |
| 8046 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8047 | TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) { |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 8048 | // Call CmdClearAttachmentss outside of an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8049 | VkResult err; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8050 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 8051 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8052 | "vkCmdClearAttachments: This call " |
| 8053 | "must be issued inside an active " |
| 8054 | "render pass"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8055 | |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8056 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8057 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8058 | |
| 8059 | // Start no RenderPass |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8060 | err = m_commandBuffer->BeginCommandBuffer(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8061 | ASSERT_VK_SUCCESS(err); |
| 8062 | |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 8063 | VkClearAttachment color_attachment; |
| 8064 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 8065 | color_attachment.clearValue.color.float32[0] = 0; |
| 8066 | color_attachment.clearValue.color.float32[1] = 0; |
| 8067 | color_attachment.clearValue.color.float32[2] = 0; |
| 8068 | color_attachment.clearValue.color.float32[3] = 0; |
| 8069 | color_attachment.colorAttachment = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8070 | VkClearRect clear_rect = {{{0, 0}, {32, 32}}}; |
| 8071 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 8072 | &color_attachment, 1, &clear_rect); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8073 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8074 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 8075 | } |
| 8076 | |
Karl Schultz | 9e66a29 | 2016-04-21 15:57:51 -0600 | [diff] [blame] | 8077 | TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) { |
| 8078 | // Try to add a buffer memory barrier with no buffer. |
| 8079 | m_errorMonitor->SetDesiredFailureMsg( |
| 8080 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8081 | "required parameter pBufferMemoryBarriers[i].buffer specified as VK_NULL_HANDLE"); |
| 8082 | |
| 8083 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8084 | BeginCommandBuffer(); |
| 8085 | |
| 8086 | VkBufferMemoryBarrier buf_barrier = {}; |
| 8087 | buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; |
| 8088 | buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 8089 | buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 8090 | buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 8091 | buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 8092 | buf_barrier.buffer = VK_NULL_HANDLE; |
| 8093 | buf_barrier.offset = 0; |
| 8094 | buf_barrier.size = VK_WHOLE_SIZE; |
| 8095 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8096 | VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, |
| 8097 | 0, 0, nullptr, 1, &buf_barrier, 0, nullptr); |
| 8098 | |
| 8099 | m_errorMonitor->VerifyFound(); |
| 8100 | } |
| 8101 | |
Tony Barbour | 7fd5c0f | 2016-05-03 16:11:53 -0600 | [diff] [blame] | 8102 | TEST_F(VkLayerTest, InvalidBarriers) { |
| 8103 | TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER "); |
| 8104 | |
| 8105 | m_errorMonitor->SetDesiredFailureMsg( |
| 8106 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass"); |
| 8107 | |
| 8108 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8109 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8110 | |
| 8111 | VkMemoryBarrier mem_barrier = {}; |
| 8112 | mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER; |
| 8113 | mem_barrier.pNext = NULL; |
| 8114 | mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 8115 | mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 8116 | BeginCommandBuffer(); |
| 8117 | // BeginCommandBuffer() starts a render pass |
| 8118 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8119 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8120 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1, |
| 8121 | &mem_barrier, 0, nullptr, 0, nullptr); |
| 8122 | m_errorMonitor->VerifyFound(); |
| 8123 | |
| 8124 | m_errorMonitor->SetDesiredFailureMsg( |
| 8125 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8126 | "Image Layout cannot be transitioned to UNDEFINED"); |
| 8127 | VkImageObj image(m_device); |
| 8128 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 8129 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 8130 | ASSERT_TRUE(image.initialized()); |
| 8131 | VkImageMemoryBarrier img_barrier = {}; |
| 8132 | img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 8133 | img_barrier.pNext = NULL; |
| 8134 | img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 8135 | img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 8136 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 8137 | // New layout can't be UNDEFINED |
| 8138 | img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 8139 | img_barrier.image = image.handle(); |
| 8140 | img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 8141 | img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 8142 | img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 8143 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 8144 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 8145 | img_barrier.subresourceRange.layerCount = 1; |
| 8146 | img_barrier.subresourceRange.levelCount = 1; |
| 8147 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8148 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8149 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 8150 | nullptr, 1, &img_barrier); |
| 8151 | m_errorMonitor->VerifyFound(); |
| 8152 | img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 8153 | |
| 8154 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8155 | "Subresource must have the sum of the " |
| 8156 | "baseArrayLayer"); |
| 8157 | // baseArrayLayer + layerCount must be <= image's arrayLayers |
| 8158 | img_barrier.subresourceRange.baseArrayLayer = 1; |
| 8159 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8160 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8161 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 8162 | nullptr, 1, &img_barrier); |
| 8163 | m_errorMonitor->VerifyFound(); |
| 8164 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 8165 | |
| 8166 | m_errorMonitor->SetDesiredFailureMsg( |
| 8167 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8168 | "Subresource must have the sum of the baseMipLevel"); |
| 8169 | // baseMipLevel + levelCount must be <= image's mipLevels |
| 8170 | img_barrier.subresourceRange.baseMipLevel = 1; |
| 8171 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8172 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8173 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 8174 | nullptr, 1, &img_barrier); |
| 8175 | m_errorMonitor->VerifyFound(); |
| 8176 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 8177 | |
| 8178 | m_errorMonitor->SetDesiredFailureMsg( |
| 8179 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8180 | "Buffer Barriers cannot be used during a render pass"); |
| 8181 | vk_testing::Buffer buffer; |
| 8182 | buffer.init(*m_device, 256); |
| 8183 | VkBufferMemoryBarrier buf_barrier = {}; |
| 8184 | buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; |
| 8185 | buf_barrier.pNext = NULL; |
| 8186 | buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 8187 | buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 8188 | buf_barrier.buffer = buffer.handle(); |
| 8189 | buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 8190 | buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 8191 | buf_barrier.offset = 0; |
| 8192 | buf_barrier.size = VK_WHOLE_SIZE; |
| 8193 | // Can't send buffer barrier during a render pass |
| 8194 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8195 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8196 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 8197 | &buf_barrier, 0, nullptr); |
| 8198 | m_errorMonitor->VerifyFound(); |
| 8199 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 8200 | |
| 8201 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8202 | "which is not less than total size"); |
| 8203 | buf_barrier.offset = 257; |
| 8204 | // Offset greater than total size |
| 8205 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8206 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8207 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 8208 | &buf_barrier, 0, nullptr); |
| 8209 | m_errorMonitor->VerifyFound(); |
| 8210 | buf_barrier.offset = 0; |
| 8211 | |
| 8212 | m_errorMonitor->SetDesiredFailureMsg( |
| 8213 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size"); |
| 8214 | buf_barrier.size = 257; |
| 8215 | // Size greater than total size |
| 8216 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8217 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8218 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 8219 | &buf_barrier, 0, nullptr); |
| 8220 | m_errorMonitor->VerifyFound(); |
| 8221 | buf_barrier.size = VK_WHOLE_SIZE; |
| 8222 | |
| 8223 | m_errorMonitor->SetDesiredFailureMsg( |
| 8224 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8225 | "Image is a depth and stencil format and thus must " |
| 8226 | "have both VK_IMAGE_ASPECT_DEPTH_BIT and " |
| 8227 | "VK_IMAGE_ASPECT_STENCIL_BIT set."); |
| 8228 | VkDepthStencilObj ds_image(m_device); |
| 8229 | ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT); |
| 8230 | ASSERT_TRUE(ds_image.initialized()); |
| 8231 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 8232 | img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 8233 | img_barrier.image = ds_image.handle(); |
| 8234 | // Leave aspectMask at COLOR on purpose |
| 8235 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 8236 | VK_PIPELINE_STAGE_HOST_BIT, |
| 8237 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 8238 | nullptr, 1, &img_barrier); |
| 8239 | m_errorMonitor->VerifyFound(); |
| 8240 | } |
| 8241 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8242 | TEST_F(VkLayerTest, IdxBufferAlignmentError) { |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8243 | // Bind a BeginRenderPass within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8244 | VkResult err; |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8245 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8246 | m_errorMonitor->SetDesiredFailureMsg( |
| 8247 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8248 | "vkCmdBindIndexBuffer() offset (0x7) does not fall on "); |
| 8249 | |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8250 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8251 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8252 | uint32_t qfi = 0; |
| 8253 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8254 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 8255 | buffCI.size = 1024; |
| 8256 | buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; |
| 8257 | buffCI.queueFamilyIndexCount = 1; |
| 8258 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8259 | |
| 8260 | VkBuffer ib; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8261 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8262 | ASSERT_VK_SUCCESS(err); |
| 8263 | |
| 8264 | BeginCommandBuffer(); |
| 8265 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8266 | // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 8267 | // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8268 | // 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] | 8269 | vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, |
| 8270 | VK_INDEX_TYPE_UINT16); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8271 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8272 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8273 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8274 | vkDestroyBuffer(m_device->device(), ib, NULL); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 8275 | } |
| 8276 | |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 8277 | TEST_F(VkLayerTest, InvalidQueueFamilyIndex) { |
| 8278 | // Create an out-of-range queueFamilyIndex |
| 8279 | m_errorMonitor->SetDesiredFailureMsg( |
| 8280 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Dustin Graves | de62853 | 2016-04-21 16:30:17 -0600 | [diff] [blame] | 8281 | "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one " |
| 8282 | "of the indices specified when the device was created, via the " |
| 8283 | "VkDeviceQueueCreateInfo structure."); |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 8284 | |
| 8285 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8286 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8287 | VkBufferCreateInfo buffCI = {}; |
| 8288 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 8289 | buffCI.size = 1024; |
| 8290 | buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; |
| 8291 | buffCI.queueFamilyIndexCount = 1; |
| 8292 | // Introduce failure by specifying invalid queue_family_index |
| 8293 | uint32_t qfi = 777; |
| 8294 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 24aab04 | 2016-03-24 10:54:18 -0600 | [diff] [blame] | 8295 | buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 8296 | |
| 8297 | VkBuffer ib; |
| 8298 | vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib); |
| 8299 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8300 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 8301 | vkDestroyBuffer(m_device->device(), ib, NULL); |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 8302 | } |
| 8303 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8304 | TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) { |
| 8305 | // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be |
| 8306 | // secondary) |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8307 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8308 | m_errorMonitor->SetDesiredFailureMsg( |
| 8309 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8310 | "vkCmdExecuteCommands() called w/ Primary Cmd Buffer "); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 8311 | |
| 8312 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8313 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 8314 | |
| 8315 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8316 | // ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8317 | VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle(); |
| 8318 | vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 8319 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8320 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 8321 | } |
| 8322 | |
Tobin Ehlis | 17826bd | 2016-05-25 11:12:50 -0600 | [diff] [blame] | 8323 | TEST_F(VkLayerTest, DSUsageBitsErrors) { |
| 8324 | TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers " |
| 8325 | "that do not have correct usage bits sets."); |
| 8326 | VkResult err; |
| 8327 | |
| 8328 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8329 | VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {}; |
| 8330 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 8331 | ds_type_count[i].type = VkDescriptorType(i); |
| 8332 | ds_type_count[i].descriptorCount = 1; |
| 8333 | } |
| 8334 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 8335 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8336 | ds_pool_ci.pNext = NULL; |
| 8337 | ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 8338 | ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 8339 | ds_pool_ci.pPoolSizes = ds_type_count; |
| 8340 | |
| 8341 | VkDescriptorPool ds_pool; |
| 8342 | err = |
| 8343 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 8344 | ASSERT_VK_SUCCESS(err); |
| 8345 | |
| 8346 | // Create 10 layouts where each has a single descriptor of different type |
| 8347 | VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = |
| 8348 | {}; |
| 8349 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 8350 | dsl_binding[i].binding = 0; |
| 8351 | dsl_binding[i].descriptorType = VkDescriptorType(i); |
| 8352 | dsl_binding[i].descriptorCount = 1; |
| 8353 | dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL; |
| 8354 | dsl_binding[i].pImmutableSamplers = NULL; |
| 8355 | } |
| 8356 | |
| 8357 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 8358 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8359 | ds_layout_ci.pNext = NULL; |
| 8360 | ds_layout_ci.bindingCount = 1; |
| 8361 | VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE]; |
| 8362 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 8363 | ds_layout_ci.pBindings = dsl_binding + i; |
| 8364 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, |
| 8365 | NULL, ds_layouts + i); |
| 8366 | ASSERT_VK_SUCCESS(err); |
| 8367 | } |
| 8368 | VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {}; |
| 8369 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 8370 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 8371 | alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 8372 | alloc_info.descriptorPool = ds_pool; |
| 8373 | alloc_info.pSetLayouts = ds_layouts; |
| 8374 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8375 | descriptor_sets); |
| 8376 | ASSERT_VK_SUCCESS(err); |
| 8377 | |
| 8378 | // Create a buffer & bufferView to be used for invalid updates |
| 8379 | VkBufferCreateInfo buff_ci = {}; |
| 8380 | buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 8381 | // This usage is not valid for any descriptor type |
| 8382 | buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; |
| 8383 | buff_ci.size = 256; |
| 8384 | buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 8385 | VkBuffer buffer; |
| 8386 | err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer); |
| 8387 | ASSERT_VK_SUCCESS(err); |
| 8388 | |
| 8389 | VkBufferViewCreateInfo buff_view_ci = {}; |
| 8390 | buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; |
| 8391 | buff_view_ci.buffer = buffer; |
| 8392 | buff_view_ci.format = VK_FORMAT_R8_UNORM; |
| 8393 | buff_view_ci.range = VK_WHOLE_SIZE; |
| 8394 | VkBufferView buff_view; |
| 8395 | err = |
| 8396 | vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view); |
| 8397 | ASSERT_VK_SUCCESS(err); |
| 8398 | |
| 8399 | // Create an image to be used for invalid updates |
| 8400 | VkImageCreateInfo image_ci = {}; |
| 8401 | image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 8402 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 8403 | image_ci.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 8404 | image_ci.extent.width = 64; |
| 8405 | image_ci.extent.height = 64; |
| 8406 | image_ci.extent.depth = 1; |
| 8407 | image_ci.mipLevels = 1; |
| 8408 | image_ci.arrayLayers = 1; |
| 8409 | image_ci.samples = VK_SAMPLE_COUNT_1_BIT; |
| 8410 | image_ci.tiling = VK_IMAGE_TILING_LINEAR; |
| 8411 | image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 8412 | // This usage is not valid for any descriptor type |
| 8413 | image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 8414 | image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 8415 | VkImage image; |
| 8416 | err = vkCreateImage(m_device->device(), &image_ci, NULL, &image); |
| 8417 | ASSERT_VK_SUCCESS(err); |
| 8418 | // Bind memory to image |
| 8419 | VkMemoryRequirements mem_reqs; |
| 8420 | VkDeviceMemory image_mem; |
| 8421 | bool pass; |
| 8422 | VkMemoryAllocateInfo mem_alloc = {}; |
| 8423 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 8424 | mem_alloc.pNext = NULL; |
| 8425 | mem_alloc.allocationSize = 0; |
| 8426 | mem_alloc.memoryTypeIndex = 0; |
| 8427 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 8428 | mem_alloc.allocationSize = mem_reqs.size; |
| 8429 | pass = |
| 8430 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 8431 | ASSERT_TRUE(pass); |
| 8432 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem); |
| 8433 | ASSERT_VK_SUCCESS(err); |
| 8434 | err = vkBindImageMemory(m_device->device(), image, image_mem, 0); |
| 8435 | ASSERT_VK_SUCCESS(err); |
| 8436 | // Now create view for image |
| 8437 | VkImageViewCreateInfo image_view_ci = {}; |
| 8438 | image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 8439 | image_view_ci.image = image; |
| 8440 | image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 8441 | image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 8442 | image_view_ci.subresourceRange.layerCount = 1; |
| 8443 | image_view_ci.subresourceRange.baseArrayLayer = 0; |
| 8444 | image_view_ci.subresourceRange.levelCount = 1; |
| 8445 | image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 8446 | VkImageView image_view; |
| 8447 | err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, |
| 8448 | &image_view); |
| 8449 | ASSERT_VK_SUCCESS(err); |
| 8450 | |
| 8451 | VkDescriptorBufferInfo buff_info = {}; |
| 8452 | buff_info.buffer = buffer; |
| 8453 | VkDescriptorImageInfo img_info = {}; |
| 8454 | img_info.imageView = image_view; |
| 8455 | VkWriteDescriptorSet descriptor_write = {}; |
| 8456 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 8457 | descriptor_write.dstBinding = 0; |
| 8458 | descriptor_write.descriptorCount = 1; |
| 8459 | descriptor_write.pTexelBufferView = &buff_view; |
| 8460 | descriptor_write.pBufferInfo = &buff_info; |
| 8461 | descriptor_write.pImageInfo = &img_info; |
| 8462 | |
| 8463 | // These error messages align with VkDescriptorType struct |
| 8464 | const char *error_msgs[] = { |
| 8465 | "", // placeholder, no error for SAMPLER descriptor |
| 8466 | " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.", |
| 8467 | " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.", |
| 8468 | " does not have VK_IMAGE_USAGE_STORAGE_BIT set.", |
| 8469 | " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.", |
| 8470 | " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.", |
| 8471 | " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.", |
| 8472 | " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.", |
| 8473 | " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.", |
| 8474 | " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.", |
| 8475 | " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."}; |
| 8476 | // Start loop at 1 as SAMPLER desc type has no usage bit error |
| 8477 | for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 8478 | descriptor_write.descriptorType = VkDescriptorType(i); |
| 8479 | descriptor_write.dstSet = descriptor_sets[i]; |
| 8480 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8481 | error_msgs[i]); |
| 8482 | |
| 8483 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, |
| 8484 | NULL); |
| 8485 | |
| 8486 | m_errorMonitor->VerifyFound(); |
| 8487 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL); |
| 8488 | } |
| 8489 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL); |
| 8490 | vkDestroyImage(m_device->device(), image, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 8491 | vkFreeMemory(m_device->device(), image_mem, NULL); |
Tobin Ehlis | 17826bd | 2016-05-25 11:12:50 -0600 | [diff] [blame] | 8492 | vkDestroyImageView(m_device->device(), image_view, NULL); |
| 8493 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 8494 | vkDestroyBufferView(m_device->device(), buff_view, NULL); |
| 8495 | vkFreeDescriptorSets(m_device->device(), ds_pool, |
| 8496 | VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets); |
| 8497 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 8498 | } |
| 8499 | |
Tobin Ehlis | 2fc296b | 2016-06-15 14:05:27 -0600 | [diff] [blame] | 8500 | TEST_F(VkLayerTest, DSAspectBitsErrors) { |
| 8501 | // TODO : Initially only catching case where DEPTH & STENCIL aspect bits |
| 8502 | // are set, but could expand this test to hit more cases. |
| 8503 | TEST_DESCRIPTION("Attempt to update descriptor sets for images " |
| 8504 | "that do not have correct aspect bits sets."); |
| 8505 | VkResult err; |
| 8506 | |
| 8507 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8508 | VkDescriptorPoolSize ds_type_count = {}; |
| 8509 | ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 8510 | ds_type_count.descriptorCount = 1; |
| 8511 | |
| 8512 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 8513 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8514 | ds_pool_ci.pNext = NULL; |
| 8515 | ds_pool_ci.maxSets = 5; |
| 8516 | ds_pool_ci.poolSizeCount = 1; |
| 8517 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 8518 | |
| 8519 | VkDescriptorPool ds_pool; |
| 8520 | err = |
| 8521 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 8522 | ASSERT_VK_SUCCESS(err); |
| 8523 | |
| 8524 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 8525 | dsl_binding.binding = 0; |
| 8526 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 8527 | dsl_binding.descriptorCount = 1; |
| 8528 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8529 | dsl_binding.pImmutableSamplers = NULL; |
| 8530 | |
| 8531 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 8532 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8533 | ds_layout_ci.pNext = NULL; |
| 8534 | ds_layout_ci.bindingCount = 1; |
| 8535 | ds_layout_ci.pBindings = &dsl_binding; |
| 8536 | VkDescriptorSetLayout ds_layout; |
| 8537 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8538 | &ds_layout); |
| 8539 | ASSERT_VK_SUCCESS(err); |
| 8540 | |
| 8541 | VkDescriptorSet descriptor_set = {}; |
| 8542 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 8543 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 8544 | alloc_info.descriptorSetCount = 1; |
| 8545 | alloc_info.descriptorPool = ds_pool; |
| 8546 | alloc_info.pSetLayouts = &ds_layout; |
| 8547 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8548 | &descriptor_set); |
| 8549 | ASSERT_VK_SUCCESS(err); |
| 8550 | |
| 8551 | // Create an image to be used for invalid updates |
| 8552 | VkImageCreateInfo image_ci = {}; |
| 8553 | image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 8554 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 8555 | image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 8556 | image_ci.extent.width = 64; |
| 8557 | image_ci.extent.height = 64; |
| 8558 | image_ci.extent.depth = 1; |
| 8559 | image_ci.mipLevels = 1; |
| 8560 | image_ci.arrayLayers = 1; |
| 8561 | image_ci.samples = VK_SAMPLE_COUNT_1_BIT; |
| 8562 | image_ci.tiling = VK_IMAGE_TILING_LINEAR; |
| 8563 | image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 8564 | image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 8565 | image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 8566 | VkImage image; |
| 8567 | err = vkCreateImage(m_device->device(), &image_ci, NULL, &image); |
| 8568 | ASSERT_VK_SUCCESS(err); |
| 8569 | // Bind memory to image |
| 8570 | VkMemoryRequirements mem_reqs; |
| 8571 | VkDeviceMemory image_mem; |
| 8572 | bool pass; |
| 8573 | VkMemoryAllocateInfo mem_alloc = {}; |
| 8574 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 8575 | mem_alloc.pNext = NULL; |
| 8576 | mem_alloc.allocationSize = 0; |
| 8577 | mem_alloc.memoryTypeIndex = 0; |
| 8578 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 8579 | mem_alloc.allocationSize = mem_reqs.size; |
| 8580 | pass = |
| 8581 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 8582 | ASSERT_TRUE(pass); |
| 8583 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem); |
| 8584 | ASSERT_VK_SUCCESS(err); |
| 8585 | err = vkBindImageMemory(m_device->device(), image, image_mem, 0); |
| 8586 | ASSERT_VK_SUCCESS(err); |
| 8587 | // Now create view for image |
| 8588 | VkImageViewCreateInfo image_view_ci = {}; |
| 8589 | image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 8590 | image_view_ci.image = image; |
| 8591 | image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 8592 | image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 8593 | image_view_ci.subresourceRange.layerCount = 1; |
| 8594 | image_view_ci.subresourceRange.baseArrayLayer = 0; |
| 8595 | image_view_ci.subresourceRange.levelCount = 1; |
| 8596 | // Setting both depth & stencil aspect bits is illegal for descriptor |
| 8597 | image_view_ci.subresourceRange.aspectMask = |
| 8598 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 8599 | |
| 8600 | VkImageView image_view; |
| 8601 | err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, |
| 8602 | &image_view); |
| 8603 | ASSERT_VK_SUCCESS(err); |
| 8604 | |
| 8605 | VkDescriptorImageInfo img_info = {}; |
| 8606 | img_info.imageView = image_view; |
| 8607 | VkWriteDescriptorSet descriptor_write = {}; |
| 8608 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 8609 | descriptor_write.dstBinding = 0; |
| 8610 | descriptor_write.descriptorCount = 1; |
| 8611 | descriptor_write.pTexelBufferView = NULL; |
| 8612 | descriptor_write.pBufferInfo = NULL; |
| 8613 | descriptor_write.pImageInfo = &img_info; |
| 8614 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 8615 | descriptor_write.dstSet = descriptor_set; |
| 8616 | const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT " |
| 8617 | "or VK_IMAGE_ASPECT_STENCIL_BIT "; |
| 8618 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8619 | error_msg); |
| 8620 | |
| 8621 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8622 | |
| 8623 | m_errorMonitor->VerifyFound(); |
| 8624 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8625 | vkDestroyImage(m_device->device(), image, NULL); |
| 8626 | vkFreeMemory(m_device->device(), image_mem, NULL); |
| 8627 | vkDestroyImageView(m_device->device(), image_view, NULL); |
| 8628 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set); |
| 8629 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 8630 | } |
| 8631 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8632 | TEST_F(VkLayerTest, DSTypeMismatch) { |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8633 | // 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] | 8634 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8635 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8636 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8637 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8638 | " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update " |
| 8639 | "type is VK_DESCRIPTOR_TYPE_SAMPLER"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8640 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8641 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8642 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8643 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8644 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8645 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8646 | |
| 8647 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8648 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8649 | ds_pool_ci.pNext = NULL; |
| 8650 | ds_pool_ci.maxSets = 1; |
| 8651 | ds_pool_ci.poolSizeCount = 1; |
| 8652 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8653 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8654 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8655 | err = |
| 8656 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8657 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8658 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8659 | dsl_binding.binding = 0; |
| 8660 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8661 | dsl_binding.descriptorCount = 1; |
| 8662 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8663 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8664 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8665 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8666 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8667 | ds_layout_ci.pNext = NULL; |
| 8668 | ds_layout_ci.bindingCount = 1; |
| 8669 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8670 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8671 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8672 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8673 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8674 | ASSERT_VK_SUCCESS(err); |
| 8675 | |
| 8676 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8677 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8678 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8679 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8680 | alloc_info.descriptorPool = ds_pool; |
| 8681 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8682 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8683 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8684 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8685 | |
Tobin Ehlis | 30db8f8 | 2016-05-05 08:19:48 -0600 | [diff] [blame] | 8686 | VkSamplerCreateInfo sampler_ci = {}; |
| 8687 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8688 | sampler_ci.pNext = NULL; |
| 8689 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8690 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8691 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8692 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8693 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8694 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8695 | sampler_ci.mipLodBias = 1.0; |
| 8696 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8697 | sampler_ci.maxAnisotropy = 1; |
| 8698 | sampler_ci.compareEnable = VK_FALSE; |
| 8699 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8700 | sampler_ci.minLod = 1.0; |
| 8701 | sampler_ci.maxLod = 1.0; |
| 8702 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8703 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
| 8704 | VkSampler sampler; |
| 8705 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
| 8706 | ASSERT_VK_SUCCESS(err); |
| 8707 | |
| 8708 | VkDescriptorImageInfo info = {}; |
| 8709 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8710 | |
| 8711 | VkWriteDescriptorSet descriptor_write; |
| 8712 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8713 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8714 | descriptor_write.dstSet = descriptorSet; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8715 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8716 | // This is a mismatched type for the layout which expects BUFFER |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8717 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8718 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8719 | |
| 8720 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8721 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8722 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8723 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8724 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8725 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8726 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8727 | } |
| 8728 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8729 | TEST_F(VkLayerTest, DSUpdateOutOfBounds) { |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8730 | // For overlapping Update, have arrayIndex exceed that of layout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8731 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8732 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8733 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8734 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8735 | " binding #0 with 1 total descriptors but update of 1 descriptors " |
| 8736 | "starting at binding offset of 0 combined with update array element " |
| 8737 | "offset of 1 oversteps the size of this descriptor set."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8738 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8739 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8740 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8741 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8742 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8743 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8744 | |
| 8745 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8746 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8747 | ds_pool_ci.pNext = NULL; |
| 8748 | ds_pool_ci.maxSets = 1; |
| 8749 | ds_pool_ci.poolSizeCount = 1; |
| 8750 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8751 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8752 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8753 | err = |
| 8754 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8755 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8756 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8757 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8758 | dsl_binding.binding = 0; |
| 8759 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8760 | dsl_binding.descriptorCount = 1; |
| 8761 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8762 | dsl_binding.pImmutableSamplers = NULL; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8763 | |
| 8764 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8765 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8766 | ds_layout_ci.pNext = NULL; |
| 8767 | ds_layout_ci.bindingCount = 1; |
| 8768 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8769 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8770 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8771 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8772 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8773 | ASSERT_VK_SUCCESS(err); |
| 8774 | |
| 8775 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8776 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8777 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8778 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8779 | alloc_info.descriptorPool = ds_pool; |
| 8780 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8781 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8782 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8783 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8784 | |
Tobin Ehlis | 30db8f8 | 2016-05-05 08:19:48 -0600 | [diff] [blame] | 8785 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 8786 | VkDescriptorBufferInfo buff_info = {}; |
| 8787 | buff_info.buffer = |
| 8788 | VkBuffer(0); // Don't care about buffer handle for this test |
| 8789 | buff_info.offset = 0; |
| 8790 | buff_info.range = 1024; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8791 | |
| 8792 | VkWriteDescriptorSet descriptor_write; |
| 8793 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8794 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8795 | descriptor_write.dstSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8796 | descriptor_write.dstArrayElement = |
| 8797 | 1; /* This index out of bounds for the update */ |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8798 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8799 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8800 | descriptor_write.pBufferInfo = &buff_info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8801 | |
| 8802 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8803 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8804 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8805 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8806 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8807 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8808 | } |
| 8809 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8810 | TEST_F(VkLayerTest, InvalidDSUpdateIndex) { |
| 8811 | // Create layout w/ count of 1 and attempt update to that layout w/ binding |
| 8812 | // index 2 |
| 8813 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8814 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8815 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8816 | " does not have binding 2."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8817 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8818 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8819 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8820 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8821 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8822 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8823 | |
| 8824 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8825 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8826 | ds_pool_ci.pNext = NULL; |
| 8827 | ds_pool_ci.maxSets = 1; |
| 8828 | ds_pool_ci.poolSizeCount = 1; |
| 8829 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 8830 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8831 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8832 | err = |
| 8833 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8834 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8835 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8836 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8837 | dsl_binding.binding = 0; |
| 8838 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8839 | dsl_binding.descriptorCount = 1; |
| 8840 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8841 | dsl_binding.pImmutableSamplers = NULL; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8842 | |
| 8843 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8844 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8845 | ds_layout_ci.pNext = NULL; |
| 8846 | ds_layout_ci.bindingCount = 1; |
| 8847 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8848 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8849 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8850 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8851 | ASSERT_VK_SUCCESS(err); |
| 8852 | |
| 8853 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8854 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8855 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8856 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8857 | alloc_info.descriptorPool = ds_pool; |
| 8858 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8859 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8860 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8861 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8862 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8863 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8864 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8865 | sampler_ci.pNext = NULL; |
| 8866 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8867 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8868 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8869 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8870 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8871 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8872 | sampler_ci.mipLodBias = 1.0; |
| 8873 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8874 | sampler_ci.maxAnisotropy = 1; |
| 8875 | sampler_ci.compareEnable = VK_FALSE; |
| 8876 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8877 | sampler_ci.minLod = 1.0; |
| 8878 | sampler_ci.maxLod = 1.0; |
| 8879 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8880 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8881 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8882 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8883 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8884 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8885 | |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8886 | VkDescriptorImageInfo info = {}; |
| 8887 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8888 | |
| 8889 | VkWriteDescriptorSet descriptor_write; |
| 8890 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8891 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8892 | descriptor_write.dstSet = descriptorSet; |
| 8893 | descriptor_write.dstBinding = 2; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8894 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8895 | // 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] | 8896 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8897 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8898 | |
| 8899 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8900 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8901 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8902 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8903 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8904 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8905 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8906 | } |
| 8907 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8908 | TEST_F(VkLayerTest, InvalidDSUpdateStruct) { |
| 8909 | // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* |
| 8910 | // types |
| 8911 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8912 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 8913 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 660bcdc | 2016-05-17 10:39:46 -0600 | [diff] [blame] | 8914 | ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8915 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8916 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 8917 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8918 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8919 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8920 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8921 | |
| 8922 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8923 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8924 | ds_pool_ci.pNext = NULL; |
| 8925 | ds_pool_ci.maxSets = 1; |
| 8926 | ds_pool_ci.poolSizeCount = 1; |
| 8927 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 8928 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8929 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8930 | err = |
| 8931 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8932 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8933 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8934 | dsl_binding.binding = 0; |
| 8935 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8936 | dsl_binding.descriptorCount = 1; |
| 8937 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8938 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8939 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8940 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8941 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8942 | ds_layout_ci.pNext = NULL; |
| 8943 | ds_layout_ci.bindingCount = 1; |
| 8944 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8945 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8946 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8947 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8948 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8949 | ASSERT_VK_SUCCESS(err); |
| 8950 | |
| 8951 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8952 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8953 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8954 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8955 | alloc_info.descriptorPool = ds_pool; |
| 8956 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8957 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8958 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8959 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8960 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8961 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8962 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8963 | sampler_ci.pNext = NULL; |
| 8964 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8965 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8966 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8967 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8968 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8969 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8970 | sampler_ci.mipLodBias = 1.0; |
| 8971 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8972 | sampler_ci.maxAnisotropy = 1; |
| 8973 | sampler_ci.compareEnable = VK_FALSE; |
| 8974 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8975 | sampler_ci.minLod = 1.0; |
| 8976 | sampler_ci.maxLod = 1.0; |
| 8977 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8978 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8979 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8980 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8981 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8982 | |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8983 | VkDescriptorImageInfo info = {}; |
| 8984 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8985 | |
| 8986 | VkWriteDescriptorSet descriptor_write; |
| 8987 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8988 | descriptor_write.sType = |
| 8989 | (VkStructureType)0x99999999; /* Intentionally broken struct type */ |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8990 | descriptor_write.dstSet = descriptorSet; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8991 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8992 | // 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] | 8993 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8994 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8995 | |
| 8996 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8997 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8998 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8999 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9000 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 9001 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9002 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9003 | } |
| 9004 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9005 | TEST_F(VkLayerTest, SampleDescriptorUpdateError) { |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9006 | // Create a single Sampler descriptor and send it an invalid Sampler |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9007 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9008 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9009 | m_errorMonitor->SetDesiredFailureMsg( |
| 9010 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9011 | "Attempted write update to sampler descriptor with invalid sampler"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9012 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9013 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9014 | // TODO : Farm Descriptor setup code to helper function(s) to reduce copied |
| 9015 | // code |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9016 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9017 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 9018 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9019 | |
| 9020 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9021 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9022 | ds_pool_ci.pNext = NULL; |
| 9023 | ds_pool_ci.maxSets = 1; |
| 9024 | ds_pool_ci.poolSizeCount = 1; |
| 9025 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9026 | |
| 9027 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9028 | err = |
| 9029 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9030 | ASSERT_VK_SUCCESS(err); |
| 9031 | |
| 9032 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9033 | dsl_binding.binding = 0; |
| 9034 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 9035 | dsl_binding.descriptorCount = 1; |
| 9036 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9037 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9038 | |
| 9039 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9040 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9041 | ds_layout_ci.pNext = NULL; |
| 9042 | ds_layout_ci.bindingCount = 1; |
| 9043 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9044 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9045 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9046 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9047 | ASSERT_VK_SUCCESS(err); |
| 9048 | |
| 9049 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9050 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9051 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9052 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9053 | alloc_info.descriptorPool = ds_pool; |
| 9054 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9055 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9056 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9057 | ASSERT_VK_SUCCESS(err); |
| 9058 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9059 | VkSampler sampler = |
| 9060 | (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9061 | |
| 9062 | VkDescriptorImageInfo descriptor_info; |
| 9063 | memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo)); |
| 9064 | descriptor_info.sampler = sampler; |
| 9065 | |
| 9066 | VkWriteDescriptorSet descriptor_write; |
| 9067 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 9068 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9069 | descriptor_write.dstSet = descriptorSet; |
| 9070 | descriptor_write.dstBinding = 0; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9071 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9072 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 9073 | descriptor_write.pImageInfo = &descriptor_info; |
| 9074 | |
| 9075 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9076 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9077 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9078 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9079 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9080 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9081 | } |
| 9082 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9083 | TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) { |
| 9084 | // Create a single combined Image/Sampler descriptor and send it an invalid |
| 9085 | // imageView |
| 9086 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9087 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9088 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9089 | "Attempted write update to combined " |
| 9090 | "image sampler descriptor failed due " |
Tobin Ehlis | 63c4b8a | 2016-05-09 10:29:34 -0600 | [diff] [blame] | 9091 | "to: Invalid VkImageView:"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9092 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9093 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9094 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9095 | ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 9096 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9097 | |
| 9098 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9099 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9100 | ds_pool_ci.pNext = NULL; |
| 9101 | ds_pool_ci.maxSets = 1; |
| 9102 | ds_pool_ci.poolSizeCount = 1; |
| 9103 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9104 | |
| 9105 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9106 | err = |
| 9107 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9108 | ASSERT_VK_SUCCESS(err); |
| 9109 | |
| 9110 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9111 | dsl_binding.binding = 0; |
| 9112 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 9113 | dsl_binding.descriptorCount = 1; |
| 9114 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9115 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9116 | |
| 9117 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9118 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9119 | ds_layout_ci.pNext = NULL; |
| 9120 | ds_layout_ci.bindingCount = 1; |
| 9121 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9122 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9123 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9124 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9125 | ASSERT_VK_SUCCESS(err); |
| 9126 | |
| 9127 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9128 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9129 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9130 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9131 | alloc_info.descriptorPool = ds_pool; |
| 9132 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9133 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9134 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9135 | ASSERT_VK_SUCCESS(err); |
| 9136 | |
| 9137 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9138 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 9139 | sampler_ci.pNext = NULL; |
| 9140 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 9141 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 9142 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 9143 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9144 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9145 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9146 | sampler_ci.mipLodBias = 1.0; |
| 9147 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 9148 | sampler_ci.maxAnisotropy = 1; |
| 9149 | sampler_ci.compareEnable = VK_FALSE; |
| 9150 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 9151 | sampler_ci.minLod = 1.0; |
| 9152 | sampler_ci.maxLod = 1.0; |
| 9153 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 9154 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9155 | |
| 9156 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9157 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9158 | ASSERT_VK_SUCCESS(err); |
| 9159 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9160 | VkImageView view = |
| 9161 | (VkImageView)((size_t)0xbaadbeef); // invalid imageView object |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9162 | |
| 9163 | VkDescriptorImageInfo descriptor_info; |
| 9164 | memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo)); |
| 9165 | descriptor_info.sampler = sampler; |
| 9166 | descriptor_info.imageView = view; |
| 9167 | |
| 9168 | VkWriteDescriptorSet descriptor_write; |
| 9169 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 9170 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9171 | descriptor_write.dstSet = descriptorSet; |
| 9172 | descriptor_write.dstBinding = 0; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9173 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9174 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 9175 | descriptor_write.pImageInfo = &descriptor_info; |
| 9176 | |
| 9177 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9178 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9179 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9180 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9181 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 9182 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9183 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 9184 | } |
| 9185 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9186 | TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) { |
| 9187 | // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update |
| 9188 | // into the other |
| 9189 | VkResult err; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9190 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9191 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9192 | " binding #1 with type " |
| 9193 | "VK_DESCRIPTOR_TYPE_SAMPLER. Types do " |
| 9194 | "not match."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9195 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9196 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9197 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9198 | VkDescriptorPoolSize ds_type_count[2] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9199 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9200 | ds_type_count[0].descriptorCount = 1; |
| 9201 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 9202 | ds_type_count[1].descriptorCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9203 | |
| 9204 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9205 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9206 | ds_pool_ci.pNext = NULL; |
| 9207 | ds_pool_ci.maxSets = 1; |
| 9208 | ds_pool_ci.poolSizeCount = 2; |
| 9209 | ds_pool_ci.pPoolSizes = ds_type_count; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9210 | |
| 9211 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9212 | err = |
| 9213 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9214 | ASSERT_VK_SUCCESS(err); |
| 9215 | VkDescriptorSetLayoutBinding dsl_binding[2] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9216 | dsl_binding[0].binding = 0; |
| 9217 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9218 | dsl_binding[0].descriptorCount = 1; |
| 9219 | dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 9220 | dsl_binding[0].pImmutableSamplers = NULL; |
| 9221 | dsl_binding[1].binding = 1; |
| 9222 | dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 9223 | dsl_binding[1].descriptorCount = 1; |
| 9224 | dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL; |
| 9225 | dsl_binding[1].pImmutableSamplers = NULL; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9226 | |
| 9227 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9228 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9229 | ds_layout_ci.pNext = NULL; |
| 9230 | ds_layout_ci.bindingCount = 2; |
| 9231 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9232 | |
| 9233 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9234 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9235 | &ds_layout); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9236 | ASSERT_VK_SUCCESS(err); |
| 9237 | |
| 9238 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9239 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9240 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9241 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9242 | alloc_info.descriptorPool = ds_pool; |
| 9243 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9244 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9245 | &descriptorSet); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9246 | ASSERT_VK_SUCCESS(err); |
| 9247 | |
| 9248 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9249 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 9250 | sampler_ci.pNext = NULL; |
| 9251 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 9252 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 9253 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 9254 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9255 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9256 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 9257 | sampler_ci.mipLodBias = 1.0; |
| 9258 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 9259 | sampler_ci.maxAnisotropy = 1; |
| 9260 | sampler_ci.compareEnable = VK_FALSE; |
| 9261 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 9262 | sampler_ci.minLod = 1.0; |
| 9263 | sampler_ci.maxLod = 1.0; |
| 9264 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 9265 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9266 | |
| 9267 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9268 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9269 | ASSERT_VK_SUCCESS(err); |
| 9270 | |
| 9271 | VkDescriptorImageInfo info = {}; |
| 9272 | info.sampler = sampler; |
| 9273 | |
| 9274 | VkWriteDescriptorSet descriptor_write; |
| 9275 | memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet)); |
| 9276 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9277 | descriptor_write.dstSet = descriptorSet; |
| 9278 | descriptor_write.dstBinding = 1; // SAMPLER binding from layout above |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9279 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9280 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 9281 | descriptor_write.pImageInfo = &info; |
| 9282 | // This write update should succeed |
| 9283 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 9284 | // Now perform a copy update that fails due to type mismatch |
| 9285 | VkCopyDescriptorSet copy_ds_update; |
| 9286 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 9287 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 9288 | copy_ds_update.srcSet = descriptorSet; |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9289 | copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9290 | copy_ds_update.dstSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9291 | copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9292 | copy_ds_update.descriptorCount = 1; // copy 1 descriptor |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9293 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 9294 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9295 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9296 | // 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] | 9297 | m_errorMonitor->SetDesiredFailureMsg( |
| 9298 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9299 | " does not have copy update src binding of 3."); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9300 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 9301 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 9302 | copy_ds_update.srcSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9303 | copy_ds_update.srcBinding = |
| 9304 | 3; // ERROR : Invalid binding for matching layout |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9305 | copy_ds_update.dstSet = descriptorSet; |
| 9306 | copy_ds_update.dstBinding = 0; |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9307 | copy_ds_update.descriptorCount = 1; // Copy 1 descriptor |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9308 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 9309 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9310 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9311 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9312 | // 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] | 9313 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 9314 | VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus " |
| 9315 | "update array offset of 0 and update of " |
| 9316 | "5 descriptors oversteps total number " |
| 9317 | "of descriptors in set: 2."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9318 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9319 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 9320 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 9321 | copy_ds_update.srcSet = descriptorSet; |
| 9322 | copy_ds_update.srcBinding = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9323 | copy_ds_update.dstSet = descriptorSet; |
| 9324 | copy_ds_update.dstBinding = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9325 | copy_ds_update.descriptorCount = |
| 9326 | 5; // ERROR copy 5 descriptors (out of bounds for layout) |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9327 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 9328 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9329 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9330 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9331 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 9332 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9333 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9334 | } |
| 9335 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9336 | TEST_F(VkLayerTest, NumSamplesMismatch) { |
| 9337 | // Create CommandBuffer where MSAA samples doesn't match RenderPass |
| 9338 | // sampleCount |
| 9339 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9340 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9341 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9342 | "Num samples mismatch! "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9343 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9344 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9345 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9346 | VkDescriptorPoolSize ds_type_count = {}; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9347 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9348 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9349 | |
| 9350 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9351 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9352 | ds_pool_ci.pNext = NULL; |
| 9353 | ds_pool_ci.maxSets = 1; |
| 9354 | ds_pool_ci.poolSizeCount = 1; |
| 9355 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 9356 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9357 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9358 | err = |
| 9359 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9360 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9361 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9362 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 9363 | dsl_binding.binding = 0; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9364 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | 0212448 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 9365 | dsl_binding.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9366 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9367 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9368 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9369 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9370 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9371 | ds_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9372 | ds_layout_ci.bindingCount = 1; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 9373 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9374 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9375 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9376 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9377 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9378 | ASSERT_VK_SUCCESS(err); |
| 9379 | |
| 9380 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9381 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9382 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9383 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9384 | alloc_info.descriptorPool = ds_pool; |
| 9385 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9386 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9387 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9388 | ASSERT_VK_SUCCESS(err); |
| 9389 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9390 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9391 | pipe_ms_state_ci.sType = |
| 9392 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9393 | pipe_ms_state_ci.pNext = NULL; |
| 9394 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT; |
| 9395 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9396 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9397 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9398 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9399 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9400 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9401 | pipeline_layout_ci.pNext = NULL; |
| 9402 | pipeline_layout_ci.setLayoutCount = 1; |
| 9403 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9404 | |
| 9405 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9406 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9407 | &pipeline_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9408 | ASSERT_VK_SUCCESS(err); |
| 9409 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9410 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9411 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9412 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9413 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9414 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9415 | // but add it to be able to run on more devices |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9416 | VkPipelineObj pipe(m_device); |
| 9417 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 9418 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9419 | pipe.AddColorAttachment(); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9420 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 9421 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9422 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 9423 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9424 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9425 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9426 | |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9427 | // Render triangle (the error should trigger on the attempt to draw). |
| 9428 | Draw(3, 1, 0, 0); |
| 9429 | |
| 9430 | // Finalize recording of the command buffer |
| 9431 | EndCommandBuffer(); |
| 9432 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9433 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9434 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9435 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9436 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9437 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9438 | } |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9439 | |
Tobin Ehlis | 85aa15a | 2016-06-15 10:52:37 -0600 | [diff] [blame] | 9440 | TEST_F(VkLayerTest, RenderPassIncompatible) { |
| 9441 | TEST_DESCRIPTION("Hit RenderPass incompatible cases. " |
| 9442 | "Initial case is drawing with an active renderpass that's " |
| 9443 | "not compatible with the bound PSO's creation renderpass"); |
| 9444 | VkResult err; |
| 9445 | |
| 9446 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9447 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9448 | |
| 9449 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 9450 | dsl_binding.binding = 0; |
| 9451 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9452 | dsl_binding.descriptorCount = 1; |
| 9453 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9454 | dsl_binding.pImmutableSamplers = NULL; |
| 9455 | |
| 9456 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9457 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9458 | ds_layout_ci.pNext = NULL; |
| 9459 | ds_layout_ci.bindingCount = 1; |
| 9460 | ds_layout_ci.pBindings = &dsl_binding; |
| 9461 | |
| 9462 | VkDescriptorSetLayout ds_layout; |
| 9463 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9464 | &ds_layout); |
| 9465 | ASSERT_VK_SUCCESS(err); |
| 9466 | |
| 9467 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 9468 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9469 | pipeline_layout_ci.pNext = NULL; |
| 9470 | pipeline_layout_ci.setLayoutCount = 1; |
| 9471 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 9472 | |
| 9473 | VkPipelineLayout pipeline_layout; |
| 9474 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9475 | &pipeline_layout); |
| 9476 | ASSERT_VK_SUCCESS(err); |
| 9477 | |
| 9478 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9479 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9480 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9481 | VK_SHADER_STAGE_FRAGMENT_BIT, |
| 9482 | this); // We shouldn't need a fragment shader |
| 9483 | // but add it to be able to run on more devices |
| 9484 | // Create a renderpass that will be incompatible with default renderpass |
| 9485 | VkAttachmentReference attach = {}; |
| 9486 | attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 9487 | VkAttachmentReference color_att = {}; |
| 9488 | color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 9489 | VkSubpassDescription subpass = {}; |
| 9490 | subpass.inputAttachmentCount = 1; |
| 9491 | subpass.pInputAttachments = &attach; |
| 9492 | subpass.colorAttachmentCount = 1; |
| 9493 | subpass.pColorAttachments = &color_att; |
| 9494 | VkRenderPassCreateInfo rpci = {}; |
| 9495 | rpci.subpassCount = 1; |
| 9496 | rpci.pSubpasses = &subpass; |
| 9497 | rpci.attachmentCount = 1; |
| 9498 | VkAttachmentDescription attach_desc = {}; |
| 9499 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
Cody Northrop | bd16af1 | 2016-06-21 09:25:48 -0600 | [diff] [blame] | 9500 | // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM |
| 9501 | attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM; |
Tobin Ehlis | 85aa15a | 2016-06-15 10:52:37 -0600 | [diff] [blame] | 9502 | rpci.pAttachments = &attach_desc; |
| 9503 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 9504 | VkRenderPass rp; |
| 9505 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9506 | VkPipelineObj pipe(m_device); |
| 9507 | pipe.AddShader(&vs); |
| 9508 | pipe.AddShader(&fs); |
| 9509 | pipe.AddColorAttachment(); |
| 9510 | VkViewport view_port = {}; |
| 9511 | m_viewports.push_back(view_port); |
| 9512 | pipe.SetViewport(m_viewports); |
| 9513 | VkRect2D rect = {}; |
| 9514 | m_scissors.push_back(rect); |
| 9515 | pipe.SetScissor(m_scissors); |
| 9516 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 9517 | |
| 9518 | VkCommandBufferInheritanceInfo cbii = {}; |
| 9519 | cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; |
| 9520 | cbii.renderPass = rp; |
| 9521 | cbii.subpass = 0; |
| 9522 | VkCommandBufferBeginInfo cbbi = {}; |
| 9523 | cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 9524 | cbbi.pInheritanceInfo = &cbii; |
| 9525 | vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi); |
| 9526 | VkRenderPassBeginInfo rpbi = {}; |
| 9527 | rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 9528 | rpbi.framebuffer = m_framebuffer; |
| 9529 | rpbi.renderPass = rp; |
| 9530 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, |
| 9531 | VK_SUBPASS_CONTENTS_INLINE); |
| 9532 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9533 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 9534 | |
| 9535 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9536 | " is incompatible w/ gfx pipeline "); |
| 9537 | // Render triangle (the error should trigger on the attempt to draw). |
| 9538 | Draw(3, 1, 0, 0); |
| 9539 | |
| 9540 | // Finalize recording of the command buffer |
| 9541 | EndCommandBuffer(); |
| 9542 | |
| 9543 | m_errorMonitor->VerifyFound(); |
| 9544 | |
| 9545 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9546 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9547 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 9548 | } |
| 9549 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9550 | TEST_F(VkLayerTest, NumBlendAttachMismatch) { |
| 9551 | // Create Pipeline where the number of blend attachments doesn't match the |
| 9552 | // number of color attachments. In this case, we don't add any color |
| 9553 | // blend attachments even though we have a color attachment. |
| 9554 | VkResult err; |
| 9555 | |
| 9556 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9557 | "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] | 9558 | |
| 9559 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9560 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9561 | VkDescriptorPoolSize ds_type_count = {}; |
| 9562 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9563 | ds_type_count.descriptorCount = 1; |
| 9564 | |
| 9565 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 9566 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9567 | ds_pool_ci.pNext = NULL; |
| 9568 | ds_pool_ci.maxSets = 1; |
| 9569 | ds_pool_ci.poolSizeCount = 1; |
| 9570 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 9571 | |
| 9572 | VkDescriptorPool ds_pool; |
| 9573 | err = |
| 9574 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 9575 | ASSERT_VK_SUCCESS(err); |
| 9576 | |
| 9577 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 9578 | dsl_binding.binding = 0; |
| 9579 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9580 | dsl_binding.descriptorCount = 1; |
| 9581 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9582 | dsl_binding.pImmutableSamplers = NULL; |
| 9583 | |
| 9584 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9585 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9586 | ds_layout_ci.pNext = NULL; |
| 9587 | ds_layout_ci.bindingCount = 1; |
| 9588 | ds_layout_ci.pBindings = &dsl_binding; |
| 9589 | |
| 9590 | VkDescriptorSetLayout ds_layout; |
| 9591 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9592 | &ds_layout); |
| 9593 | ASSERT_VK_SUCCESS(err); |
| 9594 | |
| 9595 | VkDescriptorSet descriptorSet; |
| 9596 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 9597 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 9598 | alloc_info.descriptorSetCount = 1; |
| 9599 | alloc_info.descriptorPool = ds_pool; |
| 9600 | alloc_info.pSetLayouts = &ds_layout; |
| 9601 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9602 | &descriptorSet); |
| 9603 | ASSERT_VK_SUCCESS(err); |
| 9604 | |
| 9605 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
| 9606 | pipe_ms_state_ci.sType = |
| 9607 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9608 | pipe_ms_state_ci.pNext = NULL; |
| 9609 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; |
| 9610 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9611 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9612 | pipe_ms_state_ci.pSampleMask = NULL; |
| 9613 | |
| 9614 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 9615 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9616 | pipeline_layout_ci.pNext = NULL; |
| 9617 | pipeline_layout_ci.setLayoutCount = 1; |
| 9618 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 9619 | |
| 9620 | VkPipelineLayout pipeline_layout; |
| 9621 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9622 | &pipeline_layout); |
| 9623 | ASSERT_VK_SUCCESS(err); |
| 9624 | |
| 9625 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9626 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9627 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9628 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9629 | this); // We shouldn't need a fragment shader |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9630 | // but add it to be able to run on more devices |
| 9631 | VkPipelineObj pipe(m_device); |
| 9632 | pipe.AddShader(&vs); |
| 9633 | pipe.AddShader(&fs); |
| 9634 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 9635 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 9636 | |
| 9637 | BeginCommandBuffer(); |
| 9638 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9639 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 9640 | |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9641 | // Render triangle (the error should trigger on the attempt to draw). |
| 9642 | Draw(3, 1, 0, 0); |
| 9643 | |
| 9644 | // Finalize recording of the command buffer |
| 9645 | EndCommandBuffer(); |
| 9646 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9647 | m_errorMonitor->VerifyFound(); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9648 | |
| 9649 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9650 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9651 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 9652 | } |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9653 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 9654 | TEST_F(VkLayerTest, MissingClearAttachment) { |
| 9655 | TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment " |
| 9656 | "structure passed to vkCmdClearAttachments"); |
| 9657 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9658 | "vkCmdClearAttachments() attachment index 1 not found in attachment " |
| 9659 | "reference array of active subpass 0"); |
| 9660 | |
| 9661 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments); |
| 9662 | m_errorMonitor->VerifyFound(); |
| 9663 | } |
| 9664 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9665 | TEST_F(VkLayerTest, ClearCmdNoDraw) { |
| 9666 | // Create CommandBuffer where we add ClearCmd for FB Color attachment prior |
| 9667 | // to issuing a Draw |
| 9668 | VkResult err; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9669 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9670 | m_errorMonitor->SetDesiredFailureMsg( |
Tony Barbour | 7e56d30 | 2016-03-02 15:12:01 -0700 | [diff] [blame] | 9671 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9672 | "vkCmdClearAttachments() issued on CB object "); |
| 9673 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9674 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9675 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9676 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9677 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9678 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9679 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9680 | |
| 9681 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9682 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9683 | ds_pool_ci.pNext = NULL; |
| 9684 | ds_pool_ci.maxSets = 1; |
| 9685 | ds_pool_ci.poolSizeCount = 1; |
| 9686 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9687 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9688 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9689 | err = |
| 9690 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9691 | ASSERT_VK_SUCCESS(err); |
| 9692 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9693 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9694 | dsl_binding.binding = 0; |
| 9695 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9696 | dsl_binding.descriptorCount = 1; |
| 9697 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9698 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9699 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9700 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9701 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9702 | ds_layout_ci.pNext = NULL; |
| 9703 | ds_layout_ci.bindingCount = 1; |
| 9704 | ds_layout_ci.pBindings = &dsl_binding; |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9705 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9706 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9707 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9708 | &ds_layout); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9709 | ASSERT_VK_SUCCESS(err); |
| 9710 | |
| 9711 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9712 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9713 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9714 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9715 | alloc_info.descriptorPool = ds_pool; |
| 9716 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9717 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9718 | &descriptorSet); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9719 | ASSERT_VK_SUCCESS(err); |
| 9720 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9721 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9722 | pipe_ms_state_ci.sType = |
| 9723 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9724 | pipe_ms_state_ci.pNext = NULL; |
| 9725 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT; |
| 9726 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9727 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9728 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9729 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9730 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9731 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9732 | pipeline_layout_ci.pNext = NULL; |
| 9733 | pipeline_layout_ci.setLayoutCount = 1; |
| 9734 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9735 | |
| 9736 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9737 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9738 | &pipeline_layout); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9739 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9740 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9741 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9742 | VK_SHADER_STAGE_VERTEX_BIT, this); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9743 | // 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] | 9744 | // on more devices |
| 9745 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9746 | VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9747 | |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9748 | VkPipelineObj pipe(m_device); |
| 9749 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 9750 | pipe.AddShader(&fs); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9751 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 9752 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 9753 | |
| 9754 | BeginCommandBuffer(); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9755 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9756 | // Main thing we care about for this test is that the VkImage obj we're |
| 9757 | // clearing matches Color Attachment of FB |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9758 | // Also pass down other dummy params to keep driver and paramchecker happy |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 9759 | VkClearAttachment color_attachment; |
| 9760 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9761 | color_attachment.clearValue.color.float32[0] = 1.0; |
| 9762 | color_attachment.clearValue.color.float32[1] = 1.0; |
| 9763 | color_attachment.clearValue.color.float32[2] = 1.0; |
| 9764 | color_attachment.clearValue.color.float32[3] = 1.0; |
| 9765 | color_attachment.colorAttachment = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9766 | VkClearRect clear_rect = { |
| 9767 | {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}}; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9768 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9769 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 9770 | &color_attachment, 1, &clear_rect); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9771 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9772 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9773 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9774 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9775 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9776 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9777 | } |
| 9778 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9779 | TEST_F(VkLayerTest, VtxBufferBadIndex) { |
| 9780 | VkResult err; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9781 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9782 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 9783 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | dfcd9b6 | 2015-12-14 15:14:10 -0700 | [diff] [blame] | 9784 | "but no vertex buffers are attached to this Pipeline State Object"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9785 | |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9786 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 9787 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9788 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9789 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9790 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9791 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9792 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9793 | |
| 9794 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9795 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9796 | ds_pool_ci.pNext = NULL; |
| 9797 | ds_pool_ci.maxSets = 1; |
| 9798 | ds_pool_ci.poolSizeCount = 1; |
| 9799 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9800 | |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 9801 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9802 | err = |
| 9803 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9804 | ASSERT_VK_SUCCESS(err); |
| 9805 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9806 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9807 | dsl_binding.binding = 0; |
| 9808 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9809 | dsl_binding.descriptorCount = 1; |
| 9810 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9811 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9812 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9813 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9814 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9815 | ds_layout_ci.pNext = NULL; |
| 9816 | ds_layout_ci.bindingCount = 1; |
| 9817 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9818 | |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9819 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9820 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9821 | &ds_layout); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9822 | ASSERT_VK_SUCCESS(err); |
| 9823 | |
| 9824 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9825 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9826 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9827 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9828 | alloc_info.descriptorPool = ds_pool; |
| 9829 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9830 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9831 | &descriptorSet); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9832 | ASSERT_VK_SUCCESS(err); |
| 9833 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9834 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9835 | pipe_ms_state_ci.sType = |
| 9836 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9837 | pipe_ms_state_ci.pNext = NULL; |
| 9838 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; |
| 9839 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9840 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9841 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9842 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9843 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9844 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9845 | pipeline_layout_ci.pNext = NULL; |
| 9846 | pipeline_layout_ci.setLayoutCount = 1; |
| 9847 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 9848 | VkPipelineLayout pipeline_layout; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9849 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9850 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9851 | &pipeline_layout); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9852 | ASSERT_VK_SUCCESS(err); |
| 9853 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9854 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9855 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9856 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9857 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9858 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9859 | // but add it to be able to run on more devices |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9860 | VkPipelineObj pipe(m_device); |
| 9861 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 9862 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9863 | pipe.AddColorAttachment(); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9864 | pipe.SetMSAA(&pipe_ms_state_ci); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 9865 | pipe.SetViewport(m_viewports); |
| 9866 | pipe.SetScissor(m_scissors); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9867 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 9868 | |
| 9869 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9870 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9871 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | f7bf450 | 2015-09-09 15:12:35 -0600 | [diff] [blame] | 9872 | // Don't care about actual data, just need to get to draw to flag error |
| 9873 | static const float vbo_data[3] = {1.f, 0.f, 1.f}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9874 | VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), |
| 9875 | (const void *)&vbo_data); |
Tobin Ehlis | f7bf450 | 2015-09-09 15:12:35 -0600 | [diff] [blame] | 9876 | 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] | 9877 | Draw(1, 0, 0, 0); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9878 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9879 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9880 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9881 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9882 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9883 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9884 | } |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 9885 | // INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here) |
| 9886 | TEST_F(VkLayerTest, InvalidImageLayout) { |
| 9887 | TEST_DESCRIPTION("Hit all possible validation checks associated with the " |
| 9888 | "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having" |
| 9889 | "images in the wrong layout when they're copied or transitioned."); |
| 9890 | // 3 in ValidateCmdBufImageLayouts |
| 9891 | // * -1 Attempt to submit cmd buf w/ deleted image |
| 9892 | // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource |
| 9893 | // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource |
| 9894 | m_errorMonitor->SetDesiredFailureMsg( |
| 9895 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9896 | "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL."); |
| 9897 | |
| 9898 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9899 | // Create src & dst images to use for copy operations |
| 9900 | VkImage src_image; |
| 9901 | VkImage dst_image; |
| 9902 | |
| 9903 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 9904 | const int32_t tex_width = 32; |
| 9905 | const int32_t tex_height = 32; |
| 9906 | |
| 9907 | VkImageCreateInfo image_create_info = {}; |
| 9908 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 9909 | image_create_info.pNext = NULL; |
| 9910 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 9911 | image_create_info.format = tex_format; |
| 9912 | image_create_info.extent.width = tex_width; |
| 9913 | image_create_info.extent.height = tex_height; |
| 9914 | image_create_info.extent.depth = 1; |
| 9915 | image_create_info.mipLevels = 1; |
| 9916 | image_create_info.arrayLayers = 4; |
| 9917 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 9918 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 9919 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 9920 | image_create_info.flags = 0; |
| 9921 | |
| 9922 | VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image); |
| 9923 | ASSERT_VK_SUCCESS(err); |
| 9924 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image); |
| 9925 | ASSERT_VK_SUCCESS(err); |
| 9926 | |
| 9927 | BeginCommandBuffer(); |
| 9928 | VkImageCopy copyRegion; |
| 9929 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9930 | copyRegion.srcSubresource.mipLevel = 0; |
| 9931 | copyRegion.srcSubresource.baseArrayLayer = 0; |
| 9932 | copyRegion.srcSubresource.layerCount = 1; |
| 9933 | copyRegion.srcOffset.x = 0; |
| 9934 | copyRegion.srcOffset.y = 0; |
| 9935 | copyRegion.srcOffset.z = 0; |
| 9936 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9937 | copyRegion.dstSubresource.mipLevel = 0; |
| 9938 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 9939 | copyRegion.dstSubresource.layerCount = 1; |
| 9940 | copyRegion.dstOffset.x = 0; |
| 9941 | copyRegion.dstOffset.y = 0; |
| 9942 | copyRegion.dstOffset.z = 0; |
| 9943 | copyRegion.extent.width = 1; |
| 9944 | copyRegion.extent.height = 1; |
| 9945 | copyRegion.extent.depth = 1; |
| 9946 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9947 | m_errorMonitor->VerifyFound(); |
| 9948 | // Now cause error due to src image layout changing |
| 9949 | m_errorMonitor->SetDesiredFailureMsg( |
| 9950 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9951 | "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL."); |
| 9952 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9953 | m_errorMonitor->VerifyFound(); |
| 9954 | // Final src error is due to bad layout type |
| 9955 | m_errorMonitor->SetDesiredFailureMsg( |
| 9956 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9957 | "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL."); |
| 9958 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9959 | m_errorMonitor->VerifyFound(); |
| 9960 | // Now verify same checks for dst |
| 9961 | m_errorMonitor->SetDesiredFailureMsg( |
| 9962 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9963 | "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL."); |
| 9964 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9965 | m_errorMonitor->VerifyFound(); |
| 9966 | // Now cause error due to src image layout changing |
| 9967 | m_errorMonitor->SetDesiredFailureMsg( |
| 9968 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9969 | "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL."); |
| 9970 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, ©Region); |
| 9971 | m_errorMonitor->VerifyFound(); |
| 9972 | m_errorMonitor->SetDesiredFailureMsg( |
| 9973 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9974 | "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL."); |
| 9975 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, ©Region); |
| 9976 | m_errorMonitor->VerifyFound(); |
| 9977 | // Now cause error due to bad image layout transition in PipelineBarrier |
| 9978 | VkImageMemoryBarrier image_barrier[1] = {}; |
| 9979 | image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 9980 | image_barrier[0].image = src_image; |
| 9981 | image_barrier[0].subresourceRange.layerCount = 2; |
| 9982 | image_barrier[0].subresourceRange.levelCount = 2; |
| 9983 | image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9984 | m_errorMonitor->SetDesiredFailureMsg( |
| 9985 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9986 | "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL."); |
| 9987 | vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier); |
| 9988 | m_errorMonitor->VerifyFound(); |
| 9989 | |
| 9990 | // Finally some layout errors at RenderPass create time |
| 9991 | // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing. |
| 9992 | VkAttachmentReference attach = {}; |
| 9993 | // perf warning for GENERAL layout w/ non-DS input attachment |
| 9994 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 9995 | VkSubpassDescription subpass = {}; |
| 9996 | subpass.inputAttachmentCount = 1; |
| 9997 | subpass.pInputAttachments = &attach; |
| 9998 | VkRenderPassCreateInfo rpci = {}; |
| 9999 | rpci.subpassCount = 1; |
| 10000 | rpci.pSubpasses = &subpass; |
| 10001 | rpci.attachmentCount = 1; |
| 10002 | VkAttachmentDescription attach_desc = {}; |
| 10003 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 10004 | rpci.pAttachments = &attach_desc; |
Tobin Ehlis | 1efce02 | 2016-05-11 10:40:34 -0600 | [diff] [blame] | 10005 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 10006 | VkRenderPass rp; |
| 10007 | m_errorMonitor->SetDesiredFailureMsg( |
| 10008 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 10009 | "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL."); |
| 10010 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 10011 | m_errorMonitor->VerifyFound(); |
| 10012 | // error w/ non-general layout |
| 10013 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 10014 | |
| 10015 | m_errorMonitor->SetDesiredFailureMsg( |
| 10016 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10017 | "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL."); |
| 10018 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 10019 | m_errorMonitor->VerifyFound(); |
| 10020 | subpass.inputAttachmentCount = 0; |
| 10021 | subpass.colorAttachmentCount = 1; |
| 10022 | subpass.pColorAttachments = &attach; |
| 10023 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 10024 | // perf warning for GENERAL layout on color attachment |
| 10025 | m_errorMonitor->SetDesiredFailureMsg( |
| 10026 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 10027 | "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL."); |
| 10028 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 10029 | m_errorMonitor->VerifyFound(); |
| 10030 | // error w/ non-color opt or GENERAL layout for color attachment |
| 10031 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 10032 | m_errorMonitor->SetDesiredFailureMsg( |
| 10033 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10034 | "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL."); |
| 10035 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 10036 | m_errorMonitor->VerifyFound(); |
| 10037 | subpass.colorAttachmentCount = 0; |
| 10038 | subpass.pDepthStencilAttachment = &attach; |
| 10039 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 10040 | // perf warning for GENERAL layout on DS attachment |
| 10041 | m_errorMonitor->SetDesiredFailureMsg( |
| 10042 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 10043 | "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL."); |
| 10044 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 10045 | m_errorMonitor->VerifyFound(); |
| 10046 | // error w/ non-ds opt or GENERAL layout for color attachment |
| 10047 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 10048 | m_errorMonitor->SetDesiredFailureMsg( |
| 10049 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10050 | "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL."); |
| 10051 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 10052 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 1efce02 | 2016-05-11 10:40:34 -0600 | [diff] [blame] | 10053 | // For this error we need a valid renderpass so create default one |
| 10054 | attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 10055 | attach.attachment = 0; |
| 10056 | attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 10057 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
| 10058 | attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE; |
| 10059 | attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 10060 | attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 10061 | // Can't do a CLEAR load on READ_ONLY initialLayout |
| 10062 | attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 10063 | attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 10064 | attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 10065 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10066 | " with invalid first layout " |
| 10067 | "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_" |
| 10068 | "ONLY_OPTIMAL"); |
| 10069 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 10070 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 10071 | |
| 10072 | vkDestroyImage(m_device->device(), src_image, NULL); |
| 10073 | vkDestroyImage(m_device->device(), dst_image, NULL); |
| 10074 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 10075 | #endif // DRAW_STATE_TESTS |
| 10076 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 10077 | #if THREADING_TESTS |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10078 | #if GTEST_IS_THREADSAFE |
| 10079 | struct thread_data_struct { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10080 | VkCommandBuffer commandBuffer; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10081 | VkEvent event; |
| 10082 | bool bailout; |
| 10083 | }; |
| 10084 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10085 | extern "C" void *AddToCommandBuffer(void *arg) { |
| 10086 | struct thread_data_struct *data = (struct thread_data_struct *)arg; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10087 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10088 | for (int i = 0; i < 10000; i++) { |
| 10089 | vkCmdSetEvent(data->commandBuffer, data->event, |
| 10090 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10091 | if (data->bailout) { |
| 10092 | break; |
| 10093 | } |
| 10094 | } |
| 10095 | return NULL; |
| 10096 | } |
| 10097 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10098 | TEST_F(VkLayerTest, ThreadCommandBufferCollision) { |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 10099 | test_platform_thread thread; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10100 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10101 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10102 | "THREADING ERROR"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10103 | |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10104 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10105 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 10106 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10107 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10108 | // Calls AllocateCommandBuffers |
| 10109 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
Mark Lobodzinski | 5495d13 | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 10110 | |
| 10111 | // Avoid creating RenderPass |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10112 | commandBuffer.BeginCommandBuffer(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10113 | |
| 10114 | VkEventCreateInfo event_info; |
| 10115 | VkEvent event; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10116 | VkResult err; |
| 10117 | |
| 10118 | memset(&event_info, 0, sizeof(event_info)); |
| 10119 | event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 10120 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10121 | err = vkCreateEvent(device(), &event_info, NULL, &event); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10122 | ASSERT_VK_SUCCESS(err); |
| 10123 | |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10124 | err = vkResetEvent(device(), event); |
| 10125 | ASSERT_VK_SUCCESS(err); |
| 10126 | |
| 10127 | struct thread_data_struct data; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10128 | data.commandBuffer = commandBuffer.GetBufferHandle(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10129 | data.event = event; |
| 10130 | data.bailout = false; |
| 10131 | m_errorMonitor->SetBailout(&data.bailout); |
| 10132 | // Add many entries to command buffer from another thread. |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 10133 | test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10134 | // Add many entries to command buffer from this thread at the same time. |
| 10135 | AddToCommandBuffer(&data); |
Mark Lobodzinski | 5495d13 | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 10136 | |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 10137 | test_platform_thread_join(thread, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10138 | commandBuffer.EndCommandBuffer(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10139 | |
Mike Stroyan | 10b8cb7 | 2016-01-22 15:22:03 -0700 | [diff] [blame] | 10140 | m_errorMonitor->SetBailout(NULL); |
| 10141 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10142 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10143 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10144 | vkDestroyEvent(device(), event, NULL); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 10145 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 10146 | #endif // GTEST_IS_THREADSAFE |
| 10147 | #endif // THREADING_TESTS |
| 10148 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10149 | #if SHADER_CHECKER_TESTS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10150 | TEST_F(VkLayerTest, InvalidSPIRVCodeSize) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10151 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 10152 | "Invalid SPIR-V header"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10153 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10154 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10155 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10156 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10157 | VkShaderModule module; |
| 10158 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 10159 | struct icd_spv_header spv; |
| 10160 | |
| 10161 | spv.magic = ICD_SPV_MAGIC; |
| 10162 | spv.version = ICD_SPV_VERSION; |
| 10163 | spv.gen_magic = 0; |
| 10164 | |
| 10165 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 10166 | moduleCreateInfo.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10167 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10168 | moduleCreateInfo.codeSize = 4; |
| 10169 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10170 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10171 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10172 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10173 | } |
| 10174 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10175 | TEST_F(VkLayerTest, InvalidSPIRVMagic) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10176 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 10177 | "Invalid SPIR-V magic number"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10178 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10179 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10180 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10181 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10182 | VkShaderModule module; |
| 10183 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 10184 | struct icd_spv_header spv; |
| 10185 | |
| 10186 | spv.magic = ~ICD_SPV_MAGIC; |
| 10187 | spv.version = ICD_SPV_VERSION; |
| 10188 | spv.gen_magic = 0; |
| 10189 | |
| 10190 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 10191 | moduleCreateInfo.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10192 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10193 | moduleCreateInfo.codeSize = sizeof(spv) + 10; |
| 10194 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10195 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10196 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10197 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10198 | } |
| 10199 | |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 10200 | #if 0 |
| 10201 | // Not currently covered by SPIRV-Tools validator |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10202 | TEST_F(VkLayerTest, InvalidSPIRVVersion) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10203 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 10204 | "Invalid SPIR-V header"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10205 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10206 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10207 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10208 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10209 | VkShaderModule module; |
| 10210 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 10211 | struct icd_spv_header spv; |
| 10212 | |
| 10213 | spv.magic = ICD_SPV_MAGIC; |
| 10214 | spv.version = ~ICD_SPV_VERSION; |
| 10215 | spv.gen_magic = 0; |
| 10216 | |
| 10217 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 10218 | moduleCreateInfo.pNext = NULL; |
| 10219 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10220 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10221 | moduleCreateInfo.codeSize = sizeof(spv) + 10; |
| 10222 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10223 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10224 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10225 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10226 | } |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 10227 | #endif |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 10228 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10229 | TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 10230 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10231 | "not consumed by fragment shader"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10232 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10233 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10234 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10235 | |
| 10236 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10237 | "#version 450\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10238 | "\n" |
| 10239 | "layout(location=0) out float x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10240 | "out gl_PerVertex {\n" |
| 10241 | " vec4 gl_Position;\n" |
| 10242 | "};\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10243 | "void main(){\n" |
| 10244 | " gl_Position = vec4(1);\n" |
| 10245 | " x = 0;\n" |
| 10246 | "}\n"; |
| 10247 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10248 | "#version 450\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10249 | "\n" |
| 10250 | "layout(location=0) out vec4 color;\n" |
| 10251 | "void main(){\n" |
| 10252 | " color = vec4(1);\n" |
| 10253 | "}\n"; |
| 10254 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10255 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10256 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10257 | |
| 10258 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10259 | pipe.AddColorAttachment(); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10260 | pipe.AddShader(&vs); |
| 10261 | pipe.AddShader(&fs); |
| 10262 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10263 | VkDescriptorSetObj descriptorSet(m_device); |
| 10264 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10265 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10266 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10267 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10268 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10269 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10270 | } |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 10271 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10272 | TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10273 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10274 | "not written by vertex shader"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10275 | |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10276 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10277 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10278 | |
| 10279 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10280 | "#version 450\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10281 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10282 | "out gl_PerVertex {\n" |
| 10283 | " vec4 gl_Position;\n" |
| 10284 | "};\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10285 | "void main(){\n" |
| 10286 | " gl_Position = vec4(1);\n" |
| 10287 | "}\n"; |
| 10288 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10289 | "#version 450\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10290 | "\n" |
| 10291 | "layout(location=0) in float x;\n" |
| 10292 | "layout(location=0) out vec4 color;\n" |
| 10293 | "void main(){\n" |
| 10294 | " color = vec4(x);\n" |
| 10295 | "}\n"; |
| 10296 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10297 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10298 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10299 | |
| 10300 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10301 | pipe.AddColorAttachment(); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10302 | pipe.AddShader(&vs); |
| 10303 | pipe.AddShader(&fs); |
| 10304 | |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10305 | VkDescriptorSetObj descriptorSet(m_device); |
| 10306 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10307 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10308 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10309 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10310 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10311 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 10312 | } |
| 10313 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10314 | TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) { |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10315 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10316 | "not written by vertex shader"); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10317 | |
| 10318 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10319 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10320 | |
| 10321 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10322 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10323 | "\n" |
| 10324 | "out gl_PerVertex {\n" |
| 10325 | " vec4 gl_Position;\n" |
| 10326 | "};\n" |
| 10327 | "void main(){\n" |
| 10328 | " gl_Position = vec4(1);\n" |
| 10329 | "}\n"; |
| 10330 | char const *fsSource = |
| 10331 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10332 | "\n" |
| 10333 | "in block { layout(location=0) float x; } ins;\n" |
| 10334 | "layout(location=0) out vec4 color;\n" |
| 10335 | "void main(){\n" |
| 10336 | " color = vec4(ins.x);\n" |
| 10337 | "}\n"; |
| 10338 | |
| 10339 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10340 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10341 | |
| 10342 | VkPipelineObj pipe(m_device); |
| 10343 | pipe.AddColorAttachment(); |
| 10344 | pipe.AddShader(&vs); |
| 10345 | pipe.AddShader(&fs); |
| 10346 | |
| 10347 | VkDescriptorSetObj descriptorSet(m_device); |
| 10348 | descriptorSet.AppendDummy(); |
| 10349 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10350 | |
| 10351 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10352 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10353 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10354 | } |
| 10355 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10356 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) { |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10357 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10358 | "Type mismatch on location 0.0: 'ptr to " |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10359 | "output arr[2] of float32' vs 'ptr to " |
| 10360 | "input arr[3] of float32'"); |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10361 | |
| 10362 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10363 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10364 | |
| 10365 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10366 | "#version 450\n" |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10367 | "\n" |
| 10368 | "layout(location=0) out float x[2];\n" |
| 10369 | "out gl_PerVertex {\n" |
| 10370 | " vec4 gl_Position;\n" |
| 10371 | "};\n" |
| 10372 | "void main(){\n" |
| 10373 | " x[0] = 0; x[1] = 0;\n" |
| 10374 | " gl_Position = vec4(1);\n" |
| 10375 | "}\n"; |
| 10376 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10377 | "#version 450\n" |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10378 | "\n" |
| 10379 | "layout(location=0) in float x[3];\n" |
| 10380 | "layout(location=0) out vec4 color;\n" |
| 10381 | "void main(){\n" |
| 10382 | " color = vec4(x[0] + x[1] + x[2]);\n" |
| 10383 | "}\n"; |
| 10384 | |
| 10385 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10386 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10387 | |
| 10388 | VkPipelineObj pipe(m_device); |
| 10389 | pipe.AddColorAttachment(); |
| 10390 | pipe.AddShader(&vs); |
| 10391 | pipe.AddShader(&fs); |
| 10392 | |
| 10393 | VkDescriptorSetObj descriptorSet(m_device); |
| 10394 | descriptorSet.AppendDummy(); |
| 10395 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10396 | |
| 10397 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10398 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10399 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10400 | } |
| 10401 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10402 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10403 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10404 | "Type mismatch on location 0"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10405 | |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10406 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10407 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10408 | |
| 10409 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10410 | "#version 450\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10411 | "\n" |
| 10412 | "layout(location=0) out int x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10413 | "out gl_PerVertex {\n" |
| 10414 | " vec4 gl_Position;\n" |
| 10415 | "};\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10416 | "void main(){\n" |
| 10417 | " x = 0;\n" |
| 10418 | " gl_Position = vec4(1);\n" |
| 10419 | "}\n"; |
| 10420 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10421 | "#version 450\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10422 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10423 | "layout(location=0) in float x;\n" /* VS writes int */ |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10424 | "layout(location=0) out vec4 color;\n" |
| 10425 | "void main(){\n" |
| 10426 | " color = vec4(x);\n" |
| 10427 | "}\n"; |
| 10428 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10429 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10430 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10431 | |
| 10432 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10433 | pipe.AddColorAttachment(); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10434 | pipe.AddShader(&vs); |
| 10435 | pipe.AddShader(&fs); |
| 10436 | |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10437 | VkDescriptorSetObj descriptorSet(m_device); |
| 10438 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10439 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10440 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10441 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10442 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10443 | m_errorMonitor->VerifyFound(); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10444 | } |
| 10445 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10446 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) { |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10447 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10448 | "Type mismatch on location 0"); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10449 | |
| 10450 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10451 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10452 | |
| 10453 | char const *vsSource = |
| 10454 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10455 | "\n" |
| 10456 | "out block { layout(location=0) int x; } outs;\n" |
| 10457 | "out gl_PerVertex {\n" |
| 10458 | " vec4 gl_Position;\n" |
| 10459 | "};\n" |
| 10460 | "void main(){\n" |
| 10461 | " outs.x = 0;\n" |
| 10462 | " gl_Position = vec4(1);\n" |
| 10463 | "}\n"; |
| 10464 | char const *fsSource = |
| 10465 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10466 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10467 | "in block { layout(location=0) float x; } ins;\n" /* VS writes int */ |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10468 | "layout(location=0) out vec4 color;\n" |
| 10469 | "void main(){\n" |
| 10470 | " color = vec4(ins.x);\n" |
| 10471 | "}\n"; |
| 10472 | |
| 10473 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10474 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10475 | |
| 10476 | VkPipelineObj pipe(m_device); |
| 10477 | pipe.AddColorAttachment(); |
| 10478 | pipe.AddShader(&vs); |
| 10479 | pipe.AddShader(&fs); |
| 10480 | |
| 10481 | VkDescriptorSetObj descriptorSet(m_device); |
| 10482 | descriptorSet.AppendDummy(); |
| 10483 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10484 | |
| 10485 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10486 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10487 | m_errorMonitor->VerifyFound(); |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10488 | } |
| 10489 | |
| 10490 | TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) { |
| 10491 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10492 | "location 0.0 which is not written by vertex shader"); |
| 10493 | |
| 10494 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10495 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10496 | |
| 10497 | char const *vsSource = |
| 10498 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10499 | "\n" |
| 10500 | "out block { layout(location=1) float x; } outs;\n" |
| 10501 | "out gl_PerVertex {\n" |
| 10502 | " vec4 gl_Position;\n" |
| 10503 | "};\n" |
| 10504 | "void main(){\n" |
| 10505 | " outs.x = 0;\n" |
| 10506 | " gl_Position = vec4(1);\n" |
| 10507 | "}\n"; |
| 10508 | char const *fsSource = |
| 10509 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10510 | "\n" |
| 10511 | "in block { layout(location=0) float x; } ins;\n" |
| 10512 | "layout(location=0) out vec4 color;\n" |
| 10513 | "void main(){\n" |
| 10514 | " color = vec4(ins.x);\n" |
| 10515 | "}\n"; |
| 10516 | |
| 10517 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10518 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10519 | |
| 10520 | VkPipelineObj pipe(m_device); |
| 10521 | pipe.AddColorAttachment(); |
| 10522 | pipe.AddShader(&vs); |
| 10523 | pipe.AddShader(&fs); |
| 10524 | |
| 10525 | VkDescriptorSetObj descriptorSet(m_device); |
| 10526 | descriptorSet.AppendDummy(); |
| 10527 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10528 | |
| 10529 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10530 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10531 | m_errorMonitor->VerifyFound(); |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10532 | } |
| 10533 | |
| 10534 | TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) { |
| 10535 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10536 | "location 0.1 which is not written by vertex shader"); |
| 10537 | |
| 10538 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10539 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10540 | |
| 10541 | char const *vsSource = |
| 10542 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10543 | "\n" |
| 10544 | "out block { layout(location=0, component=0) float x; } outs;\n" |
| 10545 | "out gl_PerVertex {\n" |
| 10546 | " vec4 gl_Position;\n" |
| 10547 | "};\n" |
| 10548 | "void main(){\n" |
| 10549 | " outs.x = 0;\n" |
| 10550 | " gl_Position = vec4(1);\n" |
| 10551 | "}\n"; |
| 10552 | char const *fsSource = |
| 10553 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10554 | "\n" |
| 10555 | "in block { layout(location=0, component=1) float x; } ins;\n" |
| 10556 | "layout(location=0) out vec4 color;\n" |
| 10557 | "void main(){\n" |
| 10558 | " color = vec4(ins.x);\n" |
| 10559 | "}\n"; |
| 10560 | |
| 10561 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10562 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10563 | |
| 10564 | VkPipelineObj pipe(m_device); |
| 10565 | pipe.AddColorAttachment(); |
| 10566 | pipe.AddShader(&vs); |
| 10567 | pipe.AddShader(&fs); |
| 10568 | |
| 10569 | VkDescriptorSetObj descriptorSet(m_device); |
| 10570 | descriptorSet.AppendDummy(); |
| 10571 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10572 | |
| 10573 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10574 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10575 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10576 | } |
| 10577 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10578 | TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 10579 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10580 | "location 0 not consumed by VS"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10581 | |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10582 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10583 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10584 | |
| 10585 | VkVertexInputBindingDescription input_binding; |
| 10586 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10587 | |
| 10588 | VkVertexInputAttributeDescription input_attrib; |
| 10589 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10590 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10591 | |
| 10592 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10593 | "#version 450\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10594 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10595 | "out gl_PerVertex {\n" |
| 10596 | " vec4 gl_Position;\n" |
| 10597 | "};\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10598 | "void main(){\n" |
| 10599 | " gl_Position = vec4(1);\n" |
| 10600 | "}\n"; |
| 10601 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10602 | "#version 450\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10603 | "\n" |
| 10604 | "layout(location=0) out vec4 color;\n" |
| 10605 | "void main(){\n" |
| 10606 | " color = vec4(1);\n" |
| 10607 | "}\n"; |
| 10608 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10609 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10610 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10611 | |
| 10612 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10613 | pipe.AddColorAttachment(); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10614 | pipe.AddShader(&vs); |
| 10615 | pipe.AddShader(&fs); |
| 10616 | |
| 10617 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10618 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10619 | |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10620 | VkDescriptorSetObj descriptorSet(m_device); |
| 10621 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10622 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10623 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10624 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10625 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10626 | m_errorMonitor->VerifyFound(); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10627 | } |
| 10628 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10629 | TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 10630 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10631 | "location 0 not consumed by VS"); |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10632 | |
| 10633 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10634 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10635 | |
| 10636 | VkVertexInputBindingDescription input_binding; |
| 10637 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10638 | |
| 10639 | VkVertexInputAttributeDescription input_attrib; |
| 10640 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10641 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10642 | |
| 10643 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10644 | "#version 450\n" |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10645 | "\n" |
| 10646 | "layout(location=1) in float x;\n" |
| 10647 | "out gl_PerVertex {\n" |
| 10648 | " vec4 gl_Position;\n" |
| 10649 | "};\n" |
| 10650 | "void main(){\n" |
| 10651 | " gl_Position = vec4(x);\n" |
| 10652 | "}\n"; |
| 10653 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10654 | "#version 450\n" |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10655 | "\n" |
| 10656 | "layout(location=0) out vec4 color;\n" |
| 10657 | "void main(){\n" |
| 10658 | " color = vec4(1);\n" |
| 10659 | "}\n"; |
| 10660 | |
| 10661 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10662 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10663 | |
| 10664 | VkPipelineObj pipe(m_device); |
| 10665 | pipe.AddColorAttachment(); |
| 10666 | pipe.AddShader(&vs); |
| 10667 | pipe.AddShader(&fs); |
| 10668 | |
| 10669 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10670 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10671 | |
| 10672 | VkDescriptorSetObj descriptorSet(m_device); |
| 10673 | descriptorSet.AppendDummy(); |
| 10674 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10675 | |
| 10676 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10677 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10678 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10679 | } |
| 10680 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10681 | TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) { |
| 10682 | m_errorMonitor->SetDesiredFailureMsg( |
| 10683 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10684 | "VS consumes input at location 0 but not provided"); |
| 10685 | |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10686 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10687 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10688 | |
| 10689 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10690 | "#version 450\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10691 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10692 | "layout(location=0) in vec4 x;\n" /* not provided */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10693 | "out gl_PerVertex {\n" |
| 10694 | " vec4 gl_Position;\n" |
| 10695 | "};\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10696 | "void main(){\n" |
| 10697 | " gl_Position = x;\n" |
| 10698 | "}\n"; |
| 10699 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10700 | "#version 450\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10701 | "\n" |
| 10702 | "layout(location=0) out vec4 color;\n" |
| 10703 | "void main(){\n" |
| 10704 | " color = vec4(1);\n" |
| 10705 | "}\n"; |
| 10706 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10707 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10708 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10709 | |
| 10710 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10711 | pipe.AddColorAttachment(); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10712 | pipe.AddShader(&vs); |
| 10713 | pipe.AddShader(&fs); |
| 10714 | |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10715 | VkDescriptorSetObj descriptorSet(m_device); |
| 10716 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10717 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10718 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10719 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10720 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10721 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10722 | } |
| 10723 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10724 | TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) { |
| 10725 | m_errorMonitor->SetDesiredFailureMsg( |
| 10726 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10727 | "location 0 does not match VS input type"); |
| 10728 | |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10729 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10730 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10731 | |
| 10732 | VkVertexInputBindingDescription input_binding; |
| 10733 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10734 | |
| 10735 | VkVertexInputAttributeDescription input_attrib; |
| 10736 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10737 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10738 | |
| 10739 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10740 | "#version 450\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10741 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10742 | "layout(location=0) in int x;\n" /* attrib provided float */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10743 | "out gl_PerVertex {\n" |
| 10744 | " vec4 gl_Position;\n" |
| 10745 | "};\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10746 | "void main(){\n" |
| 10747 | " gl_Position = vec4(x);\n" |
| 10748 | "}\n"; |
| 10749 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10750 | "#version 450\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10751 | "\n" |
| 10752 | "layout(location=0) out vec4 color;\n" |
| 10753 | "void main(){\n" |
| 10754 | " color = vec4(1);\n" |
| 10755 | "}\n"; |
| 10756 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10757 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10758 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10759 | |
| 10760 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10761 | pipe.AddColorAttachment(); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10762 | pipe.AddShader(&vs); |
| 10763 | pipe.AddShader(&fs); |
| 10764 | |
| 10765 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10766 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10767 | |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10768 | VkDescriptorSetObj descriptorSet(m_device); |
| 10769 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10770 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10771 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10772 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10773 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10774 | m_errorMonitor->VerifyFound(); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10775 | } |
| 10776 | |
Chris Forbes | c68b43c | 2016-04-06 11:18:47 +1200 | [diff] [blame] | 10777 | TEST_F(VkLayerTest, CreatePipelineDuplicateStage) { |
| 10778 | m_errorMonitor->SetDesiredFailureMsg( |
| 10779 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10780 | "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT"); |
| 10781 | |
| 10782 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10783 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10784 | |
| 10785 | char const *vsSource = |
| 10786 | "#version 450\n" |
| 10787 | "\n" |
| 10788 | "out gl_PerVertex {\n" |
| 10789 | " vec4 gl_Position;\n" |
| 10790 | "};\n" |
| 10791 | "void main(){\n" |
| 10792 | " gl_Position = vec4(1);\n" |
| 10793 | "}\n"; |
| 10794 | char const *fsSource = |
| 10795 | "#version 450\n" |
| 10796 | "\n" |
| 10797 | "layout(location=0) out vec4 color;\n" |
| 10798 | "void main(){\n" |
| 10799 | " color = vec4(1);\n" |
| 10800 | "}\n"; |
| 10801 | |
| 10802 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10803 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10804 | |
| 10805 | VkPipelineObj pipe(m_device); |
| 10806 | pipe.AddColorAttachment(); |
| 10807 | pipe.AddShader(&vs); |
| 10808 | pipe.AddShader(&vs); |
| 10809 | pipe.AddShader(&fs); |
| 10810 | |
| 10811 | VkDescriptorSetObj descriptorSet(m_device); |
| 10812 | descriptorSet.AppendDummy(); |
| 10813 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10814 | |
| 10815 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10816 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10817 | m_errorMonitor->VerifyFound(); |
Chris Forbes | c68b43c | 2016-04-06 11:18:47 +1200 | [diff] [blame] | 10818 | } |
| 10819 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10820 | TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10821 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10822 | |
| 10823 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10824 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10825 | |
| 10826 | VkVertexInputBindingDescription input_binding; |
| 10827 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10828 | |
| 10829 | VkVertexInputAttributeDescription input_attribs[2]; |
| 10830 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 10831 | |
| 10832 | for (int i = 0; i < 2; i++) { |
| 10833 | input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 10834 | input_attribs[i].location = i; |
| 10835 | } |
| 10836 | |
| 10837 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10838 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10839 | "\n" |
| 10840 | "layout(location=0) in mat2x4 x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10841 | "out gl_PerVertex {\n" |
| 10842 | " vec4 gl_Position;\n" |
| 10843 | "};\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10844 | "void main(){\n" |
| 10845 | " gl_Position = x[0] + x[1];\n" |
| 10846 | "}\n"; |
| 10847 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10848 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10849 | "\n" |
| 10850 | "layout(location=0) out vec4 color;\n" |
| 10851 | "void main(){\n" |
| 10852 | " color = vec4(1);\n" |
| 10853 | "}\n"; |
| 10854 | |
| 10855 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10856 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10857 | |
| 10858 | VkPipelineObj pipe(m_device); |
| 10859 | pipe.AddColorAttachment(); |
| 10860 | pipe.AddShader(&vs); |
| 10861 | pipe.AddShader(&fs); |
| 10862 | |
| 10863 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10864 | pipe.AddVertexInputAttribs(input_attribs, 2); |
| 10865 | |
| 10866 | VkDescriptorSetObj descriptorSet(m_device); |
| 10867 | descriptorSet.AppendDummy(); |
| 10868 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10869 | |
| 10870 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10871 | |
| 10872 | /* expect success */ |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10873 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10874 | } |
| 10875 | |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10876 | TEST_F(VkLayerTest, CreatePipelineAttribArrayType) |
| 10877 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10878 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10879 | |
| 10880 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10881 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10882 | |
| 10883 | VkVertexInputBindingDescription input_binding; |
| 10884 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10885 | |
| 10886 | VkVertexInputAttributeDescription input_attribs[2]; |
| 10887 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 10888 | |
| 10889 | for (int i = 0; i < 2; i++) { |
| 10890 | input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 10891 | input_attribs[i].location = i; |
| 10892 | } |
| 10893 | |
| 10894 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10895 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10896 | "\n" |
| 10897 | "layout(location=0) in vec4 x[2];\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10898 | "out gl_PerVertex {\n" |
| 10899 | " vec4 gl_Position;\n" |
| 10900 | "};\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10901 | "void main(){\n" |
| 10902 | " gl_Position = x[0] + x[1];\n" |
| 10903 | "}\n"; |
| 10904 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10905 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10906 | "\n" |
| 10907 | "layout(location=0) out vec4 color;\n" |
| 10908 | "void main(){\n" |
| 10909 | " color = vec4(1);\n" |
| 10910 | "}\n"; |
| 10911 | |
| 10912 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10913 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10914 | |
| 10915 | VkPipelineObj pipe(m_device); |
| 10916 | pipe.AddColorAttachment(); |
| 10917 | pipe.AddShader(&vs); |
| 10918 | pipe.AddShader(&fs); |
| 10919 | |
| 10920 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10921 | pipe.AddVertexInputAttribs(input_attribs, 2); |
| 10922 | |
| 10923 | VkDescriptorSetObj descriptorSet(m_device); |
| 10924 | descriptorSet.AppendDummy(); |
| 10925 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10926 | |
| 10927 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10928 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10929 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10930 | } |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10931 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10932 | TEST_F(VkLayerTest, CreatePipelineSimplePositive) |
| 10933 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10934 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10935 | |
| 10936 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10937 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10938 | |
| 10939 | char const *vsSource = |
| 10940 | "#version 450\n" |
| 10941 | "out gl_PerVertex {\n" |
| 10942 | " vec4 gl_Position;\n" |
| 10943 | "};\n" |
| 10944 | "void main(){\n" |
| 10945 | " gl_Position = vec4(0);\n" |
| 10946 | "}\n"; |
| 10947 | char const *fsSource = |
| 10948 | "#version 450\n" |
| 10949 | "\n" |
| 10950 | "layout(location=0) out vec4 color;\n" |
| 10951 | "void main(){\n" |
| 10952 | " color = vec4(1);\n" |
| 10953 | "}\n"; |
| 10954 | |
| 10955 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10956 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10957 | |
| 10958 | VkPipelineObj pipe(m_device); |
| 10959 | pipe.AddColorAttachment(); |
| 10960 | pipe.AddShader(&vs); |
| 10961 | pipe.AddShader(&fs); |
| 10962 | |
| 10963 | VkDescriptorSetObj descriptorSet(m_device); |
| 10964 | descriptorSet.AppendDummy(); |
| 10965 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10966 | |
| 10967 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10968 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10969 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10970 | } |
| 10971 | |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 10972 | TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch) |
| 10973 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10974 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 10975 | |
| 10976 | // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block |
| 10977 | |
| 10978 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10979 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10980 | |
| 10981 | char const *vsSource = |
| 10982 | "#version 450\n" |
| 10983 | "out gl_PerVertex {\n" |
| 10984 | " vec4 gl_Position;\n" |
| 10985 | "};\n" |
| 10986 | "layout(location=0) out vec3 x;\n" |
| 10987 | "layout(location=1) out ivec3 y;\n" |
| 10988 | "layout(location=2) out vec3 z;\n" |
| 10989 | "void main(){\n" |
| 10990 | " gl_Position = vec4(0);\n" |
| 10991 | " x = vec3(0); y = ivec3(0); z = vec3(0);\n" |
| 10992 | "}\n"; |
| 10993 | char const *fsSource = |
| 10994 | "#version 450\n" |
| 10995 | "\n" |
| 10996 | "layout(location=0) out vec4 color;\n" |
| 10997 | "layout(location=0) in float x;\n" |
| 10998 | "layout(location=1) flat in int y;\n" |
| 10999 | "layout(location=2) in vec2 z;\n" |
| 11000 | "void main(){\n" |
| 11001 | " color = vec4(1 + x + y + z.x);\n" |
| 11002 | "}\n"; |
| 11003 | |
| 11004 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11005 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11006 | |
| 11007 | VkPipelineObj pipe(m_device); |
| 11008 | pipe.AddColorAttachment(); |
| 11009 | pipe.AddShader(&vs); |
| 11010 | pipe.AddShader(&fs); |
| 11011 | |
| 11012 | VkDescriptorSetObj descriptorSet(m_device); |
| 11013 | descriptorSet.AppendDummy(); |
| 11014 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11015 | |
Mike Stroyan | 255e958 | 2016-06-24 09:49:32 -0600 | [diff] [blame] | 11016 | VkResult err = VK_SUCCESS; |
| 11017 | err = |
| 11018 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11019 | ASSERT_VK_SUCCESS(err); |
| 11020 | |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 11021 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11022 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 11023 | } |
| 11024 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 11025 | TEST_F(VkLayerTest, CreatePipelineTessPerVertex) |
| 11026 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11027 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 11028 | |
| 11029 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11030 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11031 | |
Chris Forbes | c1e852d | 2016-04-04 19:26:42 +1200 | [diff] [blame] | 11032 | if (!m_device->phy().features().tessellationShader) { |
| 11033 | printf("Device does not support tessellation shaders; skipped.\n"); |
| 11034 | return; |
| 11035 | } |
| 11036 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 11037 | char const *vsSource = |
| 11038 | "#version 450\n" |
| 11039 | "void main(){}\n"; |
| 11040 | char const *tcsSource = |
| 11041 | "#version 450\n" |
| 11042 | "layout(location=0) out int x[];\n" |
| 11043 | "layout(vertices=3) out;\n" |
| 11044 | "void main(){\n" |
| 11045 | " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n" |
| 11046 | " gl_TessLevelInner[0] = 1;\n" |
| 11047 | " x[gl_InvocationID] = gl_InvocationID;\n" |
| 11048 | "}\n"; |
| 11049 | char const *tesSource = |
| 11050 | "#version 450\n" |
| 11051 | "layout(triangles, equal_spacing, cw) in;\n" |
| 11052 | "layout(location=0) in int x[];\n" |
| 11053 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 11054 | "void main(){\n" |
| 11055 | " gl_Position.xyz = gl_TessCoord;\n" |
| 11056 | " gl_Position.w = x[0] + x[1] + x[2];\n" |
| 11057 | "}\n"; |
| 11058 | char const *fsSource = |
| 11059 | "#version 450\n" |
| 11060 | "layout(location=0) out vec4 color;\n" |
| 11061 | "void main(){\n" |
| 11062 | " color = vec4(1);\n" |
| 11063 | "}\n"; |
| 11064 | |
| 11065 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11066 | VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this); |
| 11067 | VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this); |
| 11068 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11069 | |
| 11070 | VkPipelineInputAssemblyStateCreateInfo iasci{ |
| 11071 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, |
| 11072 | nullptr, |
| 11073 | 0, |
| 11074 | VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, |
| 11075 | VK_FALSE}; |
| 11076 | |
Chris Forbes | b4cacb6 | 2016-04-04 19:15:00 +1200 | [diff] [blame] | 11077 | VkPipelineTessellationStateCreateInfo tsci{ |
| 11078 | VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, |
| 11079 | nullptr, |
| 11080 | 0, |
| 11081 | 3}; |
| 11082 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 11083 | VkPipelineObj pipe(m_device); |
| 11084 | pipe.SetInputAssembly(&iasci); |
Chris Forbes | b4cacb6 | 2016-04-04 19:15:00 +1200 | [diff] [blame] | 11085 | pipe.SetTessellation(&tsci); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 11086 | pipe.AddColorAttachment(); |
| 11087 | pipe.AddShader(&vs); |
| 11088 | pipe.AddShader(&tcs); |
| 11089 | pipe.AddShader(&tes); |
| 11090 | pipe.AddShader(&fs); |
| 11091 | |
| 11092 | VkDescriptorSetObj descriptorSet(m_device); |
| 11093 | descriptorSet.AppendDummy(); |
| 11094 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11095 | |
| 11096 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11097 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11098 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 11099 | } |
| 11100 | |
Chris Forbes | a0ab815 | 2016-04-20 13:34:27 +1200 | [diff] [blame] | 11101 | TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive) |
| 11102 | { |
| 11103 | m_errorMonitor->ExpectSuccess(); |
| 11104 | |
| 11105 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11106 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11107 | |
| 11108 | if (!m_device->phy().features().geometryShader) { |
| 11109 | printf("Device does not support geometry shaders; skipped.\n"); |
| 11110 | return; |
| 11111 | } |
| 11112 | |
| 11113 | char const *vsSource = |
| 11114 | "#version 450\n" |
| 11115 | "layout(location=0) out VertexData { vec4 x; } vs_out;\n" |
| 11116 | "void main(){\n" |
| 11117 | " vs_out.x = vec4(1);\n" |
| 11118 | "}\n"; |
| 11119 | char const *gsSource = |
| 11120 | "#version 450\n" |
| 11121 | "layout(triangles) in;\n" |
| 11122 | "layout(triangle_strip, max_vertices=3) out;\n" |
| 11123 | "layout(location=0) in VertexData { vec4 x; } gs_in[];\n" |
| 11124 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 11125 | "void main() {\n" |
| 11126 | " gl_Position = gs_in[0].x;\n" |
| 11127 | " EmitVertex();\n" |
| 11128 | "}\n"; |
| 11129 | char const *fsSource = |
| 11130 | "#version 450\n" |
| 11131 | "layout(location=0) out vec4 color;\n" |
| 11132 | "void main(){\n" |
| 11133 | " color = vec4(1);\n" |
| 11134 | "}\n"; |
| 11135 | |
| 11136 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11137 | VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this); |
| 11138 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11139 | |
| 11140 | VkPipelineObj pipe(m_device); |
| 11141 | pipe.AddColorAttachment(); |
| 11142 | pipe.AddShader(&vs); |
| 11143 | pipe.AddShader(&gs); |
| 11144 | pipe.AddShader(&fs); |
| 11145 | |
| 11146 | VkDescriptorSetObj descriptorSet(m_device); |
| 11147 | descriptorSet.AppendDummy(); |
| 11148 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11149 | |
| 11150 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11151 | |
| 11152 | m_errorMonitor->VerifyNotFound(); |
| 11153 | } |
| 11154 | |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 11155 | TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) |
| 11156 | { |
| 11157 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11158 | "is per-vertex in tessellation control shader stage " |
| 11159 | "but per-patch in tessellation evaluation shader stage"); |
| 11160 | |
| 11161 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11162 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11163 | |
Chris Forbes | c1e852d | 2016-04-04 19:26:42 +1200 | [diff] [blame] | 11164 | if (!m_device->phy().features().tessellationShader) { |
| 11165 | printf("Device does not support tessellation shaders; skipped.\n"); |
| 11166 | return; |
| 11167 | } |
| 11168 | |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 11169 | char const *vsSource = |
| 11170 | "#version 450\n" |
| 11171 | "void main(){}\n"; |
| 11172 | char const *tcsSource = |
| 11173 | "#version 450\n" |
| 11174 | "layout(location=0) out int x[];\n" |
| 11175 | "layout(vertices=3) out;\n" |
| 11176 | "void main(){\n" |
| 11177 | " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n" |
| 11178 | " gl_TessLevelInner[0] = 1;\n" |
| 11179 | " x[gl_InvocationID] = gl_InvocationID;\n" |
| 11180 | "}\n"; |
| 11181 | char const *tesSource = |
| 11182 | "#version 450\n" |
| 11183 | "layout(triangles, equal_spacing, cw) in;\n" |
| 11184 | "layout(location=0) patch in int x;\n" |
| 11185 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 11186 | "void main(){\n" |
| 11187 | " gl_Position.xyz = gl_TessCoord;\n" |
| 11188 | " gl_Position.w = x;\n" |
| 11189 | "}\n"; |
| 11190 | char const *fsSource = |
| 11191 | "#version 450\n" |
| 11192 | "layout(location=0) out vec4 color;\n" |
| 11193 | "void main(){\n" |
| 11194 | " color = vec4(1);\n" |
| 11195 | "}\n"; |
| 11196 | |
| 11197 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11198 | VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this); |
| 11199 | VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this); |
| 11200 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11201 | |
| 11202 | VkPipelineInputAssemblyStateCreateInfo iasci{ |
| 11203 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, |
| 11204 | nullptr, |
| 11205 | 0, |
| 11206 | VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, |
| 11207 | VK_FALSE}; |
| 11208 | |
| 11209 | VkPipelineTessellationStateCreateInfo tsci{ |
| 11210 | VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, |
| 11211 | nullptr, |
| 11212 | 0, |
| 11213 | 3}; |
| 11214 | |
| 11215 | VkPipelineObj pipe(m_device); |
| 11216 | pipe.SetInputAssembly(&iasci); |
| 11217 | pipe.SetTessellation(&tsci); |
| 11218 | pipe.AddColorAttachment(); |
| 11219 | pipe.AddShader(&vs); |
| 11220 | pipe.AddShader(&tcs); |
| 11221 | pipe.AddShader(&tes); |
| 11222 | pipe.AddShader(&fs); |
| 11223 | |
| 11224 | VkDescriptorSetObj descriptorSet(m_device); |
| 11225 | descriptorSet.AppendDummy(); |
| 11226 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11227 | |
| 11228 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11229 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11230 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 11231 | } |
| 11232 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11233 | TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) { |
| 11234 | m_errorMonitor->SetDesiredFailureMsg( |
| 11235 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11236 | "Duplicate vertex input binding descriptions for binding 0"); |
| 11237 | |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11238 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 11239 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11240 | |
| 11241 | /* Two binding descriptions for binding 0 */ |
| 11242 | VkVertexInputBindingDescription input_bindings[2]; |
| 11243 | memset(input_bindings, 0, sizeof(input_bindings)); |
| 11244 | |
| 11245 | VkVertexInputAttributeDescription input_attrib; |
| 11246 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 11247 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 11248 | |
| 11249 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11250 | "#version 450\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11251 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11252 | "layout(location=0) in float x;\n" /* attrib provided float */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11253 | "out gl_PerVertex {\n" |
| 11254 | " vec4 gl_Position;\n" |
| 11255 | "};\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11256 | "void main(){\n" |
| 11257 | " gl_Position = vec4(x);\n" |
| 11258 | "}\n"; |
| 11259 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11260 | "#version 450\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11261 | "\n" |
| 11262 | "layout(location=0) out vec4 color;\n" |
| 11263 | "void main(){\n" |
| 11264 | " color = vec4(1);\n" |
| 11265 | "}\n"; |
| 11266 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11267 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11268 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11269 | |
| 11270 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11271 | pipe.AddColorAttachment(); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11272 | pipe.AddShader(&vs); |
| 11273 | pipe.AddShader(&fs); |
| 11274 | |
| 11275 | pipe.AddVertexInputBindings(input_bindings, 2); |
| 11276 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 11277 | |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11278 | VkDescriptorSetObj descriptorSet(m_device); |
| 11279 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11280 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11281 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11282 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11283 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11284 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 11285 | } |
Chris Forbes | 8f68b56 | 2015-05-25 11:13:32 +1200 | [diff] [blame] | 11286 | |
Chris Forbes | 35efec7 | 2016-04-21 14:32:08 +1200 | [diff] [blame] | 11287 | TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) { |
| 11288 | m_errorMonitor->ExpectSuccess(); |
| 11289 | |
| 11290 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11291 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11292 | |
Chris Forbes | 91cf3a8 | 2016-06-28 17:51:35 +1200 | [diff] [blame] | 11293 | if (!m_device->phy().features().shaderFloat64) { |
Chris Forbes | 35efec7 | 2016-04-21 14:32:08 +1200 | [diff] [blame] | 11294 | printf("Device does not support 64bit vertex attributes; skipped.\n"); |
| 11295 | return; |
| 11296 | } |
| 11297 | |
| 11298 | VkVertexInputBindingDescription input_bindings[1]; |
| 11299 | memset(input_bindings, 0, sizeof(input_bindings)); |
| 11300 | |
| 11301 | VkVertexInputAttributeDescription input_attribs[4]; |
| 11302 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 11303 | input_attribs[0].location = 0; |
| 11304 | input_attribs[0].offset = 0; |
| 11305 | input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 11306 | input_attribs[1].location = 2; |
| 11307 | input_attribs[1].offset = 32; |
| 11308 | input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 11309 | input_attribs[2].location = 4; |
| 11310 | input_attribs[2].offset = 64; |
| 11311 | input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 11312 | input_attribs[3].location = 6; |
| 11313 | input_attribs[3].offset = 96; |
| 11314 | input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 11315 | |
| 11316 | char const *vsSource = |
| 11317 | "#version 450\n" |
| 11318 | "\n" |
| 11319 | "layout(location=0) in dmat4 x;\n" |
| 11320 | "out gl_PerVertex {\n" |
| 11321 | " vec4 gl_Position;\n" |
| 11322 | "};\n" |
| 11323 | "void main(){\n" |
| 11324 | " gl_Position = vec4(x[0][0]);\n" |
| 11325 | "}\n"; |
| 11326 | char const *fsSource = |
| 11327 | "#version 450\n" |
| 11328 | "\n" |
| 11329 | "layout(location=0) out vec4 color;\n" |
| 11330 | "void main(){\n" |
| 11331 | " color = vec4(1);\n" |
| 11332 | "}\n"; |
| 11333 | |
| 11334 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11335 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11336 | |
| 11337 | VkPipelineObj pipe(m_device); |
| 11338 | pipe.AddColorAttachment(); |
| 11339 | pipe.AddShader(&vs); |
| 11340 | pipe.AddShader(&fs); |
| 11341 | |
| 11342 | pipe.AddVertexInputBindings(input_bindings, 1); |
| 11343 | pipe.AddVertexInputAttribs(input_attribs, 4); |
| 11344 | |
| 11345 | VkDescriptorSetObj descriptorSet(m_device); |
| 11346 | descriptorSet.AppendDummy(); |
| 11347 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11348 | |
| 11349 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11350 | |
| 11351 | m_errorMonitor->VerifyNotFound(); |
| 11352 | } |
| 11353 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11354 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11355 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11356 | "Attachment 0 not written by FS"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11357 | |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11358 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11359 | |
| 11360 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11361 | "#version 450\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11362 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11363 | "out gl_PerVertex {\n" |
| 11364 | " vec4 gl_Position;\n" |
| 11365 | "};\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11366 | "void main(){\n" |
| 11367 | " gl_Position = vec4(1);\n" |
| 11368 | "}\n"; |
| 11369 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11370 | "#version 450\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11371 | "\n" |
| 11372 | "void main(){\n" |
| 11373 | "}\n"; |
| 11374 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11375 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11376 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11377 | |
| 11378 | VkPipelineObj pipe(m_device); |
| 11379 | pipe.AddShader(&vs); |
| 11380 | pipe.AddShader(&fs); |
| 11381 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11382 | /* set up CB 0, not written */ |
| 11383 | pipe.AddColorAttachment(); |
| 11384 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11385 | |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11386 | VkDescriptorSetObj descriptorSet(m_device); |
| 11387 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11388 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11389 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11390 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11391 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11392 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11393 | } |
| 11394 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11395 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11396 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 11397 | VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11398 | "FS writes to output location 1 with no matching attachment"); |
| 11399 | |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11400 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11401 | |
| 11402 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11403 | "#version 450\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11404 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11405 | "out gl_PerVertex {\n" |
| 11406 | " vec4 gl_Position;\n" |
| 11407 | "};\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11408 | "void main(){\n" |
| 11409 | " gl_Position = vec4(1);\n" |
| 11410 | "}\n"; |
| 11411 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11412 | "#version 450\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11413 | "\n" |
| 11414 | "layout(location=0) out vec4 x;\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11415 | "layout(location=1) out vec4 y;\n" /* no matching attachment for this */ |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11416 | "void main(){\n" |
| 11417 | " x = vec4(1);\n" |
| 11418 | " y = vec4(1);\n" |
| 11419 | "}\n"; |
| 11420 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11421 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11422 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11423 | |
| 11424 | VkPipelineObj pipe(m_device); |
| 11425 | pipe.AddShader(&vs); |
| 11426 | pipe.AddShader(&fs); |
| 11427 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11428 | /* set up CB 0, not written */ |
| 11429 | pipe.AddColorAttachment(); |
| 11430 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11431 | /* FS writes CB 1, but we don't configure it */ |
| 11432 | |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11433 | VkDescriptorSetObj descriptorSet(m_device); |
| 11434 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11435 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11436 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11437 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11438 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11439 | m_errorMonitor->VerifyFound(); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11440 | } |
| 11441 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11442 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11443 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11444 | "does not match FS output type"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11445 | |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11446 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11447 | |
| 11448 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11449 | "#version 450\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11450 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11451 | "out gl_PerVertex {\n" |
| 11452 | " vec4 gl_Position;\n" |
| 11453 | "};\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11454 | "void main(){\n" |
| 11455 | " gl_Position = vec4(1);\n" |
| 11456 | "}\n"; |
| 11457 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11458 | "#version 450\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11459 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11460 | "layout(location=0) out ivec4 x;\n" /* not UNORM */ |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11461 | "void main(){\n" |
| 11462 | " x = ivec4(1);\n" |
| 11463 | "}\n"; |
| 11464 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11465 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11466 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11467 | |
| 11468 | VkPipelineObj pipe(m_device); |
| 11469 | pipe.AddShader(&vs); |
| 11470 | pipe.AddShader(&fs); |
| 11471 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11472 | /* set up CB 0; type is UNORM by default */ |
| 11473 | pipe.AddColorAttachment(); |
| 11474 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11475 | |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11476 | VkDescriptorSetObj descriptorSet(m_device); |
| 11477 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11478 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11479 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11480 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11481 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11482 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11483 | } |
Chris Forbes | 7b1b893 | 2015-06-05 14:43:36 +1200 | [diff] [blame] | 11484 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11485 | TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11486 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11487 | "not declared in pipeline layout"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11488 | |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11489 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11490 | |
| 11491 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11492 | "#version 450\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11493 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11494 | "out gl_PerVertex {\n" |
| 11495 | " vec4 gl_Position;\n" |
| 11496 | "};\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11497 | "void main(){\n" |
| 11498 | " gl_Position = vec4(1);\n" |
| 11499 | "}\n"; |
| 11500 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11501 | "#version 450\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11502 | "\n" |
| 11503 | "layout(location=0) out vec4 x;\n" |
| 11504 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 11505 | "void main(){\n" |
| 11506 | " x = vec4(bar.y);\n" |
| 11507 | "}\n"; |
| 11508 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11509 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11510 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11511 | |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11512 | VkPipelineObj pipe(m_device); |
| 11513 | pipe.AddShader(&vs); |
| 11514 | pipe.AddShader(&fs); |
| 11515 | |
| 11516 | /* set up CB 0; type is UNORM by default */ |
| 11517 | pipe.AddColorAttachment(); |
| 11518 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11519 | |
| 11520 | VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11521 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11522 | |
| 11523 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11524 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11525 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11526 | } |
| 11527 | |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11528 | TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) { |
| 11529 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11530 | "not declared in layout"); |
| 11531 | |
| 11532 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11533 | |
| 11534 | char const *vsSource = |
| 11535 | "#version 450\n" |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11536 | "\n" |
| 11537 | "layout(push_constant, std430) uniform foo { float x; } consts;\n" |
| 11538 | "out gl_PerVertex {\n" |
| 11539 | " vec4 gl_Position;\n" |
| 11540 | "};\n" |
| 11541 | "void main(){\n" |
| 11542 | " gl_Position = vec4(consts.x);\n" |
| 11543 | "}\n"; |
| 11544 | char const *fsSource = |
| 11545 | "#version 450\n" |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11546 | "\n" |
| 11547 | "layout(location=0) out vec4 x;\n" |
| 11548 | "void main(){\n" |
| 11549 | " x = vec4(1);\n" |
| 11550 | "}\n"; |
| 11551 | |
| 11552 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11553 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11554 | |
| 11555 | VkPipelineObj pipe(m_device); |
| 11556 | pipe.AddShader(&vs); |
| 11557 | pipe.AddShader(&fs); |
| 11558 | |
| 11559 | /* set up CB 0; type is UNORM by default */ |
| 11560 | pipe.AddColorAttachment(); |
| 11561 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11562 | |
| 11563 | VkDescriptorSetObj descriptorSet(m_device); |
| 11564 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11565 | |
| 11566 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11567 | |
| 11568 | /* should have generated an error -- no push constant ranges provided! */ |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11569 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11570 | } |
| 11571 | |
Chris Forbes | 10eb9ae | 2016-05-31 16:09:42 +1200 | [diff] [blame] | 11572 | TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) { |
| 11573 | m_errorMonitor->SetDesiredFailureMsg( |
| 11574 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11575 | "Shader uses descriptor slot 0.0"); |
| 11576 | |
| 11577 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11578 | |
| 11579 | char const *csSource = |
| 11580 | "#version 450\n" |
| 11581 | "\n" |
| 11582 | "layout(local_size_x=1) in;\n" |
| 11583 | "layout(set=0, binding=0) buffer block { vec4 x; };\n" |
| 11584 | "void main(){\n" |
| 11585 | " x = vec4(1);\n" |
| 11586 | "}\n"; |
| 11587 | |
| 11588 | VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this); |
| 11589 | |
| 11590 | VkDescriptorSetObj descriptorSet(m_device); |
| 11591 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11592 | |
| 11593 | VkComputePipelineCreateInfo cpci = { |
| 11594 | VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, |
| 11595 | nullptr, 0, { |
| 11596 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 11597 | nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, |
| 11598 | cs.handle(), "main", nullptr |
| 11599 | }, |
| 11600 | descriptorSet.GetPipelineLayout(), |
| 11601 | VK_NULL_HANDLE, -1 |
| 11602 | }; |
| 11603 | |
| 11604 | VkPipeline pipe; |
| 11605 | VkResult err = vkCreateComputePipelines( |
| 11606 | m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe); |
| 11607 | |
| 11608 | m_errorMonitor->VerifyFound(); |
| 11609 | |
| 11610 | if (err == VK_SUCCESS) { |
| 11611 | vkDestroyPipeline(m_device->device(), pipe, nullptr); |
| 11612 | } |
| 11613 | } |
| 11614 | |
| 11615 | TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) { |
| 11616 | m_errorMonitor->ExpectSuccess(); |
| 11617 | |
| 11618 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11619 | |
| 11620 | char const *csSource = |
| 11621 | "#version 450\n" |
| 11622 | "\n" |
| 11623 | "layout(local_size_x=1) in;\n" |
| 11624 | "layout(set=0, binding=0) buffer block { vec4 x; };\n" |
| 11625 | "void main(){\n" |
| 11626 | " // x is not used.\n" |
| 11627 | "}\n"; |
| 11628 | |
| 11629 | VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this); |
| 11630 | |
| 11631 | VkDescriptorSetObj descriptorSet(m_device); |
| 11632 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11633 | |
| 11634 | VkComputePipelineCreateInfo cpci = { |
| 11635 | VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, |
| 11636 | nullptr, 0, { |
| 11637 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 11638 | nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, |
| 11639 | cs.handle(), "main", nullptr |
| 11640 | }, |
| 11641 | descriptorSet.GetPipelineLayout(), |
| 11642 | VK_NULL_HANDLE, -1 |
| 11643 | }; |
| 11644 | |
| 11645 | VkPipeline pipe; |
| 11646 | VkResult err = vkCreateComputePipelines( |
| 11647 | m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe); |
| 11648 | |
| 11649 | m_errorMonitor->VerifyNotFound(); |
| 11650 | |
| 11651 | if (err == VK_SUCCESS) { |
| 11652 | vkDestroyPipeline(m_device->device(), pipe, nullptr); |
| 11653 | } |
| 11654 | } |
| 11655 | |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 11656 | #endif // SHADER_CHECKER_TESTS |
| 11657 | |
| 11658 | #if DEVICE_LIMITS_TESTS |
Mark Young | c48c4c1 | 2016-04-11 14:26:49 -0600 | [diff] [blame] | 11659 | TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11660 | m_errorMonitor->SetDesiredFailureMsg( |
| 11661 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11662 | "CreateImage extents exceed allowable limits for format"); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11663 | |
| 11664 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11665 | |
| 11666 | // Create an image |
| 11667 | VkImage image; |
| 11668 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11669 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11670 | const int32_t tex_width = 32; |
| 11671 | const int32_t tex_height = 32; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11672 | |
| 11673 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11674 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11675 | image_create_info.pNext = NULL; |
| 11676 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11677 | image_create_info.format = tex_format; |
| 11678 | image_create_info.extent.width = tex_width; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11679 | image_create_info.extent.height = tex_height; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11680 | image_create_info.extent.depth = 1; |
| 11681 | image_create_info.mipLevels = 1; |
| 11682 | image_create_info.arrayLayers = 1; |
| 11683 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11684 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11685 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 11686 | image_create_info.flags = 0; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11687 | |
| 11688 | // Introduce error by sending down a bogus width extent |
| 11689 | image_create_info.extent.width = 65536; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11690 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11691 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11692 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11693 | } |
| 11694 | |
Mark Young | c48c4c1 | 2016-04-11 14:26:49 -0600 | [diff] [blame] | 11695 | TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) { |
| 11696 | m_errorMonitor->SetDesiredFailureMsg( |
| 11697 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11698 | "CreateImage extents is 0 for at least one required dimension"); |
| 11699 | |
| 11700 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11701 | |
| 11702 | // Create an image |
| 11703 | VkImage image; |
| 11704 | |
| 11705 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11706 | const int32_t tex_width = 32; |
| 11707 | const int32_t tex_height = 32; |
| 11708 | |
| 11709 | VkImageCreateInfo image_create_info = {}; |
| 11710 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11711 | image_create_info.pNext = NULL; |
| 11712 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11713 | image_create_info.format = tex_format; |
| 11714 | image_create_info.extent.width = tex_width; |
| 11715 | image_create_info.extent.height = tex_height; |
| 11716 | image_create_info.extent.depth = 1; |
| 11717 | image_create_info.mipLevels = 1; |
| 11718 | image_create_info.arrayLayers = 1; |
| 11719 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11720 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11721 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 11722 | image_create_info.flags = 0; |
| 11723 | |
| 11724 | // Introduce error by sending down a bogus width extent |
| 11725 | image_create_info.extent.width = 0; |
| 11726 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 11727 | |
| 11728 | m_errorMonitor->VerifyFound(); |
| 11729 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 11730 | #endif // DEVICE_LIMITS_TESTS |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11731 | |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11732 | #if IMAGE_TESTS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11733 | TEST_F(VkLayerTest, InvalidImageView) { |
| 11734 | VkResult err; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11735 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11736 | m_errorMonitor->SetDesiredFailureMsg( |
| 11737 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11738 | "vkCreateImageView called with baseMipLevel 10 "); |
| 11739 | |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11740 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11741 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11742 | // Create an image and try to create a view with bad baseMipLevel |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11743 | VkImage image; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11744 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11745 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11746 | const int32_t tex_width = 32; |
| 11747 | const int32_t tex_height = 32; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11748 | |
| 11749 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11750 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11751 | image_create_info.pNext = NULL; |
| 11752 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11753 | image_create_info.format = tex_format; |
| 11754 | image_create_info.extent.width = tex_width; |
| 11755 | image_create_info.extent.height = tex_height; |
| 11756 | image_create_info.extent.depth = 1; |
| 11757 | image_create_info.mipLevels = 1; |
| 11758 | image_create_info.arrayLayers = 1; |
| 11759 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11760 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11761 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 11762 | image_create_info.flags = 0; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11763 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11764 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11765 | ASSERT_VK_SUCCESS(err); |
| 11766 | |
| 11767 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11768 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11769 | image_view_create_info.image = image; |
| 11770 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 11771 | image_view_create_info.format = tex_format; |
| 11772 | image_view_create_info.subresourceRange.layerCount = 1; |
| 11773 | image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error |
| 11774 | image_view_create_info.subresourceRange.levelCount = 1; |
| 11775 | image_view_create_info.subresourceRange.aspectMask = |
| 11776 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11777 | |
| 11778 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11779 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 11780 | &view); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11781 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11782 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 11783 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11784 | } |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11785 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11786 | TEST_F(VkLayerTest, InvalidImageViewAspect) { |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11787 | TEST_DESCRIPTION( |
| 11788 | "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] | 11789 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11790 | "vkCreateImageView: Color image " |
| 11791 | "formats must have ONLY the " |
| 11792 | "VK_IMAGE_ASPECT_COLOR_BIT set"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11793 | |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11794 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11795 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11796 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11797 | VkImageObj image(m_device); |
| 11798 | image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, |
| 11799 | VK_IMAGE_TILING_LINEAR, 0); |
| 11800 | ASSERT_TRUE(image.initialized()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11801 | |
| 11802 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11803 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11804 | image_view_create_info.image = image.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11805 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 11806 | image_view_create_info.format = tex_format; |
| 11807 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 11808 | image_view_create_info.subresourceRange.levelCount = 1; |
| 11809 | // Cause an error by setting an invalid image aspect |
| 11810 | image_view_create_info.subresourceRange.aspectMask = |
| 11811 | VK_IMAGE_ASPECT_METADATA_BIT; |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11812 | |
| 11813 | VkImageView view; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11814 | vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11815 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11816 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11817 | } |
| 11818 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11819 | TEST_F(VkLayerTest, CopyImageLayerCountMismatch) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11820 | VkResult err; |
| 11821 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11822 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11823 | m_errorMonitor->SetDesiredFailureMsg( |
| 11824 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11825 | "vkCmdCopyImage: number of layers in source and destination subresources for pRegions"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11826 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11827 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11828 | |
| 11829 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11830 | VkImage srcImage; |
| 11831 | VkImage dstImage; |
| 11832 | VkDeviceMemory srcMem; |
| 11833 | VkDeviceMemory destMem; |
| 11834 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11835 | |
| 11836 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11837 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11838 | image_create_info.pNext = NULL; |
| 11839 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11840 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11841 | image_create_info.extent.width = 32; |
| 11842 | image_create_info.extent.height = 32; |
| 11843 | image_create_info.extent.depth = 1; |
| 11844 | image_create_info.mipLevels = 1; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11845 | image_create_info.arrayLayers = 4; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11846 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11847 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 11848 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11849 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11850 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11851 | err = |
| 11852 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11853 | ASSERT_VK_SUCCESS(err); |
| 11854 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11855 | err = |
| 11856 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11857 | ASSERT_VK_SUCCESS(err); |
| 11858 | |
| 11859 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11860 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11861 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 11862 | memAlloc.pNext = NULL; |
| 11863 | memAlloc.allocationSize = 0; |
| 11864 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11865 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 11866 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11867 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11868 | pass = |
| 11869 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 11870 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11871 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11872 | ASSERT_VK_SUCCESS(err); |
| 11873 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11874 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11875 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11876 | pass = |
| 11877 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11878 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11879 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11880 | ASSERT_VK_SUCCESS(err); |
| 11881 | |
| 11882 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 11883 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11884 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11885 | ASSERT_VK_SUCCESS(err); |
| 11886 | |
| 11887 | BeginCommandBuffer(); |
| 11888 | VkImageCopy copyRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11889 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11890 | copyRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 11891 | copyRegion.srcSubresource.baseArrayLayer = 0; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11892 | copyRegion.srcSubresource.layerCount = 1; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11893 | copyRegion.srcOffset.x = 0; |
| 11894 | copyRegion.srcOffset.y = 0; |
| 11895 | copyRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11896 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11897 | copyRegion.dstSubresource.mipLevel = 0; |
| 11898 | copyRegion.dstSubresource.baseArrayLayer = 0; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11899 | // Introduce failure by forcing the dst layerCount to differ from src |
| 11900 | copyRegion.dstSubresource.layerCount = 3; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11901 | copyRegion.dstOffset.x = 0; |
| 11902 | copyRegion.dstOffset.y = 0; |
| 11903 | copyRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11904 | copyRegion.extent.width = 1; |
| 11905 | copyRegion.extent.height = 1; |
| 11906 | copyRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11907 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 11908 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11909 | EndCommandBuffer(); |
| 11910 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11911 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11912 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11913 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11914 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11915 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 11916 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11917 | } |
| 11918 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11919 | TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) { |
| 11920 | |
| 11921 | TEST_DESCRIPTION("Creating images with unsuported formats "); |
| 11922 | |
| 11923 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11924 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11925 | VkImageObj image(m_device); |
| 11926 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 11927 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 11928 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 11929 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 11930 | ASSERT_TRUE(image.initialized()); |
| 11931 | |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11932 | // Create image with unsupported format - Expect FORMAT_UNSUPPORTED |
| 11933 | VkImageCreateInfo image_create_info; |
| 11934 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11935 | image_create_info.pNext = NULL; |
| 11936 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11937 | image_create_info.format = VK_FORMAT_UNDEFINED; |
| 11938 | image_create_info.extent.width = 32; |
| 11939 | image_create_info.extent.height = 32; |
| 11940 | image_create_info.extent.depth = 1; |
| 11941 | image_create_info.mipLevels = 1; |
| 11942 | image_create_info.arrayLayers = 1; |
| 11943 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11944 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 11945 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11946 | image_create_info.flags = 0; |
| 11947 | |
| 11948 | m_errorMonitor->SetDesiredFailureMsg( |
| 11949 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11950 | "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED"); |
| 11951 | |
| 11952 | VkImage localImage; |
| 11953 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage); |
| 11954 | m_errorMonitor->VerifyFound(); |
| 11955 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11956 | VkFormat unsupported = VK_FORMAT_UNDEFINED; |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11957 | // Look for a format that is COMPLETELY unsupported with this hardware |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11958 | for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) { |
| 11959 | VkFormat format = static_cast<VkFormat>(f); |
| 11960 | VkFormatProperties fProps = m_device->format_properties(format); |
| 11961 | if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && |
| 11962 | fProps.optimalTilingFeatures == 0) { |
| 11963 | unsupported = format; |
| 11964 | break; |
| 11965 | } |
| 11966 | } |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11967 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11968 | if (unsupported != VK_FORMAT_UNDEFINED) { |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11969 | image_create_info.format = unsupported; |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11970 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11971 | "is an unsupported format"); |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11972 | |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11973 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage); |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11974 | m_errorMonitor->VerifyFound(); |
| 11975 | } |
| 11976 | } |
| 11977 | |
| 11978 | TEST_F(VkLayerTest, ImageLayerViewTests) { |
| 11979 | VkResult ret; |
| 11980 | TEST_DESCRIPTION("Passing bad parameters to CreateImageView"); |
| 11981 | |
| 11982 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11983 | |
| 11984 | VkImageObj image(m_device); |
| 11985 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 11986 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 11987 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 11988 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 11989 | ASSERT_TRUE(image.initialized()); |
| 11990 | |
| 11991 | VkImageView imgView; |
| 11992 | VkImageViewCreateInfo imgViewInfo = {}; |
| 11993 | imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 11994 | imgViewInfo.image = image.handle(); |
| 11995 | imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 11996 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11997 | imgViewInfo.subresourceRange.layerCount = 1; |
| 11998 | imgViewInfo.subresourceRange.baseMipLevel = 0; |
| 11999 | imgViewInfo.subresourceRange.levelCount = 1; |
| 12000 | imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 12001 | |
| 12002 | m_errorMonitor->SetDesiredFailureMsg( |
| 12003 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12004 | "vkCreateImageView called with baseMipLevel"); |
| 12005 | // View can't have baseMipLevel >= image's mipLevels - Expect |
| 12006 | // VIEW_CREATE_ERROR |
| 12007 | imgViewInfo.subresourceRange.baseMipLevel = 1; |
| 12008 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 12009 | m_errorMonitor->VerifyFound(); |
| 12010 | imgViewInfo.subresourceRange.baseMipLevel = 0; |
| 12011 | |
| 12012 | m_errorMonitor->SetDesiredFailureMsg( |
| 12013 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12014 | "vkCreateImageView called with baseArrayLayer"); |
| 12015 | // View can't have baseArrayLayer >= image's arraySize - Expect |
| 12016 | // VIEW_CREATE_ERROR |
| 12017 | imgViewInfo.subresourceRange.baseArrayLayer = 1; |
| 12018 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 12019 | m_errorMonitor->VerifyFound(); |
| 12020 | imgViewInfo.subresourceRange.baseArrayLayer = 0; |
| 12021 | |
| 12022 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12023 | "vkCreateImageView called with 0 in " |
| 12024 | "pCreateInfo->subresourceRange." |
| 12025 | "levelCount"); |
| 12026 | // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR |
| 12027 | imgViewInfo.subresourceRange.levelCount = 0; |
| 12028 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 12029 | m_errorMonitor->VerifyFound(); |
| 12030 | imgViewInfo.subresourceRange.levelCount = 1; |
| 12031 | |
| 12032 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12033 | "vkCreateImageView called with 0 in " |
| 12034 | "pCreateInfo->subresourceRange." |
| 12035 | "layerCount"); |
| 12036 | // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR |
| 12037 | imgViewInfo.subresourceRange.layerCount = 0; |
| 12038 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 12039 | m_errorMonitor->VerifyFound(); |
| 12040 | imgViewInfo.subresourceRange.layerCount = 1; |
| 12041 | |
| 12042 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12043 | "but both must be color formats"); |
| 12044 | // Can't use depth format for view into color image - Expect INVALID_FORMAT |
| 12045 | imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 12046 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 12047 | m_errorMonitor->VerifyFound(); |
| 12048 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12049 | |
| 12050 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12051 | "Formats MUST be IDENTICAL unless " |
| 12052 | "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT " |
| 12053 | "was set on image creation."); |
| 12054 | // Same compatibility class but no MUTABLE_FORMAT bit - Expect |
| 12055 | // VIEW_CREATE_ERROR |
| 12056 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT; |
| 12057 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 12058 | m_errorMonitor->VerifyFound(); |
| 12059 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12060 | |
| 12061 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12062 | "can support ImageViews with " |
| 12063 | "differing formats but they must be " |
| 12064 | "in the same compatibility class."); |
| 12065 | // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect |
| 12066 | // VIEW_CREATE_ERROR |
| 12067 | VkImageCreateInfo mutImgInfo = image.create_info(); |
| 12068 | VkImage mutImage; |
| 12069 | mutImgInfo.format = VK_FORMAT_R8_UINT; |
| 12070 | assert( |
| 12071 | m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & |
| 12072 | VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT); |
| 12073 | mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; |
| 12074 | mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12075 | ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage); |
| 12076 | ASSERT_VK_SUCCESS(ret); |
| 12077 | imgViewInfo.image = mutImage; |
| 12078 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 12079 | m_errorMonitor->VerifyFound(); |
| 12080 | imgViewInfo.image = image.handle(); |
| 12081 | vkDestroyImage(m_device->handle(), mutImage, NULL); |
| 12082 | } |
| 12083 | |
| 12084 | TEST_F(VkLayerTest, MiscImageLayerTests) { |
| 12085 | |
| 12086 | TEST_DESCRIPTION("Image layer tests that don't belong elsewhare"); |
| 12087 | |
| 12088 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12089 | |
| 12090 | VkImageObj image(m_device); |
| 12091 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 12092 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 12093 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 12094 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 12095 | ASSERT_TRUE(image.initialized()); |
| 12096 | |
| 12097 | m_errorMonitor->SetDesiredFailureMsg( |
| 12098 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12099 | "number of layers in image subresource is zero"); |
| 12100 | vk_testing::Buffer buffer; |
| 12101 | VkMemoryPropertyFlags reqs = 0; |
| 12102 | buffer.init_as_src(*m_device, 128 * 128 * 4, reqs); |
| 12103 | VkBufferImageCopy region = {}; |
| 12104 | region.bufferRowLength = 128; |
| 12105 | region.bufferImageHeight = 128; |
| 12106 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 12107 | // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT |
| 12108 | region.imageSubresource.layerCount = 0; |
| 12109 | region.imageExtent.height = 4; |
| 12110 | region.imageExtent.width = 4; |
| 12111 | region.imageExtent.depth = 1; |
| 12112 | m_commandBuffer->BeginCommandBuffer(); |
| 12113 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 12114 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 12115 | 1, ®ion); |
| 12116 | m_errorMonitor->VerifyFound(); |
| 12117 | region.imageSubresource.layerCount = 1; |
| 12118 | |
| 12119 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12120 | "aspectMasks for each region must " |
| 12121 | "specify only COLOR or DEPTH or " |
| 12122 | "STENCIL"); |
| 12123 | // Expect MISMATCHED_IMAGE_ASPECT |
| 12124 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT; |
| 12125 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 12126 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 12127 | 1, ®ion); |
| 12128 | m_errorMonitor->VerifyFound(); |
| 12129 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 12130 | |
| 12131 | m_errorMonitor->SetDesiredFailureMsg( |
| 12132 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12133 | "If the format of srcImage is a depth, stencil, depth stencil or " |
| 12134 | "integer-based format then filter must be VK_FILTER_NEAREST"); |
| 12135 | // Expect INVALID_FILTER |
| 12136 | VkImageObj intImage1(m_device); |
| 12137 | intImage1.init(128, 128, VK_FORMAT_R8_UINT, |
| 12138 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, |
| 12139 | 0); |
| 12140 | VkImageObj intImage2(m_device); |
| 12141 | intImage2.init(128, 128, VK_FORMAT_R8_UINT, |
| 12142 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, |
| 12143 | 0); |
| 12144 | VkImageBlit blitRegion = {}; |
| 12145 | blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 12146 | blitRegion.srcSubresource.baseArrayLayer = 0; |
| 12147 | blitRegion.srcSubresource.layerCount = 1; |
| 12148 | blitRegion.srcSubresource.mipLevel = 0; |
| 12149 | blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 12150 | blitRegion.dstSubresource.baseArrayLayer = 0; |
| 12151 | blitRegion.dstSubresource.layerCount = 1; |
| 12152 | blitRegion.dstSubresource.mipLevel = 0; |
| 12153 | |
| 12154 | vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), |
| 12155 | intImage1.layout(), intImage2.handle(), intImage2.layout(), |
| 12156 | 16, &blitRegion, VK_FILTER_LINEAR); |
| 12157 | m_errorMonitor->VerifyFound(); |
| 12158 | |
| 12159 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12160 | "called with 0 in ppMemoryBarriers"); |
| 12161 | VkImageMemoryBarrier img_barrier; |
| 12162 | img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 12163 | img_barrier.pNext = NULL; |
| 12164 | img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 12165 | img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 12166 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 12167 | img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 12168 | img_barrier.image = image.handle(); |
| 12169 | img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 12170 | img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 12171 | img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 12172 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 12173 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 12174 | // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE |
| 12175 | img_barrier.subresourceRange.layerCount = 0; |
| 12176 | img_barrier.subresourceRange.levelCount = 1; |
| 12177 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 12178 | VK_PIPELINE_STAGE_HOST_BIT, |
| 12179 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 12180 | nullptr, 1, &img_barrier); |
| 12181 | m_errorMonitor->VerifyFound(); |
| 12182 | img_barrier.subresourceRange.layerCount = 1; |
| 12183 | } |
| 12184 | |
| 12185 | TEST_F(VkLayerTest, ImageFormatLimits) { |
| 12186 | |
| 12187 | TEST_DESCRIPTION("Exceed the limits of image format "); |
| 12188 | |
| 12189 | m_errorMonitor->SetDesiredFailureMsg( |
| 12190 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12191 | "CreateImage extents exceed allowable limits for format"); |
| 12192 | VkImageCreateInfo image_create_info = {}; |
| 12193 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12194 | image_create_info.pNext = NULL; |
| 12195 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12196 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12197 | image_create_info.extent.width = 32; |
| 12198 | image_create_info.extent.height = 32; |
| 12199 | image_create_info.extent.depth = 1; |
| 12200 | image_create_info.mipLevels = 1; |
| 12201 | image_create_info.arrayLayers = 1; |
| 12202 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12203 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12204 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 12205 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 12206 | image_create_info.flags = 0; |
| 12207 | |
| 12208 | VkImage nullImg; |
| 12209 | VkImageFormatProperties imgFmtProps; |
| 12210 | vkGetPhysicalDeviceImageFormatProperties( |
| 12211 | gpu(), image_create_info.format, image_create_info.imageType, |
| 12212 | image_create_info.tiling, image_create_info.usage, |
| 12213 | image_create_info.flags, &imgFmtProps); |
| 12214 | image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1; |
| 12215 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 12216 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 12217 | m_errorMonitor->VerifyFound(); |
| 12218 | image_create_info.extent.depth = 1; |
| 12219 | |
| 12220 | m_errorMonitor->SetDesiredFailureMsg( |
| 12221 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12222 | "exceeds allowable maximum supported by format of"); |
| 12223 | image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1; |
| 12224 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 12225 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 12226 | m_errorMonitor->VerifyFound(); |
| 12227 | image_create_info.mipLevels = 1; |
| 12228 | |
| 12229 | m_errorMonitor->SetDesiredFailureMsg( |
| 12230 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12231 | "exceeds allowable maximum supported by format of"); |
| 12232 | image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1; |
| 12233 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 12234 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 12235 | m_errorMonitor->VerifyFound(); |
| 12236 | image_create_info.arrayLayers = 1; |
| 12237 | |
| 12238 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12239 | "is not supported by format"); |
| 12240 | int samples = imgFmtProps.sampleCounts >> 1; |
| 12241 | image_create_info.samples = (VkSampleCountFlagBits)samples; |
| 12242 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 12243 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 12244 | m_errorMonitor->VerifyFound(); |
| 12245 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12246 | |
| 12247 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12248 | "pCreateInfo->initialLayout, must be " |
| 12249 | "VK_IMAGE_LAYOUT_UNDEFINED or " |
| 12250 | "VK_IMAGE_LAYOUT_PREINITIALIZED"); |
| 12251 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 12252 | // Expect INVALID_LAYOUT |
| 12253 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 12254 | m_errorMonitor->VerifyFound(); |
| 12255 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 12256 | } |
| 12257 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12258 | TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 12259 | VkResult err; |
| 12260 | bool pass; |
| 12261 | |
| 12262 | // Create color images with different format sizes and try to copy between them |
| 12263 | m_errorMonitor->SetDesiredFailureMsg( |
| 12264 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12265 | "vkCmdCopyImage called with unmatched source and dest image format sizes"); |
| 12266 | |
| 12267 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12268 | |
| 12269 | // Create two images of different types and try to copy between them |
| 12270 | VkImage srcImage; |
| 12271 | VkImage dstImage; |
| 12272 | VkDeviceMemory srcMem; |
| 12273 | VkDeviceMemory destMem; |
| 12274 | VkMemoryRequirements memReqs; |
| 12275 | |
| 12276 | VkImageCreateInfo image_create_info = {}; |
| 12277 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12278 | image_create_info.pNext = NULL; |
| 12279 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12280 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12281 | image_create_info.extent.width = 32; |
| 12282 | image_create_info.extent.height = 32; |
| 12283 | image_create_info.extent.depth = 1; |
| 12284 | image_create_info.mipLevels = 1; |
| 12285 | image_create_info.arrayLayers = 1; |
| 12286 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12287 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12288 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 12289 | image_create_info.flags = 0; |
| 12290 | |
| 12291 | err = |
| 12292 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
| 12293 | ASSERT_VK_SUCCESS(err); |
| 12294 | |
| 12295 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 12296 | // Introduce failure by creating second image with a different-sized format. |
| 12297 | image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16; |
| 12298 | |
| 12299 | err = |
| 12300 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
| 12301 | ASSERT_VK_SUCCESS(err); |
| 12302 | |
| 12303 | // Allocate memory |
| 12304 | VkMemoryAllocateInfo memAlloc = {}; |
| 12305 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12306 | memAlloc.pNext = NULL; |
| 12307 | memAlloc.allocationSize = 0; |
| 12308 | memAlloc.memoryTypeIndex = 0; |
| 12309 | |
| 12310 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
| 12311 | memAlloc.allocationSize = memReqs.size; |
| 12312 | pass = |
| 12313 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
| 12314 | ASSERT_TRUE(pass); |
| 12315 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
| 12316 | ASSERT_VK_SUCCESS(err); |
| 12317 | |
| 12318 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
| 12319 | memAlloc.allocationSize = memReqs.size; |
| 12320 | pass = |
| 12321 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
| 12322 | ASSERT_TRUE(pass); |
| 12323 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
| 12324 | ASSERT_VK_SUCCESS(err); |
| 12325 | |
| 12326 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12327 | ASSERT_VK_SUCCESS(err); |
| 12328 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
| 12329 | ASSERT_VK_SUCCESS(err); |
| 12330 | |
| 12331 | BeginCommandBuffer(); |
| 12332 | VkImageCopy copyRegion; |
| 12333 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 12334 | copyRegion.srcSubresource.mipLevel = 0; |
| 12335 | copyRegion.srcSubresource.baseArrayLayer = 0; |
| 12336 | copyRegion.srcSubresource.layerCount = 0; |
| 12337 | copyRegion.srcOffset.x = 0; |
| 12338 | copyRegion.srcOffset.y = 0; |
| 12339 | copyRegion.srcOffset.z = 0; |
| 12340 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 12341 | copyRegion.dstSubresource.mipLevel = 0; |
| 12342 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 12343 | copyRegion.dstSubresource.layerCount = 0; |
| 12344 | copyRegion.dstOffset.x = 0; |
| 12345 | copyRegion.dstOffset.y = 0; |
| 12346 | copyRegion.dstOffset.z = 0; |
| 12347 | copyRegion.extent.width = 1; |
| 12348 | copyRegion.extent.height = 1; |
| 12349 | copyRegion.extent.depth = 1; |
| 12350 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12351 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 12352 | EndCommandBuffer(); |
| 12353 | |
| 12354 | m_errorMonitor->VerifyFound(); |
| 12355 | |
| 12356 | vkDestroyImage(m_device->device(), srcImage, NULL); |
| 12357 | vkDestroyImage(m_device->device(), dstImage, NULL); |
| 12358 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12359 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12360 | } |
| 12361 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12362 | TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) { |
| 12363 | VkResult err; |
| 12364 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12365 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12366 | // 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] | 12367 | m_errorMonitor->SetDesiredFailureMsg( |
| 12368 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12369 | "vkCmdCopyImage called with unmatched source and dest image depth"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12370 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12371 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12372 | |
| 12373 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12374 | VkImage srcImage; |
| 12375 | VkImage dstImage; |
| 12376 | VkDeviceMemory srcMem; |
| 12377 | VkDeviceMemory destMem; |
| 12378 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12379 | |
| 12380 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12381 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12382 | image_create_info.pNext = NULL; |
| 12383 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12384 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12385 | image_create_info.extent.width = 32; |
| 12386 | image_create_info.extent.height = 32; |
| 12387 | image_create_info.extent.depth = 1; |
| 12388 | image_create_info.mipLevels = 1; |
| 12389 | image_create_info.arrayLayers = 1; |
| 12390 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12391 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12392 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 12393 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12394 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12395 | err = |
| 12396 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12397 | ASSERT_VK_SUCCESS(err); |
| 12398 | |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 12399 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 12400 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12401 | // Introduce failure by creating second image with a depth/stencil format |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12402 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12403 | image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 12404 | image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12405 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12406 | err = |
| 12407 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12408 | ASSERT_VK_SUCCESS(err); |
| 12409 | |
| 12410 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12411 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12412 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12413 | memAlloc.pNext = NULL; |
| 12414 | memAlloc.allocationSize = 0; |
| 12415 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12416 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12417 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12418 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12419 | pass = |
| 12420 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12421 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12422 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12423 | ASSERT_VK_SUCCESS(err); |
| 12424 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12425 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12426 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12427 | pass = |
| 12428 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12429 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12430 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12431 | ASSERT_VK_SUCCESS(err); |
| 12432 | |
| 12433 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12434 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12435 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12436 | ASSERT_VK_SUCCESS(err); |
| 12437 | |
| 12438 | BeginCommandBuffer(); |
| 12439 | VkImageCopy copyRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12440 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12441 | copyRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12442 | copyRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12443 | copyRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12444 | copyRegion.srcOffset.x = 0; |
| 12445 | copyRegion.srcOffset.y = 0; |
| 12446 | copyRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12447 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12448 | copyRegion.dstSubresource.mipLevel = 0; |
| 12449 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 12450 | copyRegion.dstSubresource.layerCount = 0; |
| 12451 | copyRegion.dstOffset.x = 0; |
| 12452 | copyRegion.dstOffset.y = 0; |
| 12453 | copyRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12454 | copyRegion.extent.width = 1; |
| 12455 | copyRegion.extent.height = 1; |
| 12456 | copyRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12457 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12458 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12459 | EndCommandBuffer(); |
| 12460 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12461 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12462 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12463 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12464 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12465 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12466 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12467 | } |
| 12468 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12469 | TEST_F(VkLayerTest, ResolveImageLowSampleCount) { |
| 12470 | VkResult err; |
| 12471 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12472 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12473 | m_errorMonitor->SetDesiredFailureMsg( |
| 12474 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12475 | "vkCmdResolveImage called with source sample count less than 2."); |
| 12476 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12477 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12478 | |
| 12479 | // 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] | 12480 | VkImage srcImage; |
| 12481 | VkImage dstImage; |
| 12482 | VkDeviceMemory srcMem; |
| 12483 | VkDeviceMemory destMem; |
| 12484 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12485 | |
| 12486 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12487 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12488 | image_create_info.pNext = NULL; |
| 12489 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12490 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12491 | image_create_info.extent.width = 32; |
| 12492 | image_create_info.extent.height = 1; |
| 12493 | image_create_info.extent.depth = 1; |
| 12494 | image_create_info.mipLevels = 1; |
| 12495 | image_create_info.arrayLayers = 1; |
| 12496 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12497 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12498 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 12499 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12500 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12501 | err = |
| 12502 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12503 | ASSERT_VK_SUCCESS(err); |
| 12504 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12505 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12506 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12507 | err = |
| 12508 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12509 | ASSERT_VK_SUCCESS(err); |
| 12510 | |
| 12511 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12512 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12513 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12514 | memAlloc.pNext = NULL; |
| 12515 | memAlloc.allocationSize = 0; |
| 12516 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12517 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12518 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12519 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12520 | pass = |
| 12521 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12522 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12523 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12524 | ASSERT_VK_SUCCESS(err); |
| 12525 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12526 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12527 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12528 | pass = |
| 12529 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12530 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12531 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12532 | ASSERT_VK_SUCCESS(err); |
| 12533 | |
| 12534 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12535 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12536 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12537 | ASSERT_VK_SUCCESS(err); |
| 12538 | |
| 12539 | BeginCommandBuffer(); |
| 12540 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12541 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12542 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12543 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12544 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12545 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12546 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12547 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12548 | resolveRegion.srcOffset.x = 0; |
| 12549 | resolveRegion.srcOffset.y = 0; |
| 12550 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12551 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12552 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12553 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12554 | resolveRegion.dstSubresource.layerCount = 0; |
| 12555 | resolveRegion.dstOffset.x = 0; |
| 12556 | resolveRegion.dstOffset.y = 0; |
| 12557 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12558 | resolveRegion.extent.width = 1; |
| 12559 | resolveRegion.extent.height = 1; |
| 12560 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12561 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12562 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12563 | EndCommandBuffer(); |
| 12564 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12565 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12566 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12567 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12568 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12569 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12570 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12571 | } |
| 12572 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12573 | TEST_F(VkLayerTest, ResolveImageHighSampleCount) { |
| 12574 | VkResult err; |
| 12575 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12576 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12577 | m_errorMonitor->SetDesiredFailureMsg( |
| 12578 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12579 | "vkCmdResolveImage called with dest sample count greater than 1."); |
| 12580 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12581 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12582 | |
Chris Forbes | a753069 | 2016-05-08 12:35:39 +1200 | [diff] [blame] | 12583 | // 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] | 12584 | VkImage srcImage; |
| 12585 | VkImage dstImage; |
| 12586 | VkDeviceMemory srcMem; |
| 12587 | VkDeviceMemory destMem; |
| 12588 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12589 | |
| 12590 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12591 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12592 | image_create_info.pNext = NULL; |
| 12593 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12594 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12595 | image_create_info.extent.width = 32; |
| 12596 | image_create_info.extent.height = 1; |
| 12597 | image_create_info.extent.depth = 1; |
| 12598 | image_create_info.mipLevels = 1; |
| 12599 | image_create_info.arrayLayers = 1; |
Chris Forbes | a753069 | 2016-05-08 12:35:39 +1200 | [diff] [blame] | 12600 | image_create_info.samples = VK_SAMPLE_COUNT_4_BIT; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12601 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12602 | // Note: Some implementations expect color attachment usage for any |
| 12603 | // multisample surface |
| 12604 | image_create_info.usage = |
| 12605 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12606 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12607 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12608 | err = |
| 12609 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12610 | ASSERT_VK_SUCCESS(err); |
| 12611 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12612 | // Note: Some implementations expect color attachment usage for any |
| 12613 | // multisample surface |
| 12614 | image_create_info.usage = |
| 12615 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12616 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12617 | err = |
| 12618 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12619 | ASSERT_VK_SUCCESS(err); |
| 12620 | |
| 12621 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12622 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12623 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12624 | memAlloc.pNext = NULL; |
| 12625 | memAlloc.allocationSize = 0; |
| 12626 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12627 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12628 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12629 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12630 | pass = |
| 12631 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12632 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12633 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12634 | ASSERT_VK_SUCCESS(err); |
| 12635 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12636 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12637 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12638 | pass = |
| 12639 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12640 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12641 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12642 | ASSERT_VK_SUCCESS(err); |
| 12643 | |
| 12644 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12645 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12646 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12647 | ASSERT_VK_SUCCESS(err); |
| 12648 | |
| 12649 | BeginCommandBuffer(); |
| 12650 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12651 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12652 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12653 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12654 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12655 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12656 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12657 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12658 | resolveRegion.srcOffset.x = 0; |
| 12659 | resolveRegion.srcOffset.y = 0; |
| 12660 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12661 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12662 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12663 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12664 | resolveRegion.dstSubresource.layerCount = 0; |
| 12665 | resolveRegion.dstOffset.x = 0; |
| 12666 | resolveRegion.dstOffset.y = 0; |
| 12667 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12668 | resolveRegion.extent.width = 1; |
| 12669 | resolveRegion.extent.height = 1; |
| 12670 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12671 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12672 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12673 | EndCommandBuffer(); |
| 12674 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12675 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12676 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12677 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12678 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12679 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12680 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12681 | } |
| 12682 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12683 | TEST_F(VkLayerTest, ResolveImageFormatMismatch) { |
| 12684 | VkResult err; |
| 12685 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12686 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12687 | m_errorMonitor->SetDesiredFailureMsg( |
| 12688 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12689 | "vkCmdResolveImage called with unmatched source and dest formats."); |
| 12690 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12691 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12692 | |
| 12693 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12694 | VkImage srcImage; |
| 12695 | VkImage dstImage; |
| 12696 | VkDeviceMemory srcMem; |
| 12697 | VkDeviceMemory destMem; |
| 12698 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12699 | |
| 12700 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12701 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12702 | image_create_info.pNext = NULL; |
| 12703 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12704 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12705 | image_create_info.extent.width = 32; |
| 12706 | image_create_info.extent.height = 1; |
| 12707 | image_create_info.extent.depth = 1; |
| 12708 | image_create_info.mipLevels = 1; |
| 12709 | image_create_info.arrayLayers = 1; |
| 12710 | image_create_info.samples = VK_SAMPLE_COUNT_2_BIT; |
| 12711 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12712 | // Note: Some implementations expect color attachment usage for any |
| 12713 | // multisample surface |
| 12714 | image_create_info.usage = |
| 12715 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12716 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12717 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12718 | err = |
| 12719 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12720 | ASSERT_VK_SUCCESS(err); |
| 12721 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12722 | // Set format to something other than source image |
| 12723 | image_create_info.format = VK_FORMAT_R32_SFLOAT; |
| 12724 | // Note: Some implementations expect color attachment usage for any |
| 12725 | // multisample surface |
| 12726 | image_create_info.usage = |
| 12727 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12728 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12729 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12730 | err = |
| 12731 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12732 | ASSERT_VK_SUCCESS(err); |
| 12733 | |
| 12734 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12735 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12736 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12737 | memAlloc.pNext = NULL; |
| 12738 | memAlloc.allocationSize = 0; |
| 12739 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12740 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12741 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12742 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12743 | pass = |
| 12744 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12745 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12746 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12747 | ASSERT_VK_SUCCESS(err); |
| 12748 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12749 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12750 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12751 | pass = |
| 12752 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12753 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12754 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12755 | ASSERT_VK_SUCCESS(err); |
| 12756 | |
| 12757 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12758 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12759 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12760 | ASSERT_VK_SUCCESS(err); |
| 12761 | |
| 12762 | BeginCommandBuffer(); |
| 12763 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12764 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12765 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12766 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12767 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12768 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12769 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12770 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12771 | resolveRegion.srcOffset.x = 0; |
| 12772 | resolveRegion.srcOffset.y = 0; |
| 12773 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12774 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12775 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12776 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12777 | resolveRegion.dstSubresource.layerCount = 0; |
| 12778 | resolveRegion.dstOffset.x = 0; |
| 12779 | resolveRegion.dstOffset.y = 0; |
| 12780 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12781 | resolveRegion.extent.width = 1; |
| 12782 | resolveRegion.extent.height = 1; |
| 12783 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12784 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12785 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12786 | EndCommandBuffer(); |
| 12787 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12788 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12789 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12790 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12791 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12792 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12793 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12794 | } |
| 12795 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12796 | TEST_F(VkLayerTest, ResolveImageTypeMismatch) { |
| 12797 | VkResult err; |
| 12798 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12799 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12800 | m_errorMonitor->SetDesiredFailureMsg( |
| 12801 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12802 | "vkCmdResolveImage called with unmatched source and dest image types."); |
| 12803 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12804 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12805 | |
| 12806 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12807 | VkImage srcImage; |
| 12808 | VkImage dstImage; |
| 12809 | VkDeviceMemory srcMem; |
| 12810 | VkDeviceMemory destMem; |
| 12811 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12812 | |
| 12813 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12814 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12815 | image_create_info.pNext = NULL; |
| 12816 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12817 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12818 | image_create_info.extent.width = 32; |
| 12819 | image_create_info.extent.height = 1; |
| 12820 | image_create_info.extent.depth = 1; |
| 12821 | image_create_info.mipLevels = 1; |
| 12822 | image_create_info.arrayLayers = 1; |
| 12823 | image_create_info.samples = VK_SAMPLE_COUNT_2_BIT; |
| 12824 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12825 | // Note: Some implementations expect color attachment usage for any |
| 12826 | // multisample surface |
| 12827 | image_create_info.usage = |
| 12828 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12829 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12830 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12831 | err = |
| 12832 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12833 | ASSERT_VK_SUCCESS(err); |
| 12834 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12835 | image_create_info.imageType = VK_IMAGE_TYPE_1D; |
| 12836 | // Note: Some implementations expect color attachment usage for any |
| 12837 | // multisample surface |
| 12838 | image_create_info.usage = |
| 12839 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12840 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12841 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12842 | err = |
| 12843 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12844 | ASSERT_VK_SUCCESS(err); |
| 12845 | |
| 12846 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12847 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12848 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12849 | memAlloc.pNext = NULL; |
| 12850 | memAlloc.allocationSize = 0; |
| 12851 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12852 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12853 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12854 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12855 | pass = |
| 12856 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12857 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12858 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12859 | ASSERT_VK_SUCCESS(err); |
| 12860 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12861 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12862 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12863 | pass = |
| 12864 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12865 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12866 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12867 | ASSERT_VK_SUCCESS(err); |
| 12868 | |
| 12869 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12870 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12871 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12872 | ASSERT_VK_SUCCESS(err); |
| 12873 | |
| 12874 | BeginCommandBuffer(); |
| 12875 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12876 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12877 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12878 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12879 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12880 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12881 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12882 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12883 | resolveRegion.srcOffset.x = 0; |
| 12884 | resolveRegion.srcOffset.y = 0; |
| 12885 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12886 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12887 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12888 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12889 | resolveRegion.dstSubresource.layerCount = 0; |
| 12890 | resolveRegion.dstOffset.x = 0; |
| 12891 | resolveRegion.dstOffset.y = 0; |
| 12892 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12893 | resolveRegion.extent.width = 1; |
| 12894 | resolveRegion.extent.height = 1; |
| 12895 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12896 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12897 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12898 | EndCommandBuffer(); |
| 12899 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12900 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12901 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12902 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12903 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12904 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12905 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12906 | } |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12907 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12908 | TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) { |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12909 | // 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] | 12910 | // to using a DS format, then cause it to hit error due to COLOR_BIT not |
| 12911 | // set in aspect |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12912 | // The image format check comes 2nd in validation so we trigger it first, |
| 12913 | // 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] | 12914 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12915 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12916 | m_errorMonitor->SetDesiredFailureMsg( |
| 12917 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12918 | "Combination depth/stencil image formats can have only the "); |
| 12919 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12920 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12921 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 12922 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12923 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 12924 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12925 | |
| 12926 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12927 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 12928 | ds_pool_ci.pNext = NULL; |
| 12929 | ds_pool_ci.maxSets = 1; |
| 12930 | ds_pool_ci.poolSizeCount = 1; |
| 12931 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12932 | |
| 12933 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12934 | err = |
| 12935 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12936 | ASSERT_VK_SUCCESS(err); |
| 12937 | |
| 12938 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12939 | dsl_binding.binding = 0; |
| 12940 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 12941 | dsl_binding.descriptorCount = 1; |
| 12942 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 12943 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12944 | |
| 12945 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12946 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 12947 | ds_layout_ci.pNext = NULL; |
| 12948 | ds_layout_ci.bindingCount = 1; |
| 12949 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12950 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12951 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 12952 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12953 | ASSERT_VK_SUCCESS(err); |
| 12954 | |
| 12955 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12956 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 12957 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 12958 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12959 | alloc_info.descriptorPool = ds_pool; |
| 12960 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12961 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 12962 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12963 | ASSERT_VK_SUCCESS(err); |
| 12964 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12965 | VkImage image_bad; |
| 12966 | VkImage image_good; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12967 | // One bad format and one good format for Color attachment |
Tobin Ehlis | 269f032 | 2016-05-25 16:24:21 -0600 | [diff] [blame] | 12968 | const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12969 | const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12970 | const int32_t tex_width = 32; |
| 12971 | const int32_t tex_height = 32; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12972 | |
| 12973 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12974 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12975 | image_create_info.pNext = NULL; |
| 12976 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12977 | image_create_info.format = tex_format_bad; |
| 12978 | image_create_info.extent.width = tex_width; |
| 12979 | image_create_info.extent.height = tex_height; |
| 12980 | image_create_info.extent.depth = 1; |
| 12981 | image_create_info.mipLevels = 1; |
| 12982 | image_create_info.arrayLayers = 1; |
| 12983 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12984 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12985 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | |
| 12986 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 12987 | image_create_info.flags = 0; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12988 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12989 | err = |
| 12990 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12991 | ASSERT_VK_SUCCESS(err); |
| 12992 | image_create_info.format = tex_format_good; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12993 | image_create_info.usage = |
| 12994 | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12995 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, |
| 12996 | &image_good); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12997 | ASSERT_VK_SUCCESS(err); |
| 12998 | |
| 12999 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13000 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 13001 | image_view_create_info.image = image_bad; |
| 13002 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 13003 | image_view_create_info.format = tex_format_bad; |
| 13004 | image_view_create_info.subresourceRange.baseArrayLayer = 0; |
| 13005 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 13006 | image_view_create_info.subresourceRange.layerCount = 1; |
| 13007 | image_view_create_info.subresourceRange.levelCount = 1; |
| 13008 | image_view_create_info.subresourceRange.aspectMask = |
| 13009 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13010 | |
| 13011 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 13012 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 13013 | &view); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 13014 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 13015 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13016 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13017 | vkDestroyImage(m_device->device(), image_bad, NULL); |
| 13018 | vkDestroyImage(m_device->device(), image_good, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 13019 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 13020 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 13021 | } |
Tobin Ehlis | 6e23d77 | 2016-05-19 11:08:34 -0600 | [diff] [blame] | 13022 | |
| 13023 | TEST_F(VkLayerTest, ClearImageErrors) { |
| 13024 | TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and " |
| 13025 | "ClearDepthStencilImage with a color image."); |
| 13026 | |
| 13027 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 13028 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 13029 | |
| 13030 | // Renderpass is started here so end it as Clear cmds can't be in renderpass |
| 13031 | BeginCommandBuffer(); |
| 13032 | m_commandBuffer->EndRenderPass(); |
| 13033 | |
| 13034 | // Color image |
| 13035 | VkClearColorValue clear_color; |
| 13036 | memset(clear_color.uint32, 0, sizeof(uint32_t) * 4); |
| 13037 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 13038 | const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 13039 | const int32_t img_width = 32; |
| 13040 | const int32_t img_height = 32; |
| 13041 | VkImageCreateInfo image_create_info = {}; |
| 13042 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 13043 | image_create_info.pNext = NULL; |
| 13044 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 13045 | image_create_info.format = color_format; |
| 13046 | image_create_info.extent.width = img_width; |
| 13047 | image_create_info.extent.height = img_height; |
| 13048 | image_create_info.extent.depth = 1; |
| 13049 | image_create_info.mipLevels = 1; |
| 13050 | image_create_info.arrayLayers = 1; |
| 13051 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 13052 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 13053 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 13054 | |
| 13055 | vk_testing::Image color_image; |
| 13056 | color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 13057 | reqs); |
| 13058 | |
| 13059 | const VkImageSubresourceRange color_range = |
| 13060 | vk_testing::Image::subresource_range(image_create_info, |
| 13061 | VK_IMAGE_ASPECT_COLOR_BIT); |
| 13062 | |
| 13063 | // Depth/Stencil image |
| 13064 | VkClearDepthStencilValue clear_value = {0}; |
| 13065 | reqs = 0; // don't need HOST_VISIBLE DS image |
| 13066 | VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info(); |
| 13067 | ds_image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 13068 | ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 13069 | ds_image_create_info.extent.width = 64; |
| 13070 | ds_image_create_info.extent.height = 64; |
| 13071 | ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 13072 | ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 13073 | |
| 13074 | vk_testing::Image ds_image; |
| 13075 | ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, |
| 13076 | reqs); |
| 13077 | |
| 13078 | const VkImageSubresourceRange ds_range = |
| 13079 | vk_testing::Image::subresource_range(ds_image_create_info, |
| 13080 | VK_IMAGE_ASPECT_DEPTH_BIT); |
| 13081 | |
| 13082 | m_errorMonitor->SetDesiredFailureMsg( |
| 13083 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13084 | "vkCmdClearColorImage called with depth/stencil image."); |
| 13085 | |
| 13086 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), |
| 13087 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, |
| 13088 | &color_range); |
| 13089 | |
| 13090 | m_errorMonitor->VerifyFound(); |
| 13091 | |
Tony Barbour | 26434b9 | 2016-06-02 09:43:50 -0600 | [diff] [blame] | 13092 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13093 | "vkCmdClearColorImage called with " |
| 13094 | "image created without " |
| 13095 | "VK_IMAGE_USAGE_TRANSFER_DST_BIT"); |
| 13096 | |
| 13097 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), |
| 13098 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, |
| 13099 | &color_range); |
| 13100 | |
| 13101 | m_errorMonitor->VerifyFound(); |
| 13102 | |
Tobin Ehlis | 6e23d77 | 2016-05-19 11:08:34 -0600 | [diff] [blame] | 13103 | // Call CmdClearDepthStencilImage with color image |
| 13104 | m_errorMonitor->SetDesiredFailureMsg( |
| 13105 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 13106 | "vkCmdClearDepthStencilImage called without a depth/stencil image."); |
| 13107 | |
| 13108 | vkCmdClearDepthStencilImage( |
| 13109 | m_commandBuffer->GetBufferHandle(), color_image.handle(), |
| 13110 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, |
| 13111 | &ds_range); |
| 13112 | |
| 13113 | m_errorMonitor->VerifyFound(); |
| 13114 | } |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 13115 | #endif // IMAGE_TESTS |
| 13116 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 13117 | int main(int argc, char **argv) { |
| 13118 | int result; |
| 13119 | |
Cody Northrop | 8e54a40 | 2016-03-08 22:25:52 -0700 | [diff] [blame] | 13120 | #ifdef ANDROID |
| 13121 | int vulkanSupport = InitVulkan(); |
| 13122 | if (vulkanSupport == 0) |
| 13123 | return 1; |
| 13124 | #endif |
| 13125 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 13126 | ::testing::InitGoogleTest(&argc, argv); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 13127 | VkTestFramework::InitArgs(&argc, argv); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 13128 | |
| 13129 | ::testing::AddGlobalTestEnvironment(new TestEnvironment); |
| 13130 | |
| 13131 | result = RUN_ALL_TESTS(); |
| 13132 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 13133 | VkTestFramework::Finish(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 13134 | return result; |
| 13135 | } |