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 | } |
Tobin Ehlis | 93d57e1 | 2016-06-20 11:32:13 -0600 | [diff] [blame] | 2796 | #if 0 // Disabling this test for now, needs to be updated |
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 | |
| 2803 | m_errorMonitor->SetDesiredFailureMsg( |
| 2804 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2805 | "for this object type are not compatible with the memory"); |
| 2806 | |
| 2807 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2808 | |
| 2809 | // Create an image, allocate memory, set a bad typeIndex and then try to |
| 2810 | // bind it |
| 2811 | VkImage image; |
| 2812 | VkDeviceMemory mem; |
| 2813 | VkMemoryRequirements mem_reqs; |
| 2814 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2815 | const int32_t tex_width = 32; |
| 2816 | const int32_t tex_height = 32; |
| 2817 | |
| 2818 | VkImageCreateInfo image_create_info = {}; |
| 2819 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2820 | image_create_info.pNext = NULL; |
| 2821 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2822 | image_create_info.format = tex_format; |
| 2823 | image_create_info.extent.width = tex_width; |
| 2824 | image_create_info.extent.height = tex_height; |
| 2825 | image_create_info.extent.depth = 1; |
| 2826 | image_create_info.mipLevels = 1; |
| 2827 | image_create_info.arrayLayers = 1; |
| 2828 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2829 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 2830 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2831 | image_create_info.flags = 0; |
| 2832 | |
| 2833 | VkMemoryAllocateInfo mem_alloc = {}; |
| 2834 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2835 | mem_alloc.pNext = NULL; |
| 2836 | mem_alloc.allocationSize = 0; |
| 2837 | mem_alloc.memoryTypeIndex = 0; |
| 2838 | |
| 2839 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 2840 | ASSERT_VK_SUCCESS(err); |
| 2841 | |
| 2842 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 2843 | mem_alloc.allocationSize = mem_reqs.size; |
Tobin Ehlis | 93d57e1 | 2016-06-20 11:32:13 -0600 | [diff] [blame] | 2844 | // TODO : This is not an ideal way to cause the error and triggers a segF |
| 2845 | // on at least one android driver when attempting to Allocate the memory. |
| 2846 | // That segF may or may not be a driver bug, but really what we want to do |
| 2847 | // here is find a device-supported memory type that is also not supported |
| 2848 | // for the particular image we're binding the memory too. If no such |
| 2849 | // type exists, then we can print a message and skip the test. |
Mark Lobodzinski | bc18576 | 2016-06-15 16:28:53 -0600 | [diff] [blame] | 2850 | // Introduce Failure, select likely invalid TypeIndex |
| 2851 | mem_alloc.memoryTypeIndex = 31; |
| 2852 | |
| 2853 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 2854 | ASSERT_VK_SUCCESS(err); |
| 2855 | |
| 2856 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 2857 | (void)err; |
| 2858 | |
| 2859 | m_errorMonitor->VerifyFound(); |
| 2860 | |
| 2861 | vkDestroyImage(m_device->device(), image, NULL); |
| 2862 | vkFreeMemory(m_device->device(), mem, NULL); |
| 2863 | } |
Tobin Ehlis | 93d57e1 | 2016-06-20 11:32:13 -0600 | [diff] [blame] | 2864 | #endif |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2865 | TEST_F(VkLayerTest, BindInvalidMemory) { |
| 2866 | VkResult err; |
| 2867 | bool pass; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2868 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2869 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2870 | "Invalid VkDeviceMemory Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2871 | |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2872 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2873 | |
| 2874 | // 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] | 2875 | VkImage image; |
| 2876 | VkDeviceMemory mem; |
| 2877 | VkMemoryRequirements mem_reqs; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2878 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2879 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2880 | const int32_t tex_width = 32; |
| 2881 | const int32_t tex_height = 32; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2882 | |
| 2883 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2884 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2885 | image_create_info.pNext = NULL; |
| 2886 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2887 | image_create_info.format = tex_format; |
| 2888 | image_create_info.extent.width = tex_width; |
| 2889 | image_create_info.extent.height = tex_height; |
| 2890 | image_create_info.extent.depth = 1; |
| 2891 | image_create_info.mipLevels = 1; |
| 2892 | image_create_info.arrayLayers = 1; |
| 2893 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2894 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2895 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2896 | image_create_info.flags = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2897 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2898 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2899 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2900 | mem_alloc.pNext = NULL; |
| 2901 | mem_alloc.allocationSize = 0; |
| 2902 | mem_alloc.memoryTypeIndex = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2903 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2904 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2905 | ASSERT_VK_SUCCESS(err); |
| 2906 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2907 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2908 | |
| 2909 | mem_alloc.allocationSize = mem_reqs.size; |
| 2910 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2911 | pass = |
| 2912 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 2913 | ASSERT_TRUE(pass); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2914 | |
| 2915 | // allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2916 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2917 | ASSERT_VK_SUCCESS(err); |
| 2918 | |
| 2919 | // Introduce validation failure, free memory before binding |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2920 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2921 | |
| 2922 | // Try to bind free memory that has been freed |
| 2923 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 2924 | // This may very well return an error. |
| 2925 | (void)err; |
| 2926 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2927 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2928 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2929 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2930 | } |
| 2931 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2932 | TEST_F(VkLayerTest, BindMemoryToDestroyedObject) { |
| 2933 | VkResult err; |
| 2934 | bool pass; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2935 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2936 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2937 | "Invalid VkImage Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2938 | |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2939 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2940 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2941 | // Create an image object, allocate memory, destroy the object and then try |
| 2942 | // to bind it |
| 2943 | VkImage image; |
| 2944 | VkDeviceMemory mem; |
| 2945 | VkMemoryRequirements mem_reqs; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2946 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2947 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2948 | const int32_t tex_width = 32; |
| 2949 | const int32_t tex_height = 32; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2950 | |
| 2951 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2952 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2953 | image_create_info.pNext = NULL; |
| 2954 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2955 | image_create_info.format = tex_format; |
| 2956 | image_create_info.extent.width = tex_width; |
| 2957 | image_create_info.extent.height = tex_height; |
| 2958 | image_create_info.extent.depth = 1; |
| 2959 | image_create_info.mipLevels = 1; |
| 2960 | image_create_info.arrayLayers = 1; |
| 2961 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2962 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2963 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2964 | image_create_info.flags = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2965 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2966 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2967 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2968 | mem_alloc.pNext = NULL; |
| 2969 | mem_alloc.allocationSize = 0; |
| 2970 | mem_alloc.memoryTypeIndex = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2971 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2972 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2973 | ASSERT_VK_SUCCESS(err); |
| 2974 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2975 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2976 | |
| 2977 | mem_alloc.allocationSize = mem_reqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2978 | pass = |
| 2979 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 2980 | ASSERT_TRUE(pass); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2981 | |
| 2982 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2983 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2984 | ASSERT_VK_SUCCESS(err); |
| 2985 | |
| 2986 | // Introduce validation failure, destroy Image object before binding |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2987 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2988 | ASSERT_VK_SUCCESS(err); |
| 2989 | |
| 2990 | // Now Try to bind memory to this destroyed object |
| 2991 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 2992 | // This may very well return an error. |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2993 | (void)err; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2994 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2995 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2996 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2997 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2998 | } |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 2999 | |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 3000 | #endif // OBJ_TRACKER_TESTS |
| 3001 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 3002 | #if DRAW_STATE_TESTS |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3003 | |
Mark Lobodzinski | ce7eee7 | 2016-06-14 16:33:29 -0600 | [diff] [blame] | 3004 | // This is a positive test. No errors are expected. |
| 3005 | TEST_F(VkLayerTest, StencilLoadOp) { |
| 3006 | TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to " |
| 3007 | "CLEAR. stencil[Load|Store]Op used to be ignored."); |
| 3008 | VkResult result = VK_SUCCESS; |
| 3009 | VkImageFormatProperties formatProps; |
| 3010 | vkGetPhysicalDeviceImageFormatProperties( |
| 3011 | gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, |
| 3012 | VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 3013 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, |
| 3014 | 0, &formatProps); |
| 3015 | if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) { |
| 3016 | return; |
| 3017 | } |
| 3018 | |
| 3019 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3020 | VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT; |
| 3021 | m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt, |
| 3022 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 3023 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT); |
| 3024 | VkAttachmentDescription att = {}; |
| 3025 | VkAttachmentReference ref = {}; |
| 3026 | att.format = depth_stencil_fmt; |
| 3027 | att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 3028 | att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 3029 | att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 3030 | att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE; |
| 3031 | att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3032 | att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3033 | |
| 3034 | VkClearValue clear; |
| 3035 | clear.depthStencil.depth = 1.0; |
| 3036 | clear.depthStencil.stencil = 0; |
| 3037 | ref.attachment = 0; |
| 3038 | ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3039 | |
| 3040 | VkSubpassDescription subpass = {}; |
| 3041 | subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; |
| 3042 | subpass.flags = 0; |
| 3043 | subpass.inputAttachmentCount = 0; |
| 3044 | subpass.pInputAttachments = NULL; |
| 3045 | subpass.colorAttachmentCount = 0; |
| 3046 | subpass.pColorAttachments = NULL; |
| 3047 | subpass.pResolveAttachments = NULL; |
| 3048 | subpass.pDepthStencilAttachment = &ref; |
| 3049 | subpass.preserveAttachmentCount = 0; |
| 3050 | subpass.pPreserveAttachments = NULL; |
| 3051 | |
| 3052 | VkRenderPass rp; |
| 3053 | VkRenderPassCreateInfo rp_info = {}; |
| 3054 | rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 3055 | rp_info.attachmentCount = 1; |
| 3056 | rp_info.pAttachments = &att; |
| 3057 | rp_info.subpassCount = 1; |
| 3058 | rp_info.pSubpasses = &subpass; |
| 3059 | result = vkCreateRenderPass(device(), &rp_info, NULL, &rp); |
| 3060 | ASSERT_VK_SUCCESS(result); |
| 3061 | |
| 3062 | VkImageView *depthView = m_depthStencil->BindInfo(); |
| 3063 | VkFramebufferCreateInfo fb_info = {}; |
| 3064 | fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
| 3065 | fb_info.pNext = NULL; |
| 3066 | fb_info.renderPass = rp; |
| 3067 | fb_info.attachmentCount = 1; |
| 3068 | fb_info.pAttachments = depthView; |
| 3069 | fb_info.width = 100; |
| 3070 | fb_info.height = 100; |
| 3071 | fb_info.layers = 1; |
| 3072 | VkFramebuffer fb; |
| 3073 | result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3074 | ASSERT_VK_SUCCESS(result); |
| 3075 | |
| 3076 | |
| 3077 | VkRenderPassBeginInfo rpbinfo = {}; |
| 3078 | rpbinfo.clearValueCount = 1; |
| 3079 | rpbinfo.pClearValues = &clear; |
| 3080 | rpbinfo.pNext = NULL; |
| 3081 | rpbinfo.renderPass = rp; |
| 3082 | rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 3083 | rpbinfo.renderArea.extent.width = 100; |
| 3084 | rpbinfo.renderArea.extent.height = 100; |
| 3085 | rpbinfo.renderArea.offset.x = 0; |
| 3086 | rpbinfo.renderArea.offset.y = 0; |
| 3087 | rpbinfo.framebuffer = fb; |
| 3088 | |
| 3089 | VkFence fence = {}; |
| 3090 | VkFenceCreateInfo fence_ci = {}; |
| 3091 | fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3092 | fence_ci.pNext = nullptr; |
| 3093 | fence_ci.flags = 0; |
| 3094 | result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence); |
| 3095 | ASSERT_VK_SUCCESS(result); |
| 3096 | |
| 3097 | |
| 3098 | m_commandBuffer->BeginCommandBuffer(); |
| 3099 | m_commandBuffer->BeginRenderPass(rpbinfo); |
| 3100 | m_commandBuffer->EndRenderPass(); |
| 3101 | m_commandBuffer->EndCommandBuffer(); |
| 3102 | m_commandBuffer->QueueCommandBuffer(fence); |
| 3103 | |
| 3104 | VkImageObj destImage(m_device); |
| 3105 | destImage.init(100, 100, depth_stencil_fmt, |
| 3106 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 3107 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 3108 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 3109 | VkImageMemoryBarrier barrier = {}; |
| 3110 | VkImageSubresourceRange range; |
| 3111 | barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 3112 | barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | |
| 3113 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; |
| 3114 | barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | |
| 3115 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT; |
| 3116 | barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3117 | barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 3118 | barrier.image = m_depthStencil->handle(); |
| 3119 | range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3120 | range.baseMipLevel = 0; |
| 3121 | range.levelCount = 1; |
| 3122 | range.baseArrayLayer = 0; |
| 3123 | range.layerCount = 1; |
| 3124 | barrier.subresourceRange = range; |
| 3125 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 3126 | VkCommandBufferObj cmdbuf(m_device, m_commandPool); |
| 3127 | cmdbuf.BeginCommandBuffer(); |
| 3128 | cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3129 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, |
| 3130 | nullptr, 1, &barrier); |
| 3131 | barrier.srcAccessMask = 0; |
| 3132 | barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 3133 | barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; |
| 3134 | barrier.image = destImage.handle(); |
| 3135 | barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | |
| 3136 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; |
| 3137 | cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3138 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, |
| 3139 | nullptr, 1, &barrier); |
| 3140 | VkImageCopy cregion; |
| 3141 | cregion.srcSubresource.aspectMask = |
| 3142 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3143 | cregion.srcSubresource.mipLevel = 0; |
| 3144 | cregion.srcSubresource.baseArrayLayer = 0; |
| 3145 | cregion.srcSubresource.layerCount = 1; |
| 3146 | cregion.srcOffset.x = 0; |
| 3147 | cregion.srcOffset.y = 0; |
| 3148 | cregion.srcOffset.z = 0; |
| 3149 | cregion.dstSubresource.aspectMask = |
| 3150 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3151 | cregion.dstSubresource.mipLevel = 0; |
| 3152 | cregion.dstSubresource.baseArrayLayer = 0; |
| 3153 | cregion.dstSubresource.layerCount = 1; |
| 3154 | cregion.dstOffset.x = 0; |
| 3155 | cregion.dstOffset.y = 0; |
| 3156 | cregion.dstOffset.z = 0; |
| 3157 | cregion.extent.width = 100; |
| 3158 | cregion.extent.height = 100; |
| 3159 | cregion.extent.depth = 1; |
| 3160 | cmdbuf.CopyImage(m_depthStencil->handle(), |
| 3161 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(), |
| 3162 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion); |
| 3163 | cmdbuf.EndCommandBuffer(); |
| 3164 | |
| 3165 | VkSubmitInfo submit_info; |
| 3166 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3167 | submit_info.pNext = NULL; |
| 3168 | submit_info.waitSemaphoreCount = 0; |
| 3169 | submit_info.pWaitSemaphores = NULL; |
| 3170 | submit_info.pWaitDstStageMask = NULL; |
| 3171 | submit_info.commandBufferCount = 1; |
| 3172 | submit_info.pCommandBuffers = &cmdbuf.handle(); |
| 3173 | submit_info.signalSemaphoreCount = 0; |
| 3174 | submit_info.pSignalSemaphores = NULL; |
| 3175 | |
| 3176 | m_errorMonitor->ExpectSuccess(); |
| 3177 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3178 | m_errorMonitor->VerifyNotFound(); |
| 3179 | |
Mark Lobodzinski | d0440da | 2016-06-17 15:10:03 -0600 | [diff] [blame] | 3180 | vkQueueWaitIdle(m_device->m_queue); |
Mark Lobodzinski | ce7eee7 | 2016-06-14 16:33:29 -0600 | [diff] [blame] | 3181 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 3182 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3183 | vkDestroyFramebuffer(m_device->device(), fb, nullptr); |
| 3184 | } |
| 3185 | |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3186 | TEST_F(VkLayerTest, UnusedPreserveAttachment) { |
| 3187 | TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve " |
| 3188 | "attachment reference of VK_ATTACHMENT_UNUSED"); |
| 3189 | |
| 3190 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3191 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 3192 | |
| 3193 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3194 | "must not be VK_ATTACHMENT_UNUSED"); |
| 3195 | |
| 3196 | VkAttachmentReference color_attach = {}; |
| 3197 | color_attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 3198 | color_attach.attachment = 0; |
| 3199 | uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED; |
| 3200 | VkSubpassDescription subpass = {}; |
| 3201 | subpass.colorAttachmentCount = 1; |
| 3202 | subpass.pColorAttachments = &color_attach; |
| 3203 | subpass.preserveAttachmentCount = 1; |
| 3204 | subpass.pPreserveAttachments = &preserve_attachment; |
| 3205 | |
| 3206 | VkRenderPassCreateInfo rpci = {}; |
| 3207 | rpci.subpassCount = 1; |
| 3208 | rpci.pSubpasses = &subpass; |
| 3209 | rpci.attachmentCount = 1; |
| 3210 | VkAttachmentDescription attach_desc = {}; |
| 3211 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 3212 | rpci.pAttachments = &attach_desc; |
| 3213 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 3214 | VkRenderPass rp; |
Mark Lobodzinski | a4feeeb | 2016-06-17 12:00:46 -0600 | [diff] [blame] | 3215 | VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3216 | |
| 3217 | m_errorMonitor->VerifyFound(); |
| 3218 | |
Mark Lobodzinski | a4feeeb | 2016-06-17 12:00:46 -0600 | [diff] [blame] | 3219 | if (result == VK_SUCCESS) { |
| 3220 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 3221 | } |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3222 | } |
| 3223 | |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3224 | TEST_F(VkLayerTest, FramebufferCreateErrors) { |
| 3225 | TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n" |
| 3226 | " 1. Mismatch between fb & renderPass attachmentCount\n" |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 3227 | " 2. Use a color image as depthStencil attachment\n" |
Tobin Ehlis | 77d717c | 2016-06-22 14:19:19 -0600 | [diff] [blame] | 3228 | " 3. Mismatch fb & renderPass attachment formats\n" |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 3229 | " 4. Mismatch fb & renderPass attachment #samples\n" |
Tobin Ehlis | 27f2ae8 | 2016-06-23 07:36:57 -0600 | [diff] [blame] | 3230 | " 5. FB attachment w/ non-1 mip-levels\n" |
Tobin Ehlis | b1f303b | 2016-06-23 08:19:55 -0600 | [diff] [blame] | 3231 | " 6. FB attachment where dimensions don't match\n" |
Tobin Ehlis | 08d4b5e | 2016-06-23 08:52:39 -0600 | [diff] [blame] | 3232 | " 7. FB attachment w/o identity swizzle\n" |
| 3233 | " 8. FB dimensions exceed physical device limits\n"); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3234 | |
| 3235 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3236 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 3237 | |
| 3238 | m_errorMonitor->SetDesiredFailureMsg( |
| 3239 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3240 | "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 " |
| 3241 | "does not match attachmentCount of 1 of "); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3242 | |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3243 | // Create a renderPass with a single color attachment |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3244 | VkAttachmentReference attach = {}; |
| 3245 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 3246 | VkSubpassDescription subpass = {}; |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3247 | subpass.pColorAttachments = &attach; |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3248 | VkRenderPassCreateInfo rpci = {}; |
| 3249 | rpci.subpassCount = 1; |
| 3250 | rpci.pSubpasses = &subpass; |
| 3251 | rpci.attachmentCount = 1; |
| 3252 | VkAttachmentDescription attach_desc = {}; |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 3253 | attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM; |
Tobin Ehlis | 77d717c | 2016-06-22 14:19:19 -0600 | [diff] [blame] | 3254 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3255 | rpci.pAttachments = &attach_desc; |
| 3256 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 3257 | VkRenderPass rp; |
| 3258 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3259 | ASSERT_VK_SUCCESS(err); |
| 3260 | |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3261 | VkImageView ivs[2]; |
| 3262 | ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM); |
| 3263 | ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3264 | VkFramebufferCreateInfo fb_info = {}; |
| 3265 | fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
| 3266 | fb_info.pNext = NULL; |
| 3267 | fb_info.renderPass = rp; |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3268 | // Set mis-matching attachmentCount |
| 3269 | fb_info.attachmentCount = 2; |
| 3270 | fb_info.pAttachments = ivs; |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3271 | fb_info.width = 100; |
| 3272 | fb_info.height = 100; |
| 3273 | fb_info.layers = 1; |
| 3274 | |
| 3275 | VkFramebuffer fb; |
| 3276 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3277 | |
| 3278 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3279 | if (err == VK_SUCCESS) { |
| 3280 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3281 | } |
| 3282 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3283 | |
| 3284 | // Create a renderPass with a depth-stencil attachment created with |
| 3285 | // IMAGE_USAGE_COLOR_ATTACHMENT |
| 3286 | // Add our color attachment to pDepthStencilAttachment |
| 3287 | subpass.pDepthStencilAttachment = &attach; |
| 3288 | subpass.pColorAttachments = NULL; |
| 3289 | VkRenderPass rp_ds; |
| 3290 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds); |
| 3291 | ASSERT_VK_SUCCESS(err); |
| 3292 | // Set correct attachment count, but attachment has COLOR usage bit set |
| 3293 | fb_info.attachmentCount = 1; |
| 3294 | fb_info.renderPass = rp_ds; |
| 3295 | |
| 3296 | m_errorMonitor->SetDesiredFailureMsg( |
| 3297 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3298 | " conflicts with the image's IMAGE_USAGE flags "); |
| 3299 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3300 | |
| 3301 | m_errorMonitor->VerifyFound(); |
| 3302 | if (err == VK_SUCCESS) { |
| 3303 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3304 | } |
| 3305 | vkDestroyRenderPass(m_device->device(), rp_ds, NULL); |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 3306 | |
| 3307 | // Create new renderpass with alternate attachment format from fb |
| 3308 | attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 3309 | subpass.pDepthStencilAttachment = NULL; |
| 3310 | subpass.pColorAttachments = &attach; |
| 3311 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3312 | ASSERT_VK_SUCCESS(err); |
| 3313 | |
| 3314 | // Cause error due to mis-matched formats between rp & fb |
| 3315 | // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8 |
| 3316 | fb_info.renderPass = rp; |
| 3317 | m_errorMonitor->SetDesiredFailureMsg( |
| 3318 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3319 | " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match "); |
| 3320 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3321 | |
| 3322 | m_errorMonitor->VerifyFound(); |
| 3323 | if (err == VK_SUCCESS) { |
| 3324 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3325 | } |
Tobin Ehlis | 77d717c | 2016-06-22 14:19:19 -0600 | [diff] [blame] | 3326 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 3327 | |
| 3328 | // Create new renderpass with alternate sample count from fb |
| 3329 | attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 3330 | attach_desc.samples = VK_SAMPLE_COUNT_4_BIT; |
| 3331 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3332 | ASSERT_VK_SUCCESS(err); |
| 3333 | |
| 3334 | // Cause error due to mis-matched sample count between rp & fb |
| 3335 | fb_info.renderPass = rp; |
| 3336 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3337 | " has VK_SAMPLE_COUNT_1_BIT samples " |
| 3338 | "that do not match the " |
| 3339 | "VK_SAMPLE_COUNT_4_BIT "); |
| 3340 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3341 | |
| 3342 | m_errorMonitor->VerifyFound(); |
| 3343 | if (err == VK_SUCCESS) { |
| 3344 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3345 | } |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 3346 | |
| 3347 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 3348 | |
| 3349 | // Create a custom imageView with non-1 mip levels |
| 3350 | VkImageObj image(m_device); |
| 3351 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 3352 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 3353 | ASSERT_TRUE(image.initialized()); |
| 3354 | |
| 3355 | VkImageView view; |
| 3356 | VkImageViewCreateInfo ivci = {}; |
| 3357 | ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 3358 | ivci.image = image.handle(); |
| 3359 | ivci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 3360 | ivci.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 3361 | ivci.subresourceRange.layerCount = 1; |
| 3362 | ivci.subresourceRange.baseMipLevel = 0; |
| 3363 | // Set level count 2 (only 1 is allowed for FB attachment) |
| 3364 | ivci.subresourceRange.levelCount = 2; |
| 3365 | ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 3366 | err = vkCreateImageView(m_device->device(), &ivci, NULL, &view); |
| 3367 | ASSERT_VK_SUCCESS(err); |
| 3368 | // Re-create renderpass to have matching sample count |
| 3369 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
| 3370 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3371 | ASSERT_VK_SUCCESS(err); |
| 3372 | |
| 3373 | fb_info.renderPass = rp; |
| 3374 | fb_info.pAttachments = &view; |
| 3375 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3376 | " has mip levelCount of 2 but only "); |
| 3377 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3378 | |
| 3379 | m_errorMonitor->VerifyFound(); |
| 3380 | if (err == VK_SUCCESS) { |
| 3381 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3382 | } |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 3383 | vkDestroyImageView(m_device->device(), view, NULL); |
Tobin Ehlis | 27f2ae8 | 2016-06-23 07:36:57 -0600 | [diff] [blame] | 3384 | // Update view to original color buffer and grow FB dimensions too big |
| 3385 | fb_info.pAttachments = ivs; |
| 3386 | fb_info.height = 1024; |
| 3387 | fb_info.width = 1024; |
| 3388 | fb_info.layers = 2; |
| 3389 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3390 | " Attachment dimensions must be at " |
| 3391 | "least as large. "); |
| 3392 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3393 | |
| 3394 | m_errorMonitor->VerifyFound(); |
| 3395 | if (err == VK_SUCCESS) { |
| 3396 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3397 | } |
Tobin Ehlis | b1f303b | 2016-06-23 08:19:55 -0600 | [diff] [blame] | 3398 | // Create view attachment with non-identity swizzle |
| 3399 | ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 3400 | ivci.image = image.handle(); |
| 3401 | ivci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 3402 | ivci.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 3403 | ivci.subresourceRange.layerCount = 1; |
| 3404 | ivci.subresourceRange.baseMipLevel = 0; |
| 3405 | ivci.subresourceRange.levelCount = 1; |
| 3406 | ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 3407 | ivci.components.r = VK_COMPONENT_SWIZZLE_G; |
| 3408 | ivci.components.g = VK_COMPONENT_SWIZZLE_R; |
| 3409 | ivci.components.b = VK_COMPONENT_SWIZZLE_A; |
| 3410 | ivci.components.a = VK_COMPONENT_SWIZZLE_B; |
| 3411 | err = vkCreateImageView(m_device->device(), &ivci, NULL, &view); |
| 3412 | ASSERT_VK_SUCCESS(err); |
| 3413 | |
| 3414 | fb_info.pAttachments = &view; |
| 3415 | fb_info.height = 100; |
| 3416 | fb_info.width = 100; |
| 3417 | fb_info.layers = 1; |
| 3418 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3419 | " has non-identy swizzle. All " |
| 3420 | "framebuffer attachments must have " |
| 3421 | "been created with the identity " |
| 3422 | "swizzle. "); |
| 3423 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3424 | |
| 3425 | m_errorMonitor->VerifyFound(); |
| 3426 | if (err == VK_SUCCESS) { |
| 3427 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3428 | } |
| 3429 | vkDestroyImageView(m_device->device(), view, NULL); |
Tobin Ehlis | 08d4b5e | 2016-06-23 08:52:39 -0600 | [diff] [blame] | 3430 | // Request fb that exceeds max dimensions |
| 3431 | // reset attachment to color attachment |
| 3432 | fb_info.pAttachments = ivs; |
| 3433 | fb_info.width = m_device->props.limits.maxFramebufferWidth + 1; |
| 3434 | fb_info.height = m_device->props.limits.maxFramebufferHeight + 1; |
| 3435 | fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1; |
| 3436 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3437 | " Requested VkFramebufferCreateInfo " |
| 3438 | "dimensions exceed physical device " |
| 3439 | "limits. "); |
| 3440 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3441 | |
| 3442 | m_errorMonitor->VerifyFound(); |
| 3443 | if (err == VK_SUCCESS) { |
| 3444 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3445 | } |
Tobin Ehlis | 27f2ae8 | 2016-06-23 07:36:57 -0600 | [diff] [blame] | 3446 | |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 3447 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3448 | } |
| 3449 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3450 | // This is a positive test. No errors should be generated. |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3451 | TEST_F(VkLayerTest, WaitEventThenSet) { |
| 3452 | TEST_DESCRIPTION( |
| 3453 | "Wait on a event then set it after the wait has been submitted."); |
| 3454 | |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3455 | m_errorMonitor->ExpectSuccess(); |
| 3456 | |
| 3457 | VkEvent event; |
| 3458 | VkEventCreateInfo event_create_info{}; |
| 3459 | event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 3460 | vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event); |
| 3461 | |
| 3462 | VkCommandPool command_pool; |
| 3463 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3464 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3465 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3466 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3467 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3468 | &command_pool); |
| 3469 | |
| 3470 | VkCommandBuffer command_buffer; |
| 3471 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3472 | command_buffer_allocate_info.sType = |
| 3473 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3474 | command_buffer_allocate_info.commandPool = command_pool; |
| 3475 | command_buffer_allocate_info.commandBufferCount = 1; |
| 3476 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3477 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3478 | &command_buffer); |
| 3479 | |
| 3480 | VkQueue queue = VK_NULL_HANDLE; |
| 3481 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
Tony Barbour | fe302c0 | 2016-06-06 13:05:19 -0600 | [diff] [blame] | 3482 | 0, &queue); |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3483 | |
| 3484 | { |
| 3485 | VkCommandBufferBeginInfo begin_info{}; |
| 3486 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3487 | vkBeginCommandBuffer(command_buffer, &begin_info); |
| 3488 | |
| 3489 | vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, |
| 3490 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, |
| 3491 | nullptr, 0, nullptr); |
| 3492 | vkCmdResetEvent(command_buffer, event, |
| 3493 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 3494 | vkEndCommandBuffer(command_buffer); |
| 3495 | } |
| 3496 | { |
| 3497 | VkSubmitInfo submit_info{}; |
| 3498 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3499 | submit_info.commandBufferCount = 1; |
| 3500 | submit_info.pCommandBuffers = &command_buffer; |
| 3501 | submit_info.signalSemaphoreCount = 0; |
| 3502 | submit_info.pSignalSemaphores = nullptr; |
| 3503 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3504 | } |
| 3505 | { vkSetEvent(m_device->device(), event); } |
| 3506 | |
| 3507 | vkQueueWaitIdle(queue); |
| 3508 | |
| 3509 | vkDestroyEvent(m_device->device(), event, nullptr); |
| 3510 | vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer); |
| 3511 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3512 | |
| 3513 | m_errorMonitor->VerifyNotFound(); |
| 3514 | } |
Michael Lentine | 5627e69 | 2016-05-20 17:45:02 -0500 | [diff] [blame] | 3515 | // This is a positive test. No errors should be generated. |
| 3516 | TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) { |
| 3517 | TEST_DESCRIPTION( |
| 3518 | "Issue a query and copy from it on a second command buffer."); |
| 3519 | |
| 3520 | if ((m_device->queue_props.empty()) || |
| 3521 | (m_device->queue_props[0].queueCount < 2)) |
| 3522 | return; |
| 3523 | |
| 3524 | m_errorMonitor->ExpectSuccess(); |
| 3525 | |
| 3526 | VkQueryPool query_pool; |
| 3527 | VkQueryPoolCreateInfo query_pool_create_info{}; |
| 3528 | query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; |
| 3529 | query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP; |
| 3530 | query_pool_create_info.queryCount = 1; |
| 3531 | vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, |
| 3532 | &query_pool); |
| 3533 | |
| 3534 | VkCommandPool command_pool; |
| 3535 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3536 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3537 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3538 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3539 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3540 | &command_pool); |
| 3541 | |
| 3542 | VkCommandBuffer command_buffer[2]; |
| 3543 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3544 | command_buffer_allocate_info.sType = |
| 3545 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3546 | command_buffer_allocate_info.commandPool = command_pool; |
| 3547 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3548 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3549 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3550 | command_buffer); |
| 3551 | |
| 3552 | VkQueue queue = VK_NULL_HANDLE; |
| 3553 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3554 | 1, &queue); |
| 3555 | |
| 3556 | uint32_t qfi = 0; |
| 3557 | VkBufferCreateInfo buff_create_info = {}; |
| 3558 | buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 3559 | buff_create_info.size = 1024; |
| 3560 | buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT; |
| 3561 | buff_create_info.queueFamilyIndexCount = 1; |
| 3562 | buff_create_info.pQueueFamilyIndices = &qfi; |
| 3563 | |
| 3564 | VkResult err; |
| 3565 | VkBuffer buffer; |
| 3566 | err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer); |
| 3567 | ASSERT_VK_SUCCESS(err); |
| 3568 | VkMemoryAllocateInfo mem_alloc = {}; |
| 3569 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 3570 | mem_alloc.pNext = NULL; |
| 3571 | mem_alloc.allocationSize = 1024; |
| 3572 | mem_alloc.memoryTypeIndex = 0; |
| 3573 | |
| 3574 | VkMemoryRequirements memReqs; |
| 3575 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs); |
| 3576 | bool pass = |
| 3577 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0); |
| 3578 | if (!pass) { |
| 3579 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 3580 | return; |
| 3581 | } |
| 3582 | |
| 3583 | VkDeviceMemory mem; |
| 3584 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 3585 | ASSERT_VK_SUCCESS(err); |
| 3586 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 3587 | ASSERT_VK_SUCCESS(err); |
| 3588 | |
| 3589 | { |
| 3590 | VkCommandBufferBeginInfo begin_info{}; |
| 3591 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3592 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3593 | |
| 3594 | vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1); |
| 3595 | vkCmdWriteTimestamp(command_buffer[0], |
| 3596 | VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0); |
| 3597 | |
| 3598 | vkEndCommandBuffer(command_buffer[0]); |
| 3599 | |
| 3600 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3601 | |
| 3602 | vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, |
| 3603 | 0, 0, 0); |
| 3604 | |
| 3605 | vkEndCommandBuffer(command_buffer[1]); |
| 3606 | } |
| 3607 | { |
| 3608 | VkSubmitInfo submit_info{}; |
| 3609 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3610 | submit_info.commandBufferCount = 2; |
| 3611 | submit_info.pCommandBuffers = command_buffer; |
| 3612 | submit_info.signalSemaphoreCount = 0; |
| 3613 | submit_info.pSignalSemaphores = nullptr; |
| 3614 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3615 | } |
| 3616 | |
| 3617 | vkQueueWaitIdle(queue); |
| 3618 | |
| 3619 | vkDestroyQueryPool(m_device->device(), query_pool, nullptr); |
| 3620 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer); |
| 3621 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 3622 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 3623 | vkFreeMemory(m_device->device(), mem, NULL); |
Michael Lentine | 5627e69 | 2016-05-20 17:45:02 -0500 | [diff] [blame] | 3624 | |
| 3625 | m_errorMonitor->VerifyNotFound(); |
| 3626 | } |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3627 | |
| 3628 | TEST_F(VkLayerTest, ResetEventThenSet) { |
| 3629 | TEST_DESCRIPTION( |
| 3630 | "Reset an event then set it after the reset has been submitted."); |
| 3631 | |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3632 | m_errorMonitor->ExpectSuccess(); |
| 3633 | |
| 3634 | VkEvent event; |
| 3635 | VkEventCreateInfo event_create_info{}; |
| 3636 | event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 3637 | vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event); |
| 3638 | |
| 3639 | VkCommandPool command_pool; |
| 3640 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3641 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3642 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3643 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3644 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3645 | &command_pool); |
| 3646 | |
| 3647 | VkCommandBuffer command_buffer; |
| 3648 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3649 | command_buffer_allocate_info.sType = |
| 3650 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3651 | command_buffer_allocate_info.commandPool = command_pool; |
| 3652 | command_buffer_allocate_info.commandBufferCount = 1; |
| 3653 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3654 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3655 | &command_buffer); |
| 3656 | |
| 3657 | VkQueue queue = VK_NULL_HANDLE; |
| 3658 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
Tony Barbour | fe302c0 | 2016-06-06 13:05:19 -0600 | [diff] [blame] | 3659 | 0, &queue); |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3660 | |
| 3661 | { |
| 3662 | VkCommandBufferBeginInfo begin_info{}; |
| 3663 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3664 | vkBeginCommandBuffer(command_buffer, &begin_info); |
| 3665 | |
| 3666 | vkCmdResetEvent(command_buffer, event, |
| 3667 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 3668 | vkCmdWaitEvents(command_buffer, 1, &event, |
| 3669 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3670 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, |
| 3671 | nullptr, 0, nullptr); |
| 3672 | vkEndCommandBuffer(command_buffer); |
| 3673 | } |
| 3674 | { |
| 3675 | VkSubmitInfo submit_info{}; |
| 3676 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3677 | submit_info.commandBufferCount = 1; |
| 3678 | submit_info.pCommandBuffers = &command_buffer; |
| 3679 | submit_info.signalSemaphoreCount = 0; |
| 3680 | submit_info.pSignalSemaphores = nullptr; |
| 3681 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3682 | } |
| 3683 | { |
| 3684 | m_errorMonitor->SetDesiredFailureMsg( |
| 3685 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkSetEvent() on event " |
| 3686 | "0x1 that is already in use by a " |
| 3687 | "command buffer."); |
| 3688 | vkSetEvent(m_device->device(), event); |
| 3689 | m_errorMonitor->VerifyFound(); |
| 3690 | } |
| 3691 | |
| 3692 | vkQueueWaitIdle(queue); |
| 3693 | |
| 3694 | vkDestroyEvent(m_device->device(), event, nullptr); |
| 3695 | vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer); |
| 3696 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3697 | } |
| 3698 | |
| 3699 | // This is a positive test. No errors should be generated. |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3700 | TEST_F(VkLayerTest, TwoFencesThreeFrames) { |
| 3701 | TEST_DESCRIPTION("Two command buffers with two separate fences are each " |
| 3702 | "run through a Submit & WaitForFences cycle 3 times. This " |
| 3703 | "previously revealed a bug so running this positive test " |
| 3704 | "to prevent a regression."); |
| 3705 | m_errorMonitor->ExpectSuccess(); |
| 3706 | |
| 3707 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3708 | VkQueue queue = VK_NULL_HANDLE; |
| 3709 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3710 | 0, &queue); |
| 3711 | |
| 3712 | static const uint32_t NUM_OBJECTS = 2; |
| 3713 | static const uint32_t NUM_FRAMES = 3; |
| 3714 | VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {}; |
| 3715 | VkFence fences[NUM_OBJECTS] = {}; |
| 3716 | |
| 3717 | VkCommandPool cmd_pool; |
| 3718 | VkCommandPoolCreateInfo cmd_pool_ci = {}; |
| 3719 | cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3720 | cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3721 | cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3722 | VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, |
| 3723 | nullptr, &cmd_pool); |
| 3724 | ASSERT_VK_SUCCESS(err); |
| 3725 | |
| 3726 | VkCommandBufferAllocateInfo cmd_buf_info = {}; |
| 3727 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3728 | cmd_buf_info.commandPool = cmd_pool; |
| 3729 | cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3730 | cmd_buf_info.commandBufferCount = 1; |
| 3731 | |
| 3732 | VkFenceCreateInfo fence_ci = {}; |
| 3733 | fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3734 | fence_ci.pNext = nullptr; |
| 3735 | fence_ci.flags = 0; |
| 3736 | |
| 3737 | for (uint32_t i = 0; i < NUM_OBJECTS; ++i) { |
| 3738 | err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, |
| 3739 | &cmd_buffers[i]); |
| 3740 | ASSERT_VK_SUCCESS(err); |
| 3741 | err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]); |
| 3742 | ASSERT_VK_SUCCESS(err); |
| 3743 | } |
| 3744 | |
| 3745 | for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) { |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 3746 | for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) { |
| 3747 | // Create empty cmd buffer |
| 3748 | VkCommandBufferBeginInfo cmdBufBeginDesc = {}; |
| 3749 | cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3750 | |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 3751 | err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc); |
| 3752 | ASSERT_VK_SUCCESS(err); |
| 3753 | err = vkEndCommandBuffer(cmd_buffers[obj]); |
| 3754 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3755 | |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 3756 | VkSubmitInfo submit_info = {}; |
| 3757 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3758 | submit_info.commandBufferCount = 1; |
| 3759 | submit_info.pCommandBuffers = &cmd_buffers[obj]; |
| 3760 | // Submit cmd buffer and wait for fence |
| 3761 | err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]); |
| 3762 | ASSERT_VK_SUCCESS(err); |
| 3763 | err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, |
| 3764 | UINT64_MAX); |
| 3765 | ASSERT_VK_SUCCESS(err); |
| 3766 | err = vkResetFences(m_device->device(), 1, &fences[obj]); |
| 3767 | ASSERT_VK_SUCCESS(err); |
| 3768 | } |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3769 | } |
| 3770 | m_errorMonitor->VerifyNotFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 3771 | vkDestroyCommandPool(m_device->device(), cmd_pool, NULL); |
| 3772 | for (uint32_t i = 0; i < NUM_OBJECTS; ++i) { |
| 3773 | vkDestroyFence(m_device->device(), fences[i], nullptr); |
| 3774 | } |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3775 | } |
| 3776 | // This is a positive test. No errors should be generated. |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3777 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) { |
| 3778 | |
| 3779 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 3780 | "submitted on separate queues followed by a QueueWaitIdle."); |
| 3781 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 3782 | if ((m_device->queue_props.empty()) || |
| 3783 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 3784 | return; |
| 3785 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3786 | m_errorMonitor->ExpectSuccess(); |
| 3787 | |
| 3788 | VkSemaphore semaphore; |
| 3789 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 3790 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 3791 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 3792 | &semaphore); |
| 3793 | |
| 3794 | VkCommandPool command_pool; |
| 3795 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3796 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3797 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3798 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3799 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3800 | &command_pool); |
| 3801 | |
| 3802 | VkCommandBuffer command_buffer[2]; |
| 3803 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3804 | command_buffer_allocate_info.sType = |
| 3805 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3806 | command_buffer_allocate_info.commandPool = command_pool; |
| 3807 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3808 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3809 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3810 | command_buffer); |
| 3811 | |
| 3812 | VkQueue queue = VK_NULL_HANDLE; |
| 3813 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3814 | 1, &queue); |
| 3815 | |
| 3816 | { |
| 3817 | VkCommandBufferBeginInfo begin_info{}; |
| 3818 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3819 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3820 | |
| 3821 | vkCmdPipelineBarrier(command_buffer[0], |
| 3822 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3823 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 3824 | 0, nullptr, 0, nullptr); |
| 3825 | |
| 3826 | VkViewport viewport{}; |
| 3827 | viewport.maxDepth = 1.0f; |
| 3828 | viewport.minDepth = 0.0f; |
| 3829 | viewport.width = 512; |
| 3830 | viewport.height = 512; |
| 3831 | viewport.x = 0; |
| 3832 | viewport.y = 0; |
| 3833 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 3834 | vkEndCommandBuffer(command_buffer[0]); |
| 3835 | } |
| 3836 | { |
| 3837 | VkCommandBufferBeginInfo begin_info{}; |
| 3838 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3839 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3840 | |
| 3841 | VkViewport viewport{}; |
| 3842 | viewport.maxDepth = 1.0f; |
| 3843 | viewport.minDepth = 0.0f; |
| 3844 | viewport.width = 512; |
| 3845 | viewport.height = 512; |
| 3846 | viewport.x = 0; |
| 3847 | viewport.y = 0; |
| 3848 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 3849 | vkEndCommandBuffer(command_buffer[1]); |
| 3850 | } |
| 3851 | { |
| 3852 | VkSubmitInfo submit_info{}; |
| 3853 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3854 | submit_info.commandBufferCount = 1; |
| 3855 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 3856 | submit_info.signalSemaphoreCount = 1; |
| 3857 | submit_info.pSignalSemaphores = &semaphore; |
| 3858 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3859 | } |
| 3860 | { |
| 3861 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 3862 | VkSubmitInfo submit_info{}; |
| 3863 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3864 | submit_info.commandBufferCount = 1; |
| 3865 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 3866 | submit_info.waitSemaphoreCount = 1; |
| 3867 | submit_info.pWaitSemaphores = &semaphore; |
| 3868 | submit_info.pWaitDstStageMask = flags; |
| 3869 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3870 | } |
| 3871 | |
| 3872 | vkQueueWaitIdle(m_device->m_queue); |
| 3873 | |
| 3874 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 3875 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 3876 | &command_buffer[0]); |
| 3877 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3878 | |
| 3879 | m_errorMonitor->VerifyNotFound(); |
| 3880 | } |
| 3881 | |
| 3882 | // This is a positive test. No errors should be generated. |
| 3883 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) { |
| 3884 | |
| 3885 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 3886 | "submitted on separate queues, the second having a fence" |
| 3887 | "followed by a QueueWaitIdle."); |
| 3888 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 3889 | if ((m_device->queue_props.empty()) || |
| 3890 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 3891 | return; |
| 3892 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3893 | m_errorMonitor->ExpectSuccess(); |
| 3894 | |
| 3895 | VkFence fence; |
| 3896 | VkFenceCreateInfo fence_create_info{}; |
| 3897 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3898 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 3899 | |
| 3900 | VkSemaphore semaphore; |
| 3901 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 3902 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 3903 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 3904 | &semaphore); |
| 3905 | |
| 3906 | VkCommandPool command_pool; |
| 3907 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3908 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3909 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3910 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3911 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3912 | &command_pool); |
| 3913 | |
| 3914 | VkCommandBuffer command_buffer[2]; |
| 3915 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3916 | command_buffer_allocate_info.sType = |
| 3917 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3918 | command_buffer_allocate_info.commandPool = command_pool; |
| 3919 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3920 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3921 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3922 | command_buffer); |
| 3923 | |
| 3924 | VkQueue queue = VK_NULL_HANDLE; |
| 3925 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3926 | 1, &queue); |
| 3927 | |
| 3928 | { |
| 3929 | VkCommandBufferBeginInfo begin_info{}; |
| 3930 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3931 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3932 | |
| 3933 | vkCmdPipelineBarrier(command_buffer[0], |
| 3934 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3935 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 3936 | 0, nullptr, 0, nullptr); |
| 3937 | |
| 3938 | VkViewport viewport{}; |
| 3939 | viewport.maxDepth = 1.0f; |
| 3940 | viewport.minDepth = 0.0f; |
| 3941 | viewport.width = 512; |
| 3942 | viewport.height = 512; |
| 3943 | viewport.x = 0; |
| 3944 | viewport.y = 0; |
| 3945 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 3946 | vkEndCommandBuffer(command_buffer[0]); |
| 3947 | } |
| 3948 | { |
| 3949 | VkCommandBufferBeginInfo begin_info{}; |
| 3950 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3951 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3952 | |
| 3953 | VkViewport viewport{}; |
| 3954 | viewport.maxDepth = 1.0f; |
| 3955 | viewport.minDepth = 0.0f; |
| 3956 | viewport.width = 512; |
| 3957 | viewport.height = 512; |
| 3958 | viewport.x = 0; |
| 3959 | viewport.y = 0; |
| 3960 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 3961 | vkEndCommandBuffer(command_buffer[1]); |
| 3962 | } |
| 3963 | { |
| 3964 | VkSubmitInfo submit_info{}; |
| 3965 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3966 | submit_info.commandBufferCount = 1; |
| 3967 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 3968 | submit_info.signalSemaphoreCount = 1; |
| 3969 | submit_info.pSignalSemaphores = &semaphore; |
| 3970 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3971 | } |
| 3972 | { |
| 3973 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 3974 | VkSubmitInfo submit_info{}; |
| 3975 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3976 | submit_info.commandBufferCount = 1; |
| 3977 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 3978 | submit_info.waitSemaphoreCount = 1; |
| 3979 | submit_info.pWaitSemaphores = &semaphore; |
| 3980 | submit_info.pWaitDstStageMask = flags; |
| 3981 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 3982 | } |
| 3983 | |
| 3984 | vkQueueWaitIdle(m_device->m_queue); |
| 3985 | |
| 3986 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 3987 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 3988 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 3989 | &command_buffer[0]); |
| 3990 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3991 | |
| 3992 | m_errorMonitor->VerifyNotFound(); |
| 3993 | } |
| 3994 | |
| 3995 | // This is a positive test. No errors should be generated. |
| 3996 | TEST_F(VkLayerTest, |
| 3997 | TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) { |
| 3998 | |
| 3999 | TEST_DESCRIPTION( |
| 4000 | "Two command buffers, each in a separate QueueSubmit call " |
| 4001 | "submitted on separate queues, the second having a fence" |
| 4002 | "followed by two consecutive WaitForFences calls on the same fence."); |
| 4003 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 4004 | if ((m_device->queue_props.empty()) || |
| 4005 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 4006 | return; |
| 4007 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4008 | m_errorMonitor->ExpectSuccess(); |
| 4009 | |
| 4010 | VkFence fence; |
| 4011 | VkFenceCreateInfo fence_create_info{}; |
| 4012 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4013 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4014 | |
| 4015 | VkSemaphore semaphore; |
| 4016 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4017 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4018 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4019 | &semaphore); |
| 4020 | |
| 4021 | VkCommandPool command_pool; |
| 4022 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4023 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4024 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4025 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4026 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4027 | &command_pool); |
| 4028 | |
| 4029 | VkCommandBuffer command_buffer[2]; |
| 4030 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4031 | command_buffer_allocate_info.sType = |
| 4032 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4033 | command_buffer_allocate_info.commandPool = command_pool; |
| 4034 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4035 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4036 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4037 | command_buffer); |
| 4038 | |
| 4039 | VkQueue queue = VK_NULL_HANDLE; |
| 4040 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4041 | 1, &queue); |
| 4042 | |
| 4043 | { |
| 4044 | VkCommandBufferBeginInfo begin_info{}; |
| 4045 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4046 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4047 | |
| 4048 | vkCmdPipelineBarrier(command_buffer[0], |
| 4049 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4050 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4051 | 0, nullptr, 0, nullptr); |
| 4052 | |
| 4053 | VkViewport viewport{}; |
| 4054 | viewport.maxDepth = 1.0f; |
| 4055 | viewport.minDepth = 0.0f; |
| 4056 | viewport.width = 512; |
| 4057 | viewport.height = 512; |
| 4058 | viewport.x = 0; |
| 4059 | viewport.y = 0; |
| 4060 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4061 | vkEndCommandBuffer(command_buffer[0]); |
| 4062 | } |
| 4063 | { |
| 4064 | VkCommandBufferBeginInfo begin_info{}; |
| 4065 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4066 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4067 | |
| 4068 | VkViewport viewport{}; |
| 4069 | viewport.maxDepth = 1.0f; |
| 4070 | viewport.minDepth = 0.0f; |
| 4071 | viewport.width = 512; |
| 4072 | viewport.height = 512; |
| 4073 | viewport.x = 0; |
| 4074 | viewport.y = 0; |
| 4075 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4076 | vkEndCommandBuffer(command_buffer[1]); |
| 4077 | } |
| 4078 | { |
| 4079 | VkSubmitInfo submit_info{}; |
| 4080 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4081 | submit_info.commandBufferCount = 1; |
| 4082 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4083 | submit_info.signalSemaphoreCount = 1; |
| 4084 | submit_info.pSignalSemaphores = &semaphore; |
| 4085 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4086 | } |
| 4087 | { |
| 4088 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4089 | VkSubmitInfo submit_info{}; |
| 4090 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4091 | submit_info.commandBufferCount = 1; |
| 4092 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4093 | submit_info.waitSemaphoreCount = 1; |
| 4094 | submit_info.pWaitSemaphores = &semaphore; |
| 4095 | submit_info.pWaitDstStageMask = flags; |
| 4096 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4097 | } |
| 4098 | |
| 4099 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4100 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4101 | |
| 4102 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4103 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4104 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4105 | &command_buffer[0]); |
| 4106 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4107 | |
| 4108 | m_errorMonitor->VerifyNotFound(); |
| 4109 | } |
| 4110 | |
| 4111 | // This is a positive test. No errors should be generated. |
| 4112 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) { |
| 4113 | |
| 4114 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4115 | "submitted on separate queues, the second having a fence, " |
| 4116 | "followed by a WaitForFences call."); |
| 4117 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 4118 | if ((m_device->queue_props.empty()) || |
| 4119 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 4120 | return; |
| 4121 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4122 | m_errorMonitor->ExpectSuccess(); |
| 4123 | |
| 4124 | VkFence fence; |
| 4125 | VkFenceCreateInfo fence_create_info{}; |
| 4126 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4127 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4128 | |
| 4129 | VkSemaphore semaphore; |
| 4130 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4131 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4132 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4133 | &semaphore); |
| 4134 | |
| 4135 | VkCommandPool command_pool; |
| 4136 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4137 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4138 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4139 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4140 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4141 | &command_pool); |
| 4142 | |
| 4143 | VkCommandBuffer command_buffer[2]; |
| 4144 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4145 | command_buffer_allocate_info.sType = |
| 4146 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4147 | command_buffer_allocate_info.commandPool = command_pool; |
| 4148 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4149 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4150 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4151 | command_buffer); |
| 4152 | |
| 4153 | VkQueue queue = VK_NULL_HANDLE; |
| 4154 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4155 | 1, &queue); |
| 4156 | |
| 4157 | |
| 4158 | { |
| 4159 | VkCommandBufferBeginInfo begin_info{}; |
| 4160 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4161 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4162 | |
| 4163 | vkCmdPipelineBarrier(command_buffer[0], |
| 4164 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4165 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4166 | 0, nullptr, 0, nullptr); |
| 4167 | |
| 4168 | VkViewport viewport{}; |
| 4169 | viewport.maxDepth = 1.0f; |
| 4170 | viewport.minDepth = 0.0f; |
| 4171 | viewport.width = 512; |
| 4172 | viewport.height = 512; |
| 4173 | viewport.x = 0; |
| 4174 | viewport.y = 0; |
| 4175 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4176 | vkEndCommandBuffer(command_buffer[0]); |
| 4177 | } |
| 4178 | { |
| 4179 | VkCommandBufferBeginInfo begin_info{}; |
| 4180 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4181 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4182 | |
| 4183 | VkViewport viewport{}; |
| 4184 | viewport.maxDepth = 1.0f; |
| 4185 | viewport.minDepth = 0.0f; |
| 4186 | viewport.width = 512; |
| 4187 | viewport.height = 512; |
| 4188 | viewport.x = 0; |
| 4189 | viewport.y = 0; |
| 4190 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4191 | vkEndCommandBuffer(command_buffer[1]); |
| 4192 | } |
| 4193 | { |
| 4194 | VkSubmitInfo submit_info{}; |
| 4195 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4196 | submit_info.commandBufferCount = 1; |
| 4197 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4198 | submit_info.signalSemaphoreCount = 1; |
| 4199 | submit_info.pSignalSemaphores = &semaphore; |
| 4200 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4201 | } |
| 4202 | { |
| 4203 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4204 | VkSubmitInfo submit_info{}; |
| 4205 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4206 | submit_info.commandBufferCount = 1; |
| 4207 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4208 | submit_info.waitSemaphoreCount = 1; |
| 4209 | submit_info.pWaitSemaphores = &semaphore; |
| 4210 | submit_info.pWaitDstStageMask = flags; |
| 4211 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4212 | } |
| 4213 | |
| 4214 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4215 | |
| 4216 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4217 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4218 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4219 | &command_buffer[0]); |
| 4220 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4221 | |
| 4222 | m_errorMonitor->VerifyNotFound(); |
| 4223 | } |
| 4224 | |
| 4225 | // This is a positive test. No errors should be generated. |
| 4226 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) { |
| 4227 | |
| 4228 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4229 | "on the same queue, sharing a signal/wait semaphore, the " |
| 4230 | "second having a fence, " |
| 4231 | "followed by a WaitForFences call."); |
| 4232 | |
| 4233 | m_errorMonitor->ExpectSuccess(); |
| 4234 | |
| 4235 | VkFence fence; |
| 4236 | VkFenceCreateInfo fence_create_info{}; |
| 4237 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4238 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4239 | |
| 4240 | VkSemaphore semaphore; |
| 4241 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4242 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4243 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4244 | &semaphore); |
| 4245 | |
| 4246 | VkCommandPool command_pool; |
| 4247 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4248 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4249 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4250 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4251 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4252 | &command_pool); |
| 4253 | |
| 4254 | VkCommandBuffer command_buffer[2]; |
| 4255 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4256 | command_buffer_allocate_info.sType = |
| 4257 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4258 | command_buffer_allocate_info.commandPool = command_pool; |
| 4259 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4260 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4261 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4262 | command_buffer); |
| 4263 | |
| 4264 | { |
| 4265 | VkCommandBufferBeginInfo begin_info{}; |
| 4266 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4267 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4268 | |
| 4269 | vkCmdPipelineBarrier(command_buffer[0], |
| 4270 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4271 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4272 | 0, nullptr, 0, nullptr); |
| 4273 | |
| 4274 | VkViewport viewport{}; |
| 4275 | viewport.maxDepth = 1.0f; |
| 4276 | viewport.minDepth = 0.0f; |
| 4277 | viewport.width = 512; |
| 4278 | viewport.height = 512; |
| 4279 | viewport.x = 0; |
| 4280 | viewport.y = 0; |
| 4281 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4282 | vkEndCommandBuffer(command_buffer[0]); |
| 4283 | } |
| 4284 | { |
| 4285 | VkCommandBufferBeginInfo begin_info{}; |
| 4286 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4287 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4288 | |
| 4289 | VkViewport viewport{}; |
| 4290 | viewport.maxDepth = 1.0f; |
| 4291 | viewport.minDepth = 0.0f; |
| 4292 | viewport.width = 512; |
| 4293 | viewport.height = 512; |
| 4294 | viewport.x = 0; |
| 4295 | viewport.y = 0; |
| 4296 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4297 | vkEndCommandBuffer(command_buffer[1]); |
| 4298 | } |
| 4299 | { |
| 4300 | VkSubmitInfo submit_info{}; |
| 4301 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4302 | submit_info.commandBufferCount = 1; |
| 4303 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4304 | submit_info.signalSemaphoreCount = 1; |
| 4305 | submit_info.pSignalSemaphores = &semaphore; |
| 4306 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4307 | } |
| 4308 | { |
| 4309 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4310 | VkSubmitInfo submit_info{}; |
| 4311 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4312 | submit_info.commandBufferCount = 1; |
| 4313 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4314 | submit_info.waitSemaphoreCount = 1; |
| 4315 | submit_info.pWaitSemaphores = &semaphore; |
| 4316 | submit_info.pWaitDstStageMask = flags; |
| 4317 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4318 | } |
| 4319 | |
| 4320 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4321 | |
| 4322 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4323 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4324 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4325 | &command_buffer[0]); |
| 4326 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4327 | |
| 4328 | m_errorMonitor->VerifyNotFound(); |
| 4329 | } |
| 4330 | |
| 4331 | // This is a positive test. No errors should be generated. |
| 4332 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) { |
| 4333 | |
| 4334 | TEST_DESCRIPTION( |
| 4335 | "Two command buffers, each in a separate QueueSubmit call " |
| 4336 | "on the same queue, no fences, followed by a third QueueSubmit with NO " |
| 4337 | "SubmitInfos but with a fence, followed by a WaitForFences call."); |
| 4338 | |
| 4339 | m_errorMonitor->ExpectSuccess(); |
| 4340 | |
| 4341 | VkFence fence; |
| 4342 | VkFenceCreateInfo fence_create_info{}; |
| 4343 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4344 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4345 | |
| 4346 | VkCommandPool command_pool; |
| 4347 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4348 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4349 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4350 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4351 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4352 | &command_pool); |
| 4353 | |
| 4354 | VkCommandBuffer command_buffer[2]; |
| 4355 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4356 | command_buffer_allocate_info.sType = |
| 4357 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4358 | command_buffer_allocate_info.commandPool = command_pool; |
| 4359 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4360 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4361 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4362 | command_buffer); |
| 4363 | |
| 4364 | { |
| 4365 | VkCommandBufferBeginInfo begin_info{}; |
| 4366 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4367 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4368 | |
| 4369 | vkCmdPipelineBarrier(command_buffer[0], |
| 4370 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4371 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4372 | 0, nullptr, 0, nullptr); |
| 4373 | |
| 4374 | VkViewport viewport{}; |
| 4375 | viewport.maxDepth = 1.0f; |
| 4376 | viewport.minDepth = 0.0f; |
| 4377 | viewport.width = 512; |
| 4378 | viewport.height = 512; |
| 4379 | viewport.x = 0; |
| 4380 | viewport.y = 0; |
| 4381 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4382 | vkEndCommandBuffer(command_buffer[0]); |
| 4383 | } |
| 4384 | { |
| 4385 | VkCommandBufferBeginInfo begin_info{}; |
| 4386 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4387 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4388 | |
| 4389 | VkViewport viewport{}; |
| 4390 | viewport.maxDepth = 1.0f; |
| 4391 | viewport.minDepth = 0.0f; |
| 4392 | viewport.width = 512; |
| 4393 | viewport.height = 512; |
| 4394 | viewport.x = 0; |
| 4395 | viewport.y = 0; |
| 4396 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4397 | vkEndCommandBuffer(command_buffer[1]); |
| 4398 | } |
| 4399 | { |
| 4400 | VkSubmitInfo submit_info{}; |
| 4401 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4402 | submit_info.commandBufferCount = 1; |
| 4403 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4404 | submit_info.signalSemaphoreCount = 0; |
| 4405 | submit_info.pSignalSemaphores = VK_NULL_HANDLE; |
| 4406 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4407 | } |
| 4408 | { |
| 4409 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4410 | VkSubmitInfo submit_info{}; |
| 4411 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4412 | submit_info.commandBufferCount = 1; |
| 4413 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4414 | submit_info.waitSemaphoreCount = 0; |
| 4415 | submit_info.pWaitSemaphores = VK_NULL_HANDLE; |
| 4416 | submit_info.pWaitDstStageMask = flags; |
| 4417 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4418 | } |
| 4419 | |
| 4420 | vkQueueSubmit(m_device->m_queue, 0, NULL, fence); |
| 4421 | |
| 4422 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4423 | |
| 4424 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4425 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4426 | &command_buffer[0]); |
| 4427 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4428 | |
| 4429 | m_errorMonitor->VerifyNotFound(); |
| 4430 | } |
| 4431 | |
| 4432 | // This is a positive test. No errors should be generated. |
| 4433 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) { |
| 4434 | |
| 4435 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4436 | "on the same queue, the second having a fence, followed " |
| 4437 | "by a WaitForFences call."); |
| 4438 | |
| 4439 | m_errorMonitor->ExpectSuccess(); |
| 4440 | |
| 4441 | VkFence fence; |
| 4442 | VkFenceCreateInfo fence_create_info{}; |
| 4443 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4444 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4445 | |
| 4446 | VkCommandPool command_pool; |
| 4447 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4448 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4449 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4450 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4451 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4452 | &command_pool); |
| 4453 | |
| 4454 | VkCommandBuffer command_buffer[2]; |
| 4455 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4456 | command_buffer_allocate_info.sType = |
| 4457 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4458 | command_buffer_allocate_info.commandPool = command_pool; |
| 4459 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4460 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4461 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4462 | command_buffer); |
| 4463 | |
| 4464 | { |
| 4465 | VkCommandBufferBeginInfo begin_info{}; |
| 4466 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4467 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4468 | |
| 4469 | vkCmdPipelineBarrier(command_buffer[0], |
| 4470 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4471 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4472 | 0, nullptr, 0, nullptr); |
| 4473 | |
| 4474 | VkViewport viewport{}; |
| 4475 | viewport.maxDepth = 1.0f; |
| 4476 | viewport.minDepth = 0.0f; |
| 4477 | viewport.width = 512; |
| 4478 | viewport.height = 512; |
| 4479 | viewport.x = 0; |
| 4480 | viewport.y = 0; |
| 4481 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4482 | vkEndCommandBuffer(command_buffer[0]); |
| 4483 | } |
| 4484 | { |
| 4485 | VkCommandBufferBeginInfo begin_info{}; |
| 4486 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4487 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4488 | |
| 4489 | VkViewport viewport{}; |
| 4490 | viewport.maxDepth = 1.0f; |
| 4491 | viewport.minDepth = 0.0f; |
| 4492 | viewport.width = 512; |
| 4493 | viewport.height = 512; |
| 4494 | viewport.x = 0; |
| 4495 | viewport.y = 0; |
| 4496 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4497 | vkEndCommandBuffer(command_buffer[1]); |
| 4498 | } |
| 4499 | { |
| 4500 | VkSubmitInfo submit_info{}; |
| 4501 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4502 | submit_info.commandBufferCount = 1; |
| 4503 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4504 | submit_info.signalSemaphoreCount = 0; |
| 4505 | submit_info.pSignalSemaphores = VK_NULL_HANDLE; |
| 4506 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4507 | } |
| 4508 | { |
| 4509 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4510 | VkSubmitInfo submit_info{}; |
| 4511 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4512 | submit_info.commandBufferCount = 1; |
| 4513 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4514 | submit_info.waitSemaphoreCount = 0; |
| 4515 | submit_info.pWaitSemaphores = VK_NULL_HANDLE; |
| 4516 | submit_info.pWaitDstStageMask = flags; |
| 4517 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4518 | } |
| 4519 | |
| 4520 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4521 | |
| 4522 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4523 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4524 | &command_buffer[0]); |
| 4525 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4526 | |
| 4527 | m_errorMonitor->VerifyNotFound(); |
| 4528 | } |
| 4529 | |
| 4530 | // This is a positive test. No errors should be generated. |
| 4531 | TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) { |
| 4532 | |
| 4533 | TEST_DESCRIPTION( |
| 4534 | "Two command buffers each in a separate SubmitInfo sent in a single " |
| 4535 | "QueueSubmit call followed by a WaitForFences call."); |
| 4536 | |
| 4537 | m_errorMonitor->ExpectSuccess(); |
| 4538 | |
| 4539 | VkFence fence; |
| 4540 | VkFenceCreateInfo fence_create_info{}; |
| 4541 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4542 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4543 | |
| 4544 | VkSemaphore semaphore; |
| 4545 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4546 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4547 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4548 | &semaphore); |
| 4549 | |
| 4550 | VkCommandPool command_pool; |
| 4551 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4552 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4553 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4554 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4555 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4556 | &command_pool); |
| 4557 | |
| 4558 | VkCommandBuffer command_buffer[2]; |
| 4559 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4560 | command_buffer_allocate_info.sType = |
| 4561 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4562 | command_buffer_allocate_info.commandPool = command_pool; |
| 4563 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4564 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4565 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4566 | command_buffer); |
| 4567 | |
| 4568 | { |
| 4569 | VkCommandBufferBeginInfo begin_info{}; |
| 4570 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4571 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4572 | |
| 4573 | vkCmdPipelineBarrier(command_buffer[0], |
| 4574 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4575 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4576 | 0, nullptr, 0, nullptr); |
| 4577 | |
| 4578 | VkViewport viewport{}; |
| 4579 | viewport.maxDepth = 1.0f; |
| 4580 | viewport.minDepth = 0.0f; |
| 4581 | viewport.width = 512; |
| 4582 | viewport.height = 512; |
| 4583 | viewport.x = 0; |
| 4584 | viewport.y = 0; |
| 4585 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4586 | vkEndCommandBuffer(command_buffer[0]); |
| 4587 | } |
| 4588 | { |
| 4589 | VkCommandBufferBeginInfo begin_info{}; |
| 4590 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4591 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4592 | |
| 4593 | VkViewport viewport{}; |
| 4594 | viewport.maxDepth = 1.0f; |
| 4595 | viewport.minDepth = 0.0f; |
| 4596 | viewport.width = 512; |
| 4597 | viewport.height = 512; |
| 4598 | viewport.x = 0; |
| 4599 | viewport.y = 0; |
| 4600 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4601 | vkEndCommandBuffer(command_buffer[1]); |
| 4602 | } |
| 4603 | { |
| 4604 | VkSubmitInfo submit_info[2]; |
| 4605 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4606 | |
| 4607 | submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4608 | submit_info[0].pNext = NULL; |
| 4609 | submit_info[0].commandBufferCount = 1; |
| 4610 | submit_info[0].pCommandBuffers = &command_buffer[0]; |
| 4611 | submit_info[0].signalSemaphoreCount = 1; |
| 4612 | submit_info[0].pSignalSemaphores = &semaphore; |
| 4613 | submit_info[0].waitSemaphoreCount = 0; |
| 4614 | submit_info[0].pWaitSemaphores = NULL; |
| 4615 | submit_info[0].pWaitDstStageMask = 0; |
| 4616 | |
| 4617 | submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4618 | submit_info[1].pNext = NULL; |
| 4619 | submit_info[1].commandBufferCount = 1; |
| 4620 | submit_info[1].pCommandBuffers = &command_buffer[1]; |
| 4621 | submit_info[1].waitSemaphoreCount = 1; |
| 4622 | submit_info[1].pWaitSemaphores = &semaphore; |
| 4623 | submit_info[1].pWaitDstStageMask = flags; |
| 4624 | submit_info[1].signalSemaphoreCount = 0; |
| 4625 | submit_info[1].pSignalSemaphores = NULL; |
| 4626 | vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence); |
| 4627 | } |
| 4628 | |
| 4629 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4630 | |
| 4631 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4632 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4633 | &command_buffer[0]); |
| 4634 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 4635 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4636 | |
| 4637 | m_errorMonitor->VerifyNotFound(); |
| 4638 | } |
| 4639 | |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4640 | TEST_F(VkLayerTest, DynamicDepthBiasNotBound) { |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4641 | TEST_DESCRIPTION( |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4642 | "Run a simple draw calls to validate failure when Depth Bias dynamic " |
| 4643 | "state is required but not correctly bound."); |
| 4644 | |
| 4645 | // Dynamic depth bias |
| 4646 | m_errorMonitor->SetDesiredFailureMsg( |
| 4647 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4648 | "Dynamic depth bias state not set for this command buffer"); |
| 4649 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4650 | BsoFailDepthBias); |
| 4651 | m_errorMonitor->VerifyFound(); |
| 4652 | } |
| 4653 | |
| 4654 | TEST_F(VkLayerTest, DynamicLineWidthNotBound) { |
| 4655 | TEST_DESCRIPTION( |
| 4656 | "Run a simple draw calls to validate failure when Line Width dynamic " |
| 4657 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4658 | |
| 4659 | // Dynamic line width |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4660 | m_errorMonitor->SetDesiredFailureMsg( |
| 4661 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4662 | "Dynamic line width state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4663 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4664 | BsoFailLineWidth); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4665 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4666 | } |
| 4667 | |
| 4668 | TEST_F(VkLayerTest, DynamicViewportNotBound) { |
| 4669 | TEST_DESCRIPTION( |
| 4670 | "Run a simple draw calls to validate failure when Viewport dynamic " |
| 4671 | "state is required but not correctly bound."); |
| 4672 | |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4673 | // Dynamic viewport state |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4674 | m_errorMonitor->SetDesiredFailureMsg( |
| 4675 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4676 | "Dynamic viewport state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4677 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4678 | BsoFailViewport); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4679 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4680 | } |
| 4681 | |
| 4682 | TEST_F(VkLayerTest, DynamicScissorNotBound) { |
| 4683 | TEST_DESCRIPTION( |
| 4684 | "Run a simple draw calls to validate failure when Scissor dynamic " |
| 4685 | "state is required but not correctly bound."); |
| 4686 | |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4687 | // Dynamic scissor state |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4688 | m_errorMonitor->SetDesiredFailureMsg( |
| 4689 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4690 | "Dynamic scissor state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4691 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4692 | BsoFailScissor); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4693 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4694 | } |
| 4695 | |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 4696 | TEST_F(VkLayerTest, DynamiBlendConstantsNotBound) { |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4697 | TEST_DESCRIPTION( |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 4698 | "Run a simple draw calls to validate failure when Blend Constants " |
| 4699 | "dynamic state is required but not correctly bound."); |
| 4700 | // Dynamic blend constant state |
| 4701 | m_errorMonitor->SetDesiredFailureMsg( |
| 4702 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4703 | "Dynamic blend constants state not set for this command buffer"); |
| 4704 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4705 | BsoFailBlend); |
| 4706 | m_errorMonitor->VerifyFound(); |
| 4707 | } |
| 4708 | |
| 4709 | TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) { |
| 4710 | TEST_DESCRIPTION( |
| 4711 | "Run a simple draw calls to validate failure when Depth Bounds dynamic " |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4712 | "state is required but not correctly bound."); |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 4713 | if (!m_device->phy().features().depthBounds) { |
| 4714 | printf("Device does not support depthBounds test; skipped.\n"); |
| 4715 | return; |
| 4716 | } |
| 4717 | // Dynamic depth bounds |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4718 | m_errorMonitor->SetDesiredFailureMsg( |
| 4719 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4720 | "Dynamic depth bounds state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4721 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4722 | BsoFailDepthBounds); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4723 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4724 | } |
| 4725 | |
| 4726 | TEST_F(VkLayerTest, DynamicStencilReadNotBound) { |
| 4727 | TEST_DESCRIPTION( |
| 4728 | "Run a simple draw calls to validate failure when Stencil Read dynamic " |
| 4729 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4730 | // Dynamic stencil read mask |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4731 | m_errorMonitor->SetDesiredFailureMsg( |
| 4732 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4733 | "Dynamic stencil read mask state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4734 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4735 | BsoFailStencilReadMask); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4736 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4737 | } |
| 4738 | |
| 4739 | TEST_F(VkLayerTest, DynamicStencilWriteNotBound) { |
| 4740 | TEST_DESCRIPTION( |
| 4741 | "Run a simple draw calls to validate failure when Stencil Write dynamic" |
| 4742 | " state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4743 | // Dynamic stencil write mask |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4744 | m_errorMonitor->SetDesiredFailureMsg( |
| 4745 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4746 | "Dynamic stencil write mask state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4747 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4748 | BsoFailStencilWriteMask); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4749 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4750 | } |
| 4751 | |
| 4752 | TEST_F(VkLayerTest, DynamicStencilRefNotBound) { |
| 4753 | TEST_DESCRIPTION( |
| 4754 | "Run a simple draw calls to validate failure when Stencil Ref dynamic " |
| 4755 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4756 | // Dynamic stencil reference |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4757 | m_errorMonitor->SetDesiredFailureMsg( |
| 4758 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4759 | "Dynamic stencil reference state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4760 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4761 | BsoFailStencilReference); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4762 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 963a404 | 2015-09-29 08:18:34 -0600 | [diff] [blame] | 4763 | } |
| 4764 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4765 | TEST_F(VkLayerTest, CommandBufferTwoSubmits) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4766 | m_errorMonitor->SetDesiredFailureMsg( |
| 4767 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4768 | "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has " |
| 4769 | "been submitted"); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4770 | |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4771 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4772 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 4773 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 4774 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4775 | // We luck out b/c by default the framework creates CB w/ the |
| 4776 | // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4777 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4778 | m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 4779 | m_stencil_clear_color, NULL); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4780 | EndCommandBuffer(); |
| 4781 | |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4782 | // Bypass framework since it does the waits automatically |
| 4783 | VkResult err = VK_SUCCESS; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 4784 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 4785 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4786 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 4787 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 4788 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 4789 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 4790 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 4791 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 4792 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 4793 | submit_info.pSignalSemaphores = NULL; |
| 4794 | |
Chris Forbes | 40028e2 | 2016-06-13 09:59:34 +1200 | [diff] [blame] | 4795 | err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4796 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4797 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4798 | // Cause validation error by re-submitting cmd buffer that should only be |
| 4799 | // submitted once |
Chris Forbes | 40028e2 | 2016-06-13 09:59:34 +1200 | [diff] [blame] | 4800 | err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4801 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4802 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4803 | } |
| 4804 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4805 | TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) { |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4806 | // Initiate Draw w/o a PSO bound |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4807 | VkResult err; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4808 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 4809 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4810 | "Unable to allocate 1 descriptors of " |
| 4811 | "type " |
| 4812 | "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4813 | |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4814 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4815 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4816 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4817 | // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer |
| 4818 | // descriptor from it |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 4819 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4820 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 4821 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4822 | |
| 4823 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4824 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 4825 | ds_pool_ci.pNext = NULL; |
| 4826 | ds_pool_ci.flags = 0; |
| 4827 | ds_pool_ci.maxSets = 1; |
| 4828 | ds_pool_ci.poolSizeCount = 1; |
| 4829 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4830 | |
| 4831 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4832 | err = |
| 4833 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4834 | ASSERT_VK_SUCCESS(err); |
| 4835 | |
| 4836 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4837 | dsl_binding.binding = 0; |
| 4838 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4839 | dsl_binding.descriptorCount = 1; |
| 4840 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 4841 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4842 | |
| 4843 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4844 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4845 | ds_layout_ci.pNext = NULL; |
| 4846 | ds_layout_ci.bindingCount = 1; |
| 4847 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4848 | |
| 4849 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4850 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 4851 | &ds_layout); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4852 | ASSERT_VK_SUCCESS(err); |
| 4853 | |
| 4854 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 4855 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 4856 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4857 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 4858 | alloc_info.descriptorPool = ds_pool; |
| 4859 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4860 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 4861 | &descriptorSet); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4862 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4863 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4864 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 4865 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 4866 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4867 | } |
| 4868 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4869 | TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) { |
| 4870 | VkResult err; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4871 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4872 | m_errorMonitor->SetDesiredFailureMsg( |
| 4873 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4874 | "It is invalid to call vkFreeDescriptorSets() with a pool created " |
| 4875 | "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4876 | |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4877 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4878 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4879 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 4880 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4881 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4882 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4883 | |
| 4884 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4885 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 4886 | ds_pool_ci.pNext = NULL; |
| 4887 | ds_pool_ci.maxSets = 1; |
| 4888 | ds_pool_ci.poolSizeCount = 1; |
| 4889 | ds_pool_ci.flags = 0; |
| 4890 | // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means |
| 4891 | // app can only call vkResetDescriptorPool on this pool.; |
| 4892 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4893 | |
| 4894 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4895 | err = |
| 4896 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4897 | ASSERT_VK_SUCCESS(err); |
| 4898 | |
| 4899 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4900 | dsl_binding.binding = 0; |
| 4901 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4902 | dsl_binding.descriptorCount = 1; |
| 4903 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 4904 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4905 | |
| 4906 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4907 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4908 | ds_layout_ci.pNext = NULL; |
| 4909 | ds_layout_ci.bindingCount = 1; |
| 4910 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4911 | |
| 4912 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4913 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 4914 | &ds_layout); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4915 | ASSERT_VK_SUCCESS(err); |
| 4916 | |
| 4917 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 4918 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 4919 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4920 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 4921 | alloc_info.descriptorPool = ds_pool; |
| 4922 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4923 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 4924 | &descriptorSet); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4925 | ASSERT_VK_SUCCESS(err); |
| 4926 | |
| 4927 | err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4928 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4929 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 4930 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 4931 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4932 | } |
| 4933 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4934 | TEST_F(VkLayerTest, InvalidDescriptorPool) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4935 | // Attempt to clear Descriptor Pool with bad object. |
| 4936 | // ObjectTracker should catch this. |
| 4937 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4938 | "Invalid VkDescriptorPool Object 0xbaad6001"); |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4939 | uint64_t fake_pool_handle = 0xbaad6001; |
| 4940 | VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle); |
| 4941 | vkResetDescriptorPool(device(), bad_pool, 0); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4942 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4943 | } |
| 4944 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4945 | TEST_F(VkLayerTest, InvalidDescriptorSet) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4946 | // Attempt to bind an invalid Descriptor Set to a valid Command Buffer |
| 4947 | // ObjectTracker should catch this. |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4948 | // Create a valid cmd buffer |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4949 | // call vkCmdBindDescriptorSets w/ false Descriptor Set |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4950 | |
| 4951 | uint64_t fake_set_handle = 0xbaad6001; |
| 4952 | VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4953 | VkResult err; |
| 4954 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4955 | "Invalid VkDescriptorSet Object 0xbaad6001"); |
| 4956 | |
| 4957 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4958 | |
| 4959 | VkDescriptorSetLayoutBinding layout_bindings[1] = {}; |
| 4960 | layout_bindings[0].binding = 0; |
| 4961 | layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4962 | layout_bindings[0].descriptorCount = 1; |
| 4963 | layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; |
| 4964 | layout_bindings[0].pImmutableSamplers = NULL; |
| 4965 | |
| 4966 | VkDescriptorSetLayout descriptor_set_layout; |
| 4967 | VkDescriptorSetLayoutCreateInfo dslci = {}; |
| 4968 | dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4969 | dslci.pNext = NULL; |
| 4970 | dslci.bindingCount = 1; |
| 4971 | dslci.pBindings = layout_bindings; |
| 4972 | err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout); |
Karl Schultz | 5cb2111 | 2016-04-21 17:17:40 -0600 | [diff] [blame] | 4973 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4974 | |
| 4975 | VkPipelineLayout pipeline_layout; |
| 4976 | VkPipelineLayoutCreateInfo plci = {}; |
| 4977 | plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 4978 | plci.pNext = NULL; |
| 4979 | plci.setLayoutCount = 1; |
| 4980 | plci.pSetLayouts = &descriptor_set_layout; |
| 4981 | err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout); |
Karl Schultz | 5cb2111 | 2016-04-21 17:17:40 -0600 | [diff] [blame] | 4982 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4983 | |
| 4984 | BeginCommandBuffer(); |
| 4985 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4986 | pipeline_layout, 0, 1, &bad_set, 0, NULL); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4987 | m_errorMonitor->VerifyFound(); |
| 4988 | EndCommandBuffer(); |
| 4989 | vkDestroyPipelineLayout(device(), pipeline_layout, NULL); |
| 4990 | vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4991 | } |
| 4992 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4993 | TEST_F(VkLayerTest, InvalidDescriptorSetLayout) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4994 | // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout. |
| 4995 | // ObjectTracker should catch this. |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4996 | uint64_t fake_layout_handle = 0xbaad6001; |
| 4997 | VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4998 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4999 | "Invalid VkDescriptorSetLayout Object 0xbaad6001"); |
| 5000 | |
| 5001 | VkPipelineLayout pipeline_layout; |
| 5002 | VkPipelineLayoutCreateInfo plci = {}; |
| 5003 | plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5004 | plci.pNext = NULL; |
| 5005 | plci.setLayoutCount = 1; |
| 5006 | plci.pSetLayouts = &bad_layout; |
| 5007 | vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout); |
| 5008 | |
| 5009 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5010 | } |
| 5011 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5012 | TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) { |
| 5013 | TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec " |
| 5014 | "1) A uniform buffer update must have a valid buffer index." |
| 5015 | "2) When using an array of descriptors in a single WriteDescriptor," |
| 5016 | " the descriptor types and stageflags must all be the same." |
| 5017 | "3) Immutable Sampler state must match across descriptors"); |
| 5018 | |
| 5019 | const char *invalid_BufferInfo_ErrorMessage = |
| 5020 | "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, " |
| 5021 | "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or " |
| 5022 | "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL"; |
| 5023 | const char *stateFlag_ErrorMessage = |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5024 | "Attempting write update to descriptor set "; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5025 | const char *immutable_ErrorMessage = |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5026 | "Attempting write update to descriptor set "; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5027 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5028 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage); |
| 5029 | |
| 5030 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5031 | VkDescriptorPoolSize ds_type_count[4] = {}; |
| 5032 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5033 | ds_type_count[0].descriptorCount = 1; |
| 5034 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 5035 | ds_type_count[1].descriptorCount = 1; |
| 5036 | ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 5037 | ds_type_count[2].descriptorCount = 1; |
| 5038 | ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 5039 | ds_type_count[3].descriptorCount = 1; |
| 5040 | |
| 5041 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 5042 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5043 | ds_pool_ci.maxSets = 1; |
| 5044 | ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize); |
| 5045 | ds_pool_ci.pPoolSizes = ds_type_count; |
| 5046 | |
| 5047 | VkDescriptorPool ds_pool; |
| 5048 | VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 5049 | ASSERT_VK_SUCCESS(err); |
| 5050 | |
Mark Mueller | b989672 | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5051 | VkDescriptorSetLayoutBinding layout_binding[3] = {}; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5052 | layout_binding[0].binding = 0; |
| 5053 | layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5054 | layout_binding[0].descriptorCount = 1; |
| 5055 | layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 5056 | layout_binding[0].pImmutableSamplers = NULL; |
| 5057 | |
| 5058 | layout_binding[1].binding = 1; |
| 5059 | layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 5060 | layout_binding[1].descriptorCount = 1; |
| 5061 | layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; |
| 5062 | layout_binding[1].pImmutableSamplers = NULL; |
| 5063 | |
| 5064 | VkSamplerCreateInfo sampler_ci = {}; |
| 5065 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 5066 | sampler_ci.pNext = NULL; |
| 5067 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 5068 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 5069 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 5070 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 5071 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 5072 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 5073 | sampler_ci.mipLodBias = 1.0; |
| 5074 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 5075 | sampler_ci.maxAnisotropy = 1; |
| 5076 | sampler_ci.compareEnable = VK_FALSE; |
| 5077 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 5078 | sampler_ci.minLod = 1.0; |
| 5079 | sampler_ci.maxLod = 1.0; |
| 5080 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 5081 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
| 5082 | VkSampler sampler; |
| 5083 | |
| 5084 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
| 5085 | ASSERT_VK_SUCCESS(err); |
| 5086 | |
| 5087 | layout_binding[2].binding = 2; |
| 5088 | layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 5089 | layout_binding[2].descriptorCount = 1; |
| 5090 | layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; |
| 5091 | layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler); |
| 5092 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5093 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 5094 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5095 | ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding); |
| 5096 | ds_layout_ci.pBindings = layout_binding; |
| 5097 | VkDescriptorSetLayout ds_layout; |
| 5098 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout); |
| 5099 | ASSERT_VK_SUCCESS(err); |
| 5100 | |
| 5101 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 5102 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 5103 | alloc_info.descriptorSetCount = 1; |
| 5104 | alloc_info.descriptorPool = ds_pool; |
| 5105 | alloc_info.pSetLayouts = &ds_layout; |
| 5106 | VkDescriptorSet descriptorSet; |
| 5107 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet); |
| 5108 | ASSERT_VK_SUCCESS(err); |
| 5109 | |
| 5110 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 5111 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5112 | pipeline_layout_ci.pNext = NULL; |
| 5113 | pipeline_layout_ci.setLayoutCount = 1; |
| 5114 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 5115 | |
| 5116 | VkPipelineLayout pipeline_layout; |
| 5117 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout); |
| 5118 | ASSERT_VK_SUCCESS(err); |
| 5119 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5120 | VkWriteDescriptorSet descriptor_write = {}; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5121 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5122 | descriptor_write.dstSet = descriptorSet; |
| 5123 | descriptor_write.dstBinding = 0; |
| 5124 | descriptor_write.descriptorCount = 1; |
| 5125 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5126 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5127 | // 1) The uniform buffer is intentionally invalid here |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5128 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5129 | m_errorMonitor->VerifyFound(); |
| 5130 | |
| 5131 | // Create a buffer to update the descriptor with |
| 5132 | uint32_t qfi = 0; |
| 5133 | VkBufferCreateInfo buffCI = {}; |
| 5134 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 5135 | buffCI.size = 1024; |
| 5136 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 5137 | buffCI.queueFamilyIndexCount = 1; |
| 5138 | buffCI.pQueueFamilyIndices = &qfi; |
| 5139 | |
| 5140 | VkBuffer dyub; |
| 5141 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 5142 | ASSERT_VK_SUCCESS(err); |
| 5143 | VkDescriptorBufferInfo buffInfo = {}; |
| 5144 | buffInfo.buffer = dyub; |
| 5145 | buffInfo.offset = 0; |
| 5146 | buffInfo.range = 1024; |
| 5147 | |
| 5148 | descriptor_write.pBufferInfo = &buffInfo; |
| 5149 | descriptor_write.descriptorCount = 2; |
| 5150 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5151 | // 2) The stateFlags don't match between the first and second descriptor |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5152 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage); |
| 5153 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5154 | m_errorMonitor->VerifyFound(); |
| 5155 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5156 | // 3) The second descriptor has a null_ptr pImmutableSamplers and |
| 5157 | // the third descriptor contains an immutable sampler |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5158 | descriptor_write.dstBinding = 1; |
| 5159 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5160 | |
| 5161 | |
| 5162 | // Make pImageInfo index non-null to avoid complaints of it missing |
| 5163 | VkDescriptorImageInfo imageInfo = {}; |
| 5164 | imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 5165 | descriptor_write.pImageInfo = &imageInfo; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5166 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage); |
| 5167 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5168 | m_errorMonitor->VerifyFound(); |
| 5169 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5170 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
| 5171 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 5172 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5173 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5174 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 5175 | } |
| 5176 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5177 | TEST_F(VkLayerTest, InvalidPipeline) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5178 | // Attempt to bind an invalid Pipeline to a valid Command Buffer |
| 5179 | // ObjectTracker should catch this. |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5180 | // Create a valid cmd buffer |
| 5181 | // call vkCmdBindPipeline w/ false Pipeline |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5182 | uint64_t fake_pipeline_handle = 0xbaad6001; |
| 5183 | VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5184 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5185 | "Invalid VkPipeline Object 0xbaad6001"); |
| 5186 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5187 | BeginCommandBuffer(); |
| 5188 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 5189 | VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline); |
| 5190 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 5191 | // Now issue a draw call with no pipeline bound |
| 5192 | m_errorMonitor->SetDesiredFailureMsg( |
| 5193 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5194 | "At Draw/Dispatch time no valid VkPipeline is bound!"); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 5195 | |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 5196 | BeginCommandBuffer(); |
| 5197 | Draw(1, 0, 0, 0); |
| 5198 | m_errorMonitor->VerifyFound(); |
| 5199 | // Finally same check once more but with Dispatch/Compute |
| 5200 | m_errorMonitor->SetDesiredFailureMsg( |
| 5201 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5202 | "At Draw/Dispatch time no valid VkPipeline is bound!"); |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 5203 | BeginCommandBuffer(); |
| 5204 | vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0); |
| 5205 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5206 | } |
| 5207 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5208 | TEST_F(VkLayerTest, DescriptorSetNotUpdated) { |
| 5209 | // Create and update CommandBuffer then call QueueSubmit w/o calling End on |
| 5210 | // CommandBuffer |
| 5211 | VkResult err; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5212 | |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 5213 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5214 | " bound but it was never updated. "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5215 | |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5216 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 5217 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5218 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 5219 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5220 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5221 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5222 | |
| 5223 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5224 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5225 | ds_pool_ci.pNext = NULL; |
| 5226 | ds_pool_ci.maxSets = 1; |
| 5227 | ds_pool_ci.poolSizeCount = 1; |
| 5228 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 5229 | |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5230 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5231 | err = |
| 5232 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5233 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5234 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5235 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5236 | dsl_binding.binding = 0; |
| 5237 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5238 | dsl_binding.descriptorCount = 1; |
| 5239 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5240 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5241 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5242 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5243 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5244 | ds_layout_ci.pNext = NULL; |
| 5245 | ds_layout_ci.bindingCount = 1; |
| 5246 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5247 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5248 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5249 | &ds_layout); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5250 | ASSERT_VK_SUCCESS(err); |
| 5251 | |
| 5252 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5253 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5254 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5255 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 5256 | alloc_info.descriptorPool = ds_pool; |
| 5257 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5258 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5259 | &descriptorSet); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5260 | ASSERT_VK_SUCCESS(err); |
| 5261 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5262 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5263 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5264 | pipeline_layout_ci.pNext = NULL; |
| 5265 | pipeline_layout_ci.setLayoutCount = 1; |
| 5266 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5267 | |
| 5268 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5269 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5270 | &pipeline_layout); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5271 | ASSERT_VK_SUCCESS(err); |
| 5272 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5273 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 5274 | VK_SHADER_STAGE_VERTEX_BIT, this); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5275 | // 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] | 5276 | // on more devices |
| 5277 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 5278 | VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5279 | |
Tony Barbour | c95e4ac | 2015-08-04 17:05:26 -0600 | [diff] [blame] | 5280 | VkPipelineObj pipe(m_device); |
| 5281 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 5282 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 5283 | pipe.AddColorAttachment(); |
Tony Barbour | c95e4ac | 2015-08-04 17:05:26 -0600 | [diff] [blame] | 5284 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 5285 | |
| 5286 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5287 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 5288 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 5289 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5290 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5291 | 1, &descriptorSet, 0, NULL); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5292 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5293 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 5294 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 5295 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5296 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5297 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 5298 | } |
| 5299 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5300 | TEST_F(VkLayerTest, InvalidBufferViewObject) { |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5301 | // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5302 | VkResult err; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5303 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5304 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5305 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer " |
| 5306 | "descriptor with invalid buffer view"); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5307 | |
| 5308 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5309 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5310 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5311 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5312 | |
| 5313 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5314 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5315 | ds_pool_ci.pNext = NULL; |
| 5316 | ds_pool_ci.maxSets = 1; |
| 5317 | ds_pool_ci.poolSizeCount = 1; |
| 5318 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5319 | |
| 5320 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5321 | err = |
| 5322 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5323 | ASSERT_VK_SUCCESS(err); |
| 5324 | |
| 5325 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5326 | dsl_binding.binding = 0; |
| 5327 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5328 | dsl_binding.descriptorCount = 1; |
| 5329 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5330 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5331 | |
| 5332 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5333 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5334 | ds_layout_ci.pNext = NULL; |
| 5335 | ds_layout_ci.bindingCount = 1; |
| 5336 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5337 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5338 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5339 | &ds_layout); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5340 | ASSERT_VK_SUCCESS(err); |
| 5341 | |
| 5342 | VkDescriptorSet descriptorSet; |
| 5343 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5344 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5345 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5346 | alloc_info.descriptorPool = ds_pool; |
| 5347 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5348 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5349 | &descriptorSet); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5350 | ASSERT_VK_SUCCESS(err); |
| 5351 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5352 | VkBufferView view = |
| 5353 | (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5354 | VkWriteDescriptorSet descriptor_write; |
| 5355 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 5356 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5357 | descriptor_write.dstSet = descriptorSet; |
| 5358 | descriptor_write.dstBinding = 0; |
| 5359 | descriptor_write.descriptorCount = 1; |
| 5360 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5361 | descriptor_write.pTexelBufferView = &view; |
| 5362 | |
| 5363 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5364 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5365 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5366 | |
| 5367 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5368 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 5369 | } |
| 5370 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5371 | TEST_F(VkLayerTest, InvalidDynamicOffsetCases) { |
| 5372 | // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error |
| 5373 | // cases: |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5374 | // 1. No dynamicOffset supplied |
| 5375 | // 2. Too many dynamicOffsets supplied |
| 5376 | // 3. Dynamic offset oversteps buffer being updated |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5377 | VkResult err; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 5378 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5379 | " requires 1 dynamicOffsets, but only " |
| 5380 | "0 dynamicOffsets are left in " |
| 5381 | "pDynamicOffsets "); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5382 | |
| 5383 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5384 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5385 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5386 | |
| 5387 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5388 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 5389 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5390 | |
| 5391 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5392 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5393 | ds_pool_ci.pNext = NULL; |
| 5394 | ds_pool_ci.maxSets = 1; |
| 5395 | ds_pool_ci.poolSizeCount = 1; |
| 5396 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5397 | |
| 5398 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5399 | err = |
| 5400 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5401 | ASSERT_VK_SUCCESS(err); |
| 5402 | |
| 5403 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5404 | dsl_binding.binding = 0; |
| 5405 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 5406 | dsl_binding.descriptorCount = 1; |
| 5407 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5408 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5409 | |
| 5410 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5411 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5412 | ds_layout_ci.pNext = NULL; |
| 5413 | ds_layout_ci.bindingCount = 1; |
| 5414 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5415 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5416 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5417 | &ds_layout); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5418 | ASSERT_VK_SUCCESS(err); |
| 5419 | |
| 5420 | VkDescriptorSet descriptorSet; |
| 5421 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5422 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5423 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5424 | alloc_info.descriptorPool = ds_pool; |
| 5425 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5426 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5427 | &descriptorSet); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5428 | ASSERT_VK_SUCCESS(err); |
| 5429 | |
| 5430 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5431 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5432 | pipeline_layout_ci.pNext = NULL; |
| 5433 | pipeline_layout_ci.setLayoutCount = 1; |
| 5434 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5435 | |
| 5436 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5437 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5438 | &pipeline_layout); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5439 | ASSERT_VK_SUCCESS(err); |
| 5440 | |
| 5441 | // Create a buffer to update the descriptor with |
| 5442 | uint32_t qfi = 0; |
| 5443 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5444 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 5445 | buffCI.size = 1024; |
| 5446 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 5447 | buffCI.queueFamilyIndexCount = 1; |
| 5448 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5449 | |
| 5450 | VkBuffer dyub; |
| 5451 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 5452 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5453 | // Allocate memory and bind to buffer so we can make it to the appropriate |
| 5454 | // error |
| 5455 | VkMemoryAllocateInfo mem_alloc = {}; |
| 5456 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 5457 | mem_alloc.pNext = NULL; |
| 5458 | mem_alloc.allocationSize = 1024; |
Chris Forbes | b6116cc | 2016-05-08 11:39:59 +1200 | [diff] [blame] | 5459 | mem_alloc.memoryTypeIndex = 0; |
| 5460 | |
| 5461 | VkMemoryRequirements memReqs; |
| 5462 | vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs); |
| 5463 | bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, |
| 5464 | 0); |
| 5465 | if (!pass) { |
| 5466 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
| 5467 | return; |
| 5468 | } |
| 5469 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5470 | VkDeviceMemory mem; |
| 5471 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 5472 | ASSERT_VK_SUCCESS(err); |
| 5473 | err = vkBindBufferMemory(m_device->device(), dyub, mem, 0); |
| 5474 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5475 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 5476 | VkDescriptorBufferInfo buffInfo = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5477 | buffInfo.buffer = dyub; |
| 5478 | buffInfo.offset = 0; |
| 5479 | buffInfo.range = 1024; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5480 | |
| 5481 | VkWriteDescriptorSet descriptor_write; |
| 5482 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 5483 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5484 | descriptor_write.dstSet = descriptorSet; |
| 5485 | descriptor_write.dstBinding = 0; |
| 5486 | descriptor_write.descriptorCount = 1; |
| 5487 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 5488 | descriptor_write.pBufferInfo = &buffInfo; |
| 5489 | |
| 5490 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5491 | |
| 5492 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5493 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5494 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5495 | 1, &descriptorSet, 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5496 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5497 | uint32_t pDynOff[2] = {512, 756}; |
| 5498 | // 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] | 5499 | m_errorMonitor->SetDesiredFailureMsg( |
| 5500 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5501 | "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5502 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5503 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5504 | 1, &descriptorSet, 2, pDynOff); |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5505 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5506 | // Finally cause error due to dynamicOffset being too big |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5507 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5508 | " dynamic offset 512 combined with " |
| 5509 | "offset 0 and range 1024 that " |
| 5510 | "oversteps the buffer size of 1024"); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5511 | // Create PSO to be used for draw-time errors below |
| 5512 | char const *vsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5513 | "#version 450\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5514 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 5515 | "out gl_PerVertex { \n" |
| 5516 | " vec4 gl_Position;\n" |
| 5517 | "};\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5518 | "void main(){\n" |
| 5519 | " gl_Position = vec4(1);\n" |
| 5520 | "}\n"; |
| 5521 | char const *fsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5522 | "#version 450\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5523 | "\n" |
| 5524 | "layout(location=0) out vec4 x;\n" |
| 5525 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 5526 | "void main(){\n" |
| 5527 | " x = vec4(bar.y);\n" |
| 5528 | "}\n"; |
| 5529 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 5530 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 5531 | VkPipelineObj pipe(m_device); |
| 5532 | pipe.AddShader(&vs); |
| 5533 | pipe.AddShader(&fs); |
| 5534 | pipe.AddColorAttachment(); |
| 5535 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 5536 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5537 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 5538 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 5539 | // This update should succeed, but offset size of 512 will overstep buffer |
| 5540 | // /w range 1024 & size 1024 |
| 5541 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5542 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5543 | 1, &descriptorSet, 1, pDynOff); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5544 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5545 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5546 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5547 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
Tobin Ehlis | 512098e | 2016-05-05 09:06:12 -0600 | [diff] [blame] | 5548 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5549 | |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5550 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 5551 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5552 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 5553 | } |
| 5554 | |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5555 | TEST_F(VkLayerTest, InvalidPushConstants) { |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5556 | VkResult err; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5557 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5558 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5559 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5560 | |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5561 | VkPipelineLayout pipeline_layout; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5562 | VkPushConstantRange pc_range = {}; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5563 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 5564 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5565 | pipeline_layout_ci.pushConstantRangeCount = 1; |
| 5566 | pipeline_layout_ci.pPushConstantRanges = &pc_range; |
| 5567 | |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5568 | // |
| 5569 | // Check for invalid push constant ranges in pipeline layouts. |
| 5570 | // |
| 5571 | struct PipelineLayoutTestCase { |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5572 | VkPushConstantRange const range; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5573 | char const *msg; |
| 5574 | }; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5575 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5576 | const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4; |
| 5577 | const std::array<PipelineLayoutTestCase, 10> range_tests = {{ |
| 5578 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, |
| 5579 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5580 | "size 0."}, |
| 5581 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1}, |
| 5582 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5583 | "size 1."}, |
| 5584 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1}, |
| 5585 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5586 | "size 1."}, |
| 5587 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0}, |
| 5588 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5589 | "size 0."}, |
| 5590 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4}, |
| 5591 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5592 | "offset 1. Offset must"}, |
| 5593 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big}, |
| 5594 | "vkCreatePipelineLayout() call has push constants index 0 " |
| 5595 | "with offset "}, |
| 5596 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big}, |
| 5597 | "vkCreatePipelineLayout() call has push constants " |
| 5598 | "index 0 with offset "}, |
| 5599 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0}, |
| 5600 | "vkCreatePipelineLayout() call has push constants index 0 " |
| 5601 | "with offset "}, |
| 5602 | {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020}, |
| 5603 | "vkCreatePipelineLayout() call has push " |
| 5604 | "constants index 0 with offset "}, |
| 5605 | {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0}, |
| 5606 | "vkCreatePipelineLayout() call has push " |
| 5607 | "constants index 0 with offset "}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5608 | }}; |
| 5609 | |
| 5610 | // Check for invalid offset and size |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5611 | for (const auto &iter : range_tests) { |
| 5612 | pc_range = iter.range; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5613 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5614 | iter.msg); |
| 5615 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 5616 | NULL, &pipeline_layout); |
| 5617 | m_errorMonitor->VerifyFound(); |
| 5618 | if (VK_SUCCESS == err) { |
| 5619 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5620 | } |
| 5621 | } |
| 5622 | |
| 5623 | // Check for invalid stage flag |
| 5624 | pc_range.offset = 0; |
| 5625 | pc_range.size = 16; |
| 5626 | pc_range.stageFlags = 0; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5627 | m_errorMonitor->SetDesiredFailureMsg( |
| 5628 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5629 | "vkCreatePipelineLayout() call has no stageFlags set."); |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5630 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5631 | &pipeline_layout); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5632 | m_errorMonitor->VerifyFound(); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5633 | if (VK_SUCCESS == err) { |
| 5634 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5635 | } |
| 5636 | |
| 5637 | // Check for overlapping ranges |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5638 | const uint32_t ranges_per_test = 5; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5639 | struct OverlappingRangeTestCase { |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5640 | VkPushConstantRange const ranges[ranges_per_test]; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5641 | char const *msg; |
| 5642 | }; |
| 5643 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5644 | const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5645 | {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5646 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5647 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5648 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5649 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5650 | "vkCreatePipelineLayout() call has push constants with overlapping " |
| 5651 | "ranges: 0:[0, 4), 1:[0, 4)"}, |
| 5652 | { |
| 5653 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5654 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5655 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5656 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 5657 | {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}}, |
| 5658 | "vkCreatePipelineLayout() call has push constants with " |
| 5659 | "overlapping " |
| 5660 | "ranges: 3:[12, 20), 4:[16, 20)", |
| 5661 | }, |
| 5662 | { |
| 5663 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5664 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 5665 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5666 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5667 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5668 | "vkCreatePipelineLayout() call has push constants with " |
| 5669 | "overlapping " |
| 5670 | "ranges: 0:[16, 20), 1:[12, 20)", |
| 5671 | }, |
| 5672 | { |
| 5673 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5674 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5675 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5676 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 5677 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5678 | "vkCreatePipelineLayout() call has push constants with " |
| 5679 | "overlapping " |
| 5680 | "ranges: 0:[16, 20), 3:[12, 20)", |
| 5681 | }, |
| 5682 | { |
| 5683 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5684 | {VK_SHADER_STAGE_VERTEX_BIT, 32, 4}, |
| 5685 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 96}, |
| 5686 | {VK_SHADER_STAGE_VERTEX_BIT, 40, 8}, |
| 5687 | {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}}, |
| 5688 | "vkCreatePipelineLayout() call has push constants with " |
| 5689 | "overlapping " |
| 5690 | "ranges: 0:[16, 20), 2:[4, 100)", |
| 5691 | }}}; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5692 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5693 | for (const auto &iter : overlapping_range_tests) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5694 | pipeline_layout_ci.pPushConstantRanges = iter.ranges; |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5695 | pipeline_layout_ci.pushConstantRangeCount = ranges_per_test; |
| 5696 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5697 | iter.msg); |
| 5698 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 5699 | NULL, &pipeline_layout); |
| 5700 | m_errorMonitor->VerifyFound(); |
| 5701 | if (VK_SUCCESS == err) { |
| 5702 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5703 | } |
| 5704 | } |
| 5705 | |
| 5706 | // 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] | 5707 | const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = |
| 5708 | {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5709 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5710 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5711 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 4}, |
| 5712 | {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}}, |
| 5713 | ""}, |
| 5714 | {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24}, |
| 5715 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 4}, |
| 5716 | {VK_SHADER_STAGE_VERTEX_BIT, 64, 8}, |
| 5717 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 16}, |
| 5718 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5719 | ""}}}; |
| 5720 | for (const auto &iter : overlapping_range_tests_pos) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5721 | pipeline_layout_ci.pPushConstantRanges = iter.ranges; |
| 5722 | m_errorMonitor->ExpectSuccess(); |
| 5723 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 5724 | NULL, &pipeline_layout); |
| 5725 | m_errorMonitor->VerifyNotFound(); |
| 5726 | if (VK_SUCCESS == err) { |
| 5727 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5728 | } |
| 5729 | } |
| 5730 | |
| 5731 | // |
| 5732 | // CmdPushConstants tests |
| 5733 | // |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5734 | const uint8_t dummy_values[100] = {}; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5735 | |
| 5736 | // 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] | 5737 | const std::array<PipelineLayoutTestCase, 16> cmd_range_tests = {{ |
| 5738 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, |
| 5739 | "vkCmdPushConstants() call has push constants with size 0. Size " |
| 5740 | "must be greater than zero and a multiple of 4."}, |
| 5741 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1}, |
| 5742 | "vkCmdPushConstants() call has push constants with size 1. Size " |
| 5743 | "must be greater than zero and a multiple of 4."}, |
| 5744 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1}, |
| 5745 | "vkCmdPushConstants() call has push constants with size 1. Size " |
| 5746 | "must be greater than zero and a multiple of 4."}, |
| 5747 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0}, |
| 5748 | "vkCmdPushConstants() call has push constants with offset 1. " |
| 5749 | "Offset must be a multiple of 4."}, |
| 5750 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4}, |
| 5751 | "vkCmdPushConstants() call has push constants with offset 1. " |
| 5752 | "Offset must be a multiple of 4."}, |
| 5753 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20}, |
| 5754 | "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = " |
| 5755 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5756 | {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8}, |
| 5757 | "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = " |
| 5758 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5759 | {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8}, |
| 5760 | "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = " |
| 5761 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5762 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80}, |
| 5763 | "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = " |
| 5764 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5765 | {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4}, |
| 5766 | "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in " |
| 5767 | "any of the ranges in pipeline layout"}, |
| 5768 | {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, |
| 5769 | 0, 16}, |
| 5770 | "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in " |
| 5771 | "any of the ranges in pipeline layout"}, |
| 5772 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5773 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5774 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5775 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5776 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5777 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5778 | {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5779 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5780 | {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5781 | "vkCmdPushConstants() call has push constants with offset "}, |
| 5782 | }}; |
| 5783 | |
| 5784 | // Two ranges for testing robustness |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5785 | const VkPushConstantRange pc_range2[] = { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5786 | {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5787 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5788 | }; |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5789 | pipeline_layout_ci.pushConstantRangeCount = |
| 5790 | sizeof(pc_range2) / sizeof(VkPushConstantRange); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5791 | pipeline_layout_ci.pPushConstantRanges = pc_range2; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5792 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5793 | &pipeline_layout); |
| 5794 | ASSERT_VK_SUCCESS(err); |
| 5795 | BeginCommandBuffer(); |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5796 | for (const auto &iter : cmd_range_tests) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5797 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5798 | iter.msg); |
| 5799 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5800 | iter.range.stageFlags, iter.range.offset, |
| 5801 | iter.range.size, dummy_values); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5802 | m_errorMonitor->VerifyFound(); |
| 5803 | } |
| 5804 | |
| 5805 | // Check for invalid stage flag |
| 5806 | m_errorMonitor->SetDesiredFailureMsg( |
| 5807 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5808 | "vkCmdPushConstants() call has no stageFlags set."); |
| 5809 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5810 | 0, 16, dummy_values); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5811 | m_errorMonitor->VerifyFound(); |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5812 | EndCommandBuffer(); |
| 5813 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
| 5814 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5815 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5816 | // overlapping range tests with cmd |
| 5817 | const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{ |
| 5818 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20}, |
| 5819 | "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = " |
| 5820 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5821 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5822 | "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = " |
| 5823 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5824 | {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16}, |
| 5825 | "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = " |
| 5826 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5827 | }}; |
| 5828 | const VkPushConstantRange pc_range3[] = { |
| 5829 | {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, |
| 5830 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
| 5831 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5832 | {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, |
| 5833 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, |
| 5834 | {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, |
| 5835 | {VK_SHADER_STAGE_VERTEX_BIT, 56, 28}, |
| 5836 | }; |
| 5837 | pipeline_layout_ci.pushConstantRangeCount = |
| 5838 | sizeof(pc_range3) / sizeof(VkPushConstantRange); |
| 5839 | pipeline_layout_ci.pPushConstantRanges = pc_range3; |
| 5840 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5841 | &pipeline_layout); |
| 5842 | ASSERT_VK_SUCCESS(err); |
| 5843 | BeginCommandBuffer(); |
| 5844 | for (const auto &iter : cmd_overlap_tests) { |
| 5845 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5846 | iter.msg); |
| 5847 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
| 5848 | iter.range.stageFlags, iter.range.offset, |
| 5849 | iter.range.size, dummy_values); |
| 5850 | m_errorMonitor->VerifyFound(); |
| 5851 | } |
| 5852 | EndCommandBuffer(); |
| 5853 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
| 5854 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5855 | |
| 5856 | // positive overlapping range tests with cmd |
| 5857 | const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{ |
| 5858 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""}, |
| 5859 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""}, |
| 5860 | {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""}, |
| 5861 | {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""}, |
| 5862 | }}; |
| 5863 | const VkPushConstantRange pc_range4[] = { |
| 5864 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 64}, |
| 5865 | {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, |
| 5866 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
| 5867 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5868 | {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, |
| 5869 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, |
| 5870 | {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, |
| 5871 | {VK_SHADER_STAGE_VERTEX_BIT, 56, 28}, |
| 5872 | }; |
| 5873 | pipeline_layout_ci.pushConstantRangeCount = |
| 5874 | sizeof(pc_range4) / sizeof(VkPushConstantRange); |
| 5875 | pipeline_layout_ci.pPushConstantRanges = pc_range4; |
| 5876 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5877 | &pipeline_layout); |
| 5878 | ASSERT_VK_SUCCESS(err); |
| 5879 | BeginCommandBuffer(); |
| 5880 | for (const auto &iter : cmd_overlap_tests_pos) { |
| 5881 | m_errorMonitor->ExpectSuccess(); |
| 5882 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
| 5883 | iter.range.stageFlags, iter.range.offset, |
| 5884 | iter.range.size, dummy_values); |
| 5885 | m_errorMonitor->VerifyNotFound(); |
| 5886 | } |
| 5887 | EndCommandBuffer(); |
| 5888 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5889 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5890 | } |
| 5891 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5892 | TEST_F(VkLayerTest, DescriptorSetCompatibility) { |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5893 | // Test various desriptorSet errors with bad binding combinations |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5894 | VkResult err; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5895 | |
| 5896 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5897 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5898 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5899 | |
| 5900 | static const uint32_t NUM_DESCRIPTOR_TYPES = 5; |
| 5901 | VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5902 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5903 | ds_type_count[0].descriptorCount = 10; |
| 5904 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 5905 | ds_type_count[1].descriptorCount = 2; |
| 5906 | ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
| 5907 | ds_type_count[2].descriptorCount = 2; |
| 5908 | ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 5909 | ds_type_count[3].descriptorCount = 5; |
| 5910 | // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT |
| 5911 | // type |
| 5912 | // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 5913 | ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
| 5914 | ds_type_count[4].descriptorCount = 2; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5915 | |
| 5916 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5917 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5918 | ds_pool_ci.pNext = NULL; |
| 5919 | ds_pool_ci.maxSets = 5; |
| 5920 | ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES; |
| 5921 | ds_pool_ci.pPoolSizes = ds_type_count; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5922 | |
| 5923 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5924 | err = |
| 5925 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5926 | ASSERT_VK_SUCCESS(err); |
| 5927 | |
| 5928 | static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2; |
| 5929 | VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5930 | dsl_binding[0].binding = 0; |
| 5931 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5932 | dsl_binding[0].descriptorCount = 5; |
| 5933 | dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 5934 | dsl_binding[0].pImmutableSamplers = NULL; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5935 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5936 | // Create layout identical to set0 layout but w/ different stageFlags |
| 5937 | VkDescriptorSetLayoutBinding dsl_fs_stage_only = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5938 | dsl_fs_stage_only.binding = 0; |
| 5939 | dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5940 | dsl_fs_stage_only.descriptorCount = 5; |
| 5941 | dsl_fs_stage_only.stageFlags = |
| 5942 | VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at |
| 5943 | // bind time |
| 5944 | dsl_fs_stage_only.pImmutableSamplers = NULL; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5945 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5946 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5947 | ds_layout_ci.pNext = NULL; |
| 5948 | ds_layout_ci.bindingCount = 1; |
| 5949 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5950 | static const uint32_t NUM_LAYOUTS = 4; |
| 5951 | VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5952 | VkDescriptorSetLayout ds_layout_fs_only = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5953 | // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only |
| 5954 | // layout for error case |
| 5955 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5956 | &ds_layout[0]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5957 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 5958 | ds_layout_ci.pBindings = &dsl_fs_stage_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5959 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5960 | &ds_layout_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5961 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5962 | dsl_binding[0].binding = 0; |
| 5963 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5964 | dsl_binding[0].descriptorCount = 2; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 5965 | dsl_binding[1].binding = 1; |
| 5966 | dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
| 5967 | dsl_binding[1].descriptorCount = 2; |
| 5968 | dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL; |
| 5969 | dsl_binding[1].pImmutableSamplers = NULL; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 5970 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5971 | ds_layout_ci.bindingCount = 2; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5972 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5973 | &ds_layout[1]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5974 | ASSERT_VK_SUCCESS(err); |
| 5975 | dsl_binding[0].binding = 0; |
| 5976 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5977 | dsl_binding[0].descriptorCount = 5; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5978 | ds_layout_ci.bindingCount = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5979 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5980 | &ds_layout[2]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5981 | ASSERT_VK_SUCCESS(err); |
| 5982 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5983 | dsl_binding[0].descriptorCount = 2; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5984 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5985 | &ds_layout[3]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5986 | ASSERT_VK_SUCCESS(err); |
| 5987 | |
| 5988 | static const uint32_t NUM_SETS = 4; |
| 5989 | VkDescriptorSet descriptorSet[NUM_SETS] = {}; |
| 5990 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5991 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5992 | alloc_info.descriptorSetCount = NUM_LAYOUTS; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5993 | alloc_info.descriptorPool = ds_pool; |
| 5994 | alloc_info.pSetLayouts = ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5995 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5996 | descriptorSet); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5997 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5998 | VkDescriptorSet ds0_fs_only = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5999 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6000 | alloc_info.pSetLayouts = &ds_layout_fs_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6001 | err = |
| 6002 | vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6003 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6004 | |
| 6005 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6006 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6007 | pipeline_layout_ci.pNext = NULL; |
| 6008 | pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS; |
| 6009 | pipeline_layout_ci.pSetLayouts = ds_layout; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6010 | |
| 6011 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6012 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6013 | &pipeline_layout); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6014 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6015 | // Create pipelineLayout with only one setLayout |
| 6016 | pipeline_layout_ci.setLayoutCount = 1; |
| 6017 | VkPipelineLayout single_pipe_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6018 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6019 | &single_pipe_layout); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6020 | ASSERT_VK_SUCCESS(err); |
| 6021 | // Create pipelineLayout with 2 descriptor setLayout at index 0 |
| 6022 | pipeline_layout_ci.pSetLayouts = &ds_layout[3]; |
| 6023 | VkPipelineLayout pipe_layout_one_desc; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6024 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6025 | &pipe_layout_one_desc); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6026 | ASSERT_VK_SUCCESS(err); |
| 6027 | // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0 |
| 6028 | pipeline_layout_ci.pSetLayouts = &ds_layout[2]; |
| 6029 | VkPipelineLayout pipe_layout_five_samp; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6030 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6031 | &pipe_layout_five_samp); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6032 | ASSERT_VK_SUCCESS(err); |
| 6033 | // Create pipelineLayout with UB type, but stageFlags for FS only |
| 6034 | pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only; |
| 6035 | VkPipelineLayout pipe_layout_fs_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6036 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6037 | &pipe_layout_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6038 | ASSERT_VK_SUCCESS(err); |
| 6039 | // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine |
| 6040 | VkDescriptorSetLayout pl_bad_s0[2] = {}; |
| 6041 | pl_bad_s0[0] = ds_layout_fs_only; |
| 6042 | pl_bad_s0[1] = ds_layout[1]; |
| 6043 | pipeline_layout_ci.setLayoutCount = 2; |
| 6044 | pipeline_layout_ci.pSetLayouts = pl_bad_s0; |
| 6045 | VkPipelineLayout pipe_layout_bad_set0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6046 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6047 | &pipe_layout_bad_set0); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6048 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6049 | |
| 6050 | // Create a buffer to update the descriptor with |
| 6051 | uint32_t qfi = 0; |
| 6052 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6053 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 6054 | buffCI.size = 1024; |
| 6055 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 6056 | buffCI.queueFamilyIndexCount = 1; |
| 6057 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6058 | |
| 6059 | VkBuffer dyub; |
| 6060 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 6061 | ASSERT_VK_SUCCESS(err); |
| 6062 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 6063 | static const uint32_t NUM_BUFFS = 5; |
| 6064 | VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6065 | for (uint32_t i = 0; i < NUM_BUFFS; ++i) { |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6066 | buffInfo[i].buffer = dyub; |
| 6067 | buffInfo[i].offset = 0; |
| 6068 | buffInfo[i].range = 1024; |
| 6069 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6070 | VkImage image; |
| 6071 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 6072 | const int32_t tex_width = 32; |
| 6073 | const int32_t tex_height = 32; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6074 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6075 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 6076 | image_create_info.pNext = NULL; |
| 6077 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 6078 | image_create_info.format = tex_format; |
| 6079 | image_create_info.extent.width = tex_width; |
| 6080 | image_create_info.extent.height = tex_height; |
| 6081 | image_create_info.extent.depth = 1; |
| 6082 | image_create_info.mipLevels = 1; |
| 6083 | image_create_info.arrayLayers = 1; |
| 6084 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 6085 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 6086 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 6087 | image_create_info.flags = 0; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6088 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 6089 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6090 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6091 | VkMemoryRequirements memReqs; |
| 6092 | VkDeviceMemory imageMem; |
| 6093 | bool pass; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 6094 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6095 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 6096 | memAlloc.pNext = NULL; |
| 6097 | memAlloc.allocationSize = 0; |
| 6098 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 6099 | vkGetImageMemoryRequirements(m_device->device(), image, &memReqs); |
| 6100 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6101 | pass = |
| 6102 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 6103 | ASSERT_TRUE(pass); |
| 6104 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem); |
| 6105 | ASSERT_VK_SUCCESS(err); |
| 6106 | err = vkBindImageMemory(m_device->device(), image, imageMem, 0); |
| 6107 | ASSERT_VK_SUCCESS(err); |
| 6108 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6109 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6110 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 6111 | image_view_create_info.image = image; |
| 6112 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 6113 | image_view_create_info.format = tex_format; |
| 6114 | image_view_create_info.subresourceRange.layerCount = 1; |
| 6115 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 6116 | image_view_create_info.subresourceRange.levelCount = 1; |
| 6117 | image_view_create_info.subresourceRange.aspectMask = |
| 6118 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6119 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6120 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6121 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 6122 | &view); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6123 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6124 | VkDescriptorImageInfo imageInfo[4] = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6125 | imageInfo[0].imageView = view; |
| 6126 | imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 6127 | imageInfo[1].imageView = view; |
| 6128 | imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6129 | imageInfo[2].imageView = view; |
| 6130 | imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 6131 | imageInfo[3].imageView = view; |
| 6132 | imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6133 | |
| 6134 | static const uint32_t NUM_SET_UPDATES = 3; |
| 6135 | VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {}; |
| 6136 | descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 6137 | descriptor_write[0].dstSet = descriptorSet[0]; |
| 6138 | descriptor_write[0].dstBinding = 0; |
| 6139 | descriptor_write[0].descriptorCount = 5; |
| 6140 | descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6141 | descriptor_write[0].pBufferInfo = buffInfo; |
| 6142 | descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 6143 | descriptor_write[1].dstSet = descriptorSet[1]; |
| 6144 | descriptor_write[1].dstBinding = 0; |
| 6145 | descriptor_write[1].descriptorCount = 2; |
| 6146 | descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 6147 | descriptor_write[1].pImageInfo = imageInfo; |
| 6148 | descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 6149 | descriptor_write[2].dstSet = descriptorSet[1]; |
| 6150 | descriptor_write[2].dstBinding = 1; |
| 6151 | descriptor_write[2].descriptorCount = 2; |
| 6152 | descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6153 | descriptor_write[2].pImageInfo = &imageInfo[2]; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6154 | |
| 6155 | vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6156 | |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6157 | // Create PSO to be used for draw-time errors below |
| 6158 | char const *vsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 6159 | "#version 450\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6160 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 6161 | "out gl_PerVertex {\n" |
| 6162 | " vec4 gl_Position;\n" |
| 6163 | "};\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6164 | "void main(){\n" |
| 6165 | " gl_Position = vec4(1);\n" |
| 6166 | "}\n"; |
| 6167 | char const *fsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 6168 | "#version 450\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6169 | "\n" |
| 6170 | "layout(location=0) out vec4 x;\n" |
| 6171 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 6172 | "void main(){\n" |
| 6173 | " x = vec4(bar.y);\n" |
| 6174 | "}\n"; |
| 6175 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6176 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6177 | VkPipelineObj pipe(m_device); |
| 6178 | pipe.AddShader(&vs); |
| 6179 | pipe.AddShader(&fs); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6180 | pipe.AddColorAttachment(); |
| 6181 | pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass()); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6182 | |
| 6183 | BeginCommandBuffer(); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6184 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6185 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 6186 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 6187 | // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding |
| 6188 | // of PSO |
| 6189 | // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of |
| 6190 | // cmd_pipeline.c |
| 6191 | // due to the fact that cmd_alloc_dset_data() has not been called in |
| 6192 | // cmd_bind_graphics_pipeline() |
| 6193 | // TODO : Want to cause various binding incompatibility issues here to test |
| 6194 | // DrawState |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6195 | // First cause various verify_layout_compatibility() fails |
| 6196 | // Second disturb early and late sets and verify INFO msgs |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6197 | // verify_set_layout_compatibility fail cases: |
| 6198 | // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6199 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6200 | " due to: invalid VkPipelineLayout "); |
| 6201 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6202 | VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6203 | (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, |
| 6204 | &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6205 | m_errorMonitor->VerifyFound(); |
| 6206 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6207 | // 2. layoutIndex exceeds # of layouts in layout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6208 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6209 | " attempting to bind set to index 1"); |
| 6210 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6211 | VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, |
| 6212 | 0, 2, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6213 | m_errorMonitor->VerifyFound(); |
| 6214 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6215 | vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6216 | // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5 |
| 6217 | // descriptors |
| 6218 | m_errorMonitor->SetDesiredFailureMsg( |
| 6219 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 6220 | " has 2 descriptors, but DescriptorSetLayout "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6221 | vkCmdBindDescriptorSets( |
| 6222 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6223 | pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6224 | m_errorMonitor->VerifyFound(); |
| 6225 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6226 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL); |
| 6227 | // 4. same # of descriptors but mismatch in type |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6228 | m_errorMonitor->SetDesiredFailureMsg( |
| 6229 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 6230 | " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6231 | vkCmdBindDescriptorSets( |
| 6232 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6233 | pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6234 | m_errorMonitor->VerifyFound(); |
| 6235 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6236 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL); |
| 6237 | // 5. same # of descriptors but mismatch in stageFlags |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6238 | m_errorMonitor->SetDesiredFailureMsg( |
| 6239 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 6240 | " has stageFlags 16 but binding 0 for DescriptorSetLayout "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6241 | vkCmdBindDescriptorSets( |
| 6242 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6243 | pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6244 | m_errorMonitor->VerifyFound(); |
| 6245 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6246 | // Cause INFO messages due to disturbing previously bound Sets |
| 6247 | // First bind sets 0 & 1 |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6248 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6249 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6250 | 2, &descriptorSet[0], 0, NULL); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6251 | // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6252 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 6253 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6254 | " previously bound as set #0 was disturbed "); |
| 6255 | vkCmdBindDescriptorSets( |
| 6256 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6257 | pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6258 | m_errorMonitor->VerifyFound(); |
| 6259 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6260 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6261 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6262 | 2, &descriptorSet[0], 0, NULL); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6263 | // 2. Disturb set after last bound set |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 6264 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6265 | " newly bound as set #0 so set #1 and " |
| 6266 | "any subsequent sets were disturbed "); |
| 6267 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6268 | VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6269 | pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6270 | m_errorMonitor->VerifyFound(); |
| 6271 | |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6272 | // Cause draw-time errors due to PSO incompatibilities |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6273 | // 1. Error due to not binding required set (we actually use same code as |
| 6274 | // above to disturb set0) |
| 6275 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6276 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6277 | 2, &descriptorSet[0], 0, NULL); |
| 6278 | vkCmdBindDescriptorSets( |
| 6279 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6280 | pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL); |
| 6281 | m_errorMonitor->SetDesiredFailureMsg( |
| 6282 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6283 | " uses set #0 but that set is not bound."); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6284 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6285 | m_errorMonitor->VerifyFound(); |
| 6286 | |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6287 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6288 | // 2. Error due to bound set not being compatible with PSO's |
| 6289 | // VkPipelineLayout (diff stageFlags in this case) |
| 6290 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6291 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6292 | 2, &descriptorSet[0], 0, NULL); |
| 6293 | m_errorMonitor->SetDesiredFailureMsg( |
| 6294 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6295 | " bound as set #0 is not compatible with "); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6296 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6297 | m_errorMonitor->VerifyFound(); |
| 6298 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6299 | // Remaining clean-up |
| 6300 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6301 | for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) { |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6302 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL); |
| 6303 | } |
| 6304 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL); |
Tobin Ehlis | 9bfd449 | 2016-05-05 15:09:11 -0600 | [diff] [blame] | 6305 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only); |
| 6306 | vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6307 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6308 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6309 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 6310 | vkFreeMemory(m_device->device(), imageMem, NULL); |
| 6311 | vkDestroyImage(m_device->device(), image, NULL); |
| 6312 | vkDestroyImageView(m_device->device(), view, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6313 | } |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6314 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6315 | TEST_F(VkLayerTest, NoBeginCommandBuffer) { |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6316 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6317 | m_errorMonitor->SetDesiredFailureMsg( |
| 6318 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6319 | "You must call vkBeginCommandBuffer() before this call to "); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6320 | |
| 6321 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6322 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6323 | // Call EndCommandBuffer() w/o calling BeginCommandBuffer() |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6324 | vkEndCommandBuffer(commandBuffer.GetBufferHandle()); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6325 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6326 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6327 | } |
| 6328 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6329 | TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) { |
| 6330 | VkResult err; |
| 6331 | VkCommandBuffer draw_cmd; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6332 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6333 | m_errorMonitor->SetDesiredFailureMsg( |
| 6334 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 61b36f3 | 2015-12-16 08:19:42 -0700 | [diff] [blame] | 6335 | " must specify a valid renderpass parameter."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6336 | |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6337 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6338 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6339 | VkCommandBufferAllocateInfo cmd = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6340 | cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6341 | cmd.pNext = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6342 | cmd.commandPool = m_commandPool; |
| 6343 | cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6344 | cmd.commandBufferCount = 1; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6345 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6346 | err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 6347 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6348 | |
| 6349 | // Force the failure by not setting the Renderpass and Framebuffer fields |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6350 | VkCommandBufferBeginInfo cmd_buf_info = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6351 | VkCommandBufferInheritanceInfo cmd_buf_hinfo = {}; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6352 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6353 | cmd_buf_info.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6354 | cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | |
| 6355 | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6356 | cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo; |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6357 | |
| 6358 | // The error should be caught by validation of the BeginCommandBuffer call |
| 6359 | vkBeginCommandBuffer(draw_cmd, &cmd_buf_info); |
| 6360 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6361 | m_errorMonitor->VerifyFound(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6362 | vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6363 | } |
| 6364 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6365 | TEST_F(VkLayerTest, CommandBufferResetErrors) { |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6366 | // Cause error due to Begin while recording CB |
| 6367 | // Then cause 2 errors for attempting to reset CB w/o having |
| 6368 | // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from |
| 6369 | // which CBs were allocated. Note that this bit is off by default. |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 6370 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6371 | "Cannot call Begin on CB"); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6372 | |
| 6373 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6374 | |
| 6375 | // Calls AllocateCommandBuffers |
| 6376 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
| 6377 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6378 | // Force the failure by setting the Renderpass and Framebuffer fields with |
| 6379 | // (fake) data |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6380 | VkCommandBufferBeginInfo cmd_buf_info = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6381 | VkCommandBufferInheritanceInfo cmd_buf_hinfo = {}; |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6382 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 6383 | cmd_buf_info.pNext = NULL; |
| 6384 | cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6385 | cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo; |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6386 | |
| 6387 | // Begin CB to transition to recording state |
| 6388 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
| 6389 | // Can't re-begin. This should trigger error |
| 6390 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6391 | m_errorMonitor->VerifyFound(); |
| 6392 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6393 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6394 | "Attempt to reset command buffer "); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6395 | VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test |
| 6396 | // Reset attempt will trigger error due to incorrect CommandPool state |
| 6397 | vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6398 | m_errorMonitor->VerifyFound(); |
| 6399 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6400 | m_errorMonitor->SetDesiredFailureMsg( |
| 6401 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6402 | " attempts to implicitly reset cmdBuffer created from "); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6403 | // Transition CB to RECORDED state |
| 6404 | vkEndCommandBuffer(commandBuffer.GetBufferHandle()); |
| 6405 | // Now attempting to Begin will implicitly reset, which triggers error |
| 6406 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6407 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6408 | } |
| 6409 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6410 | TEST_F(VkLayerTest, InvalidPipelineCreateState) { |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6411 | // Attempt to Create Gfx Pipeline w/o a VS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6412 | VkResult err; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6413 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6414 | m_errorMonitor->SetDesiredFailureMsg( |
| 6415 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6416 | "Invalid Pipeline CreateInfo State: Vtx Shader required"); |
| 6417 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6418 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 6419 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 6420 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6421 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6422 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6423 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6424 | |
| 6425 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6426 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6427 | ds_pool_ci.pNext = NULL; |
| 6428 | ds_pool_ci.maxSets = 1; |
| 6429 | ds_pool_ci.poolSizeCount = 1; |
| 6430 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 6431 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6432 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6433 | err = |
| 6434 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6435 | ASSERT_VK_SUCCESS(err); |
| 6436 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6437 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6438 | dsl_binding.binding = 0; |
| 6439 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6440 | dsl_binding.descriptorCount = 1; |
| 6441 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 6442 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6443 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6444 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6445 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6446 | ds_layout_ci.pNext = NULL; |
| 6447 | ds_layout_ci.bindingCount = 1; |
| 6448 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6449 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6450 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6451 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6452 | &ds_layout); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6453 | ASSERT_VK_SUCCESS(err); |
| 6454 | |
| 6455 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6456 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6457 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6458 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6459 | alloc_info.descriptorPool = ds_pool; |
| 6460 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6461 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6462 | &descriptorSet); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6463 | ASSERT_VK_SUCCESS(err); |
| 6464 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6465 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6466 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6467 | pipeline_layout_ci.setLayoutCount = 1; |
| 6468 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6469 | |
| 6470 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6471 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6472 | &pipeline_layout); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6473 | ASSERT_VK_SUCCESS(err); |
| 6474 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6475 | VkViewport vp = {}; // Just need dummy vp to point to |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6476 | VkRect2D sc = {}; // dummy scissor to point to |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6477 | |
| 6478 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6479 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 6480 | vp_state_ci.scissorCount = 1; |
| 6481 | vp_state_ci.pScissors = ≻ |
| 6482 | vp_state_ci.viewportCount = 1; |
| 6483 | vp_state_ci.pViewports = &vp; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6484 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6485 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 6486 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 6487 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 6488 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 6489 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 6490 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 6491 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 6492 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 6493 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6494 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6495 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6496 | gp_ci.pViewportState = &vp_state_ci; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6497 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6498 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6499 | gp_ci.layout = pipeline_layout; |
| 6500 | gp_ci.renderPass = renderPass(); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6501 | |
| 6502 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6503 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 6504 | pc_ci.initialDataSize = 0; |
| 6505 | pc_ci.pInitialData = 0; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6506 | |
| 6507 | VkPipeline pipeline; |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 6508 | VkPipelineCache pipelineCache; |
| 6509 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6510 | err = |
| 6511 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 6512 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6513 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6514 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6515 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6516 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 6517 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6518 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6519 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6520 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6521 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6522 | } |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6523 | /*// TODO : This test should be good, but needs Tess support in compiler to run |
| 6524 | TEST_F(VkLayerTest, InvalidPatchControlPoints) |
| 6525 | { |
| 6526 | // Attempt to Create Gfx Pipeline w/o a VS |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6527 | VkResult err; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6528 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 6529 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6530 | "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH |
| 6531 | primitive "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6532 | |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6533 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6534 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6535 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6536 | VkDescriptorPoolSize ds_type_count = {}; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6537 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6538 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6539 | |
| 6540 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 6541 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6542 | ds_pool_ci.pNext = NULL; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6543 | ds_pool_ci.poolSizeCount = 1; |
| 6544 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6545 | |
| 6546 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6547 | err = vkCreateDescriptorPool(m_device->device(), |
| 6548 | 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] | 6549 | ASSERT_VK_SUCCESS(err); |
| 6550 | |
| 6551 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6552 | dsl_binding.binding = 0; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6553 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | 0212448 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 6554 | dsl_binding.descriptorCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6555 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 6556 | dsl_binding.pImmutableSamplers = NULL; |
| 6557 | |
| 6558 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6559 | ds_layout_ci.sType = |
| 6560 | VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6561 | ds_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6562 | ds_layout_ci.bindingCount = 1; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 6563 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6564 | |
| 6565 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6566 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6567 | &ds_layout); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6568 | ASSERT_VK_SUCCESS(err); |
| 6569 | |
| 6570 | VkDescriptorSet descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6571 | err = vkAllocateDescriptorSets(m_device->device(), ds_pool, |
| 6572 | VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6573 | ASSERT_VK_SUCCESS(err); |
| 6574 | |
| 6575 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6576 | pipeline_layout_ci.sType = |
| 6577 | VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6578 | pipeline_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6579 | pipeline_layout_ci.setLayoutCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6580 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 6581 | |
| 6582 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6583 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6584 | &pipeline_layout); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6585 | ASSERT_VK_SUCCESS(err); |
| 6586 | |
| 6587 | VkPipelineShaderStageCreateInfo shaderStages[3]; |
| 6588 | memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 6589 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6590 | VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, |
| 6591 | this); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6592 | // 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] | 6593 | VkShaderObj |
| 6594 | tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, |
| 6595 | this); |
| 6596 | VkShaderObj |
| 6597 | te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, |
| 6598 | this); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6599 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6600 | shaderStages[0].sType = |
| 6601 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 6602 | shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6603 | shaderStages[0].shader = vs.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6604 | shaderStages[1].sType = |
| 6605 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 6606 | shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6607 | shaderStages[1].shader = tc.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6608 | shaderStages[2].sType = |
| 6609 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 6610 | shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6611 | shaderStages[2].shader = te.handle(); |
| 6612 | |
| 6613 | VkPipelineInputAssemblyStateCreateInfo iaCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6614 | iaCI.sType = |
| 6615 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
Chia-I Wu | 515eb8f | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6616 | iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6617 | |
| 6618 | VkPipelineTessellationStateCreateInfo tsCI = {}; |
| 6619 | tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO; |
| 6620 | tsCI.patchControlPoints = 0; // This will cause an error |
| 6621 | |
| 6622 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 6623 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6624 | gp_ci.pNext = NULL; |
| 6625 | gp_ci.stageCount = 3; |
| 6626 | gp_ci.pStages = shaderStages; |
| 6627 | gp_ci.pVertexInputState = NULL; |
| 6628 | gp_ci.pInputAssemblyState = &iaCI; |
| 6629 | gp_ci.pTessellationState = &tsCI; |
| 6630 | gp_ci.pViewportState = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6631 | gp_ci.pRasterizationState = NULL; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6632 | gp_ci.pMultisampleState = NULL; |
| 6633 | gp_ci.pDepthStencilState = NULL; |
| 6634 | gp_ci.pColorBlendState = NULL; |
| 6635 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6636 | gp_ci.layout = pipeline_layout; |
| 6637 | gp_ci.renderPass = renderPass(); |
| 6638 | |
| 6639 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 6640 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 6641 | pc_ci.pNext = NULL; |
| 6642 | pc_ci.initialSize = 0; |
| 6643 | pc_ci.initialData = 0; |
| 6644 | pc_ci.maxSize = 0; |
| 6645 | |
| 6646 | VkPipeline pipeline; |
| 6647 | VkPipelineCache pipelineCache; |
| 6648 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6649 | err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, |
| 6650 | &pipelineCache); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6651 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6652 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6653 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6654 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6655 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 6656 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6657 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6658 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6659 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6660 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6661 | } |
| 6662 | */ |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6663 | // Set scissor and viewport counts to different numbers |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6664 | TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6665 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6666 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6667 | m_errorMonitor->SetDesiredFailureMsg( |
| 6668 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6669 | "Gfx Pipeline viewport count (1) must match scissor count (0)."); |
| 6670 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6671 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6672 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6673 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6674 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6675 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6676 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6677 | |
| 6678 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6679 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6680 | ds_pool_ci.maxSets = 1; |
| 6681 | ds_pool_ci.poolSizeCount = 1; |
| 6682 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6683 | |
| 6684 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6685 | err = |
| 6686 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6687 | ASSERT_VK_SUCCESS(err); |
| 6688 | |
| 6689 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6690 | dsl_binding.binding = 0; |
| 6691 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6692 | dsl_binding.descriptorCount = 1; |
| 6693 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6694 | |
| 6695 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6696 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6697 | ds_layout_ci.bindingCount = 1; |
| 6698 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6699 | |
| 6700 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6701 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6702 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6703 | ASSERT_VK_SUCCESS(err); |
| 6704 | |
| 6705 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6706 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6707 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6708 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6709 | alloc_info.descriptorPool = ds_pool; |
| 6710 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6711 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6712 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6713 | ASSERT_VK_SUCCESS(err); |
| 6714 | |
| 6715 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6716 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6717 | pipeline_layout_ci.setLayoutCount = 1; |
| 6718 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6719 | |
| 6720 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6721 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6722 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6723 | ASSERT_VK_SUCCESS(err); |
| 6724 | |
| 6725 | VkViewport vp = {}; // Just need dummy vp to point to |
| 6726 | |
| 6727 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6728 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 6729 | vp_state_ci.scissorCount = 0; |
| 6730 | vp_state_ci.viewportCount = 1; // Count mismatch should cause error |
| 6731 | vp_state_ci.pViewports = &vp; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6732 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6733 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 6734 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 6735 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 6736 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 6737 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 6738 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 6739 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 6740 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 6741 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 6742 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6743 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6744 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6745 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 6746 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6747 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 6748 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6749 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6750 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6751 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 6752 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6753 | |
| 6754 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6755 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6756 | gp_ci.stageCount = 2; |
| 6757 | gp_ci.pStages = shaderStages; |
| 6758 | gp_ci.pViewportState = &vp_state_ci; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6759 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6760 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6761 | gp_ci.layout = pipeline_layout; |
| 6762 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6763 | |
| 6764 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6765 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6766 | |
| 6767 | VkPipeline pipeline; |
| 6768 | VkPipelineCache pipelineCache; |
| 6769 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6770 | err = |
| 6771 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6772 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6773 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6774 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6775 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6776 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6777 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6778 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6779 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6780 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6781 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6782 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6783 | // Don't set viewport state in PSO. This is an error b/c we always need this |
| 6784 | // state |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 6785 | // 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] | 6786 | TEST_F(VkLayerTest, PSOViewportStateNotSet) { |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6787 | // Attempt to Create Gfx Pipeline w/o a VS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6788 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6789 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6790 | m_errorMonitor->SetDesiredFailureMsg( |
| 6791 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6792 | "Gfx Pipeline pViewportState is null. Even if "); |
| 6793 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6794 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6795 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6796 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6797 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6798 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6799 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6800 | |
| 6801 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6802 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6803 | ds_pool_ci.maxSets = 1; |
| 6804 | ds_pool_ci.poolSizeCount = 1; |
| 6805 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6806 | |
| 6807 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6808 | err = |
| 6809 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6810 | ASSERT_VK_SUCCESS(err); |
| 6811 | |
| 6812 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6813 | dsl_binding.binding = 0; |
| 6814 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6815 | dsl_binding.descriptorCount = 1; |
| 6816 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6817 | |
| 6818 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6819 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6820 | ds_layout_ci.bindingCount = 1; |
| 6821 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6822 | |
| 6823 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6824 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6825 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6826 | ASSERT_VK_SUCCESS(err); |
| 6827 | |
| 6828 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6829 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6830 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6831 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6832 | alloc_info.descriptorPool = ds_pool; |
| 6833 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6834 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6835 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6836 | ASSERT_VK_SUCCESS(err); |
| 6837 | |
| 6838 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6839 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6840 | pipeline_layout_ci.setLayoutCount = 1; |
| 6841 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6842 | |
| 6843 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6844 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6845 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6846 | ASSERT_VK_SUCCESS(err); |
| 6847 | |
| 6848 | VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR; |
| 6849 | // Set scissor as dynamic to avoid second error |
| 6850 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6851 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 6852 | dyn_state_ci.dynamicStateCount = 1; |
| 6853 | dyn_state_ci.pDynamicStates = &sc_state; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6854 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 6855 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6856 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6857 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6858 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 6859 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6860 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 6861 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6862 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6863 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6864 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 6865 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6866 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6867 | |
| 6868 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 6869 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 6870 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 6871 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 6872 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 6873 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 6874 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 6875 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 6876 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6877 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6878 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6879 | gp_ci.stageCount = 2; |
| 6880 | gp_ci.pStages = shaderStages; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6881 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6882 | gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state |
| 6883 | // should cause validation error |
| 6884 | gp_ci.pDynamicState = &dyn_state_ci; |
| 6885 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6886 | gp_ci.layout = pipeline_layout; |
| 6887 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6888 | |
| 6889 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6890 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6891 | |
| 6892 | VkPipeline pipeline; |
| 6893 | VkPipelineCache pipelineCache; |
| 6894 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6895 | err = |
| 6896 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6897 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6898 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6899 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6900 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6901 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6902 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6903 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6904 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6905 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6906 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6907 | } |
| 6908 | // Create PSO w/o non-zero viewportCount but no viewport data |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6909 | // Then run second test where dynamic scissor count doesn't match PSO scissor |
| 6910 | // count |
| 6911 | TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) { |
| 6912 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6913 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6914 | m_errorMonitor->SetDesiredFailureMsg( |
| 6915 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6916 | "Gfx Pipeline viewportCount is 1, but pViewports is NULL. "); |
| 6917 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6918 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6919 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6920 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6921 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6922 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6923 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6924 | |
| 6925 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6926 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6927 | ds_pool_ci.maxSets = 1; |
| 6928 | ds_pool_ci.poolSizeCount = 1; |
| 6929 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6930 | |
| 6931 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6932 | err = |
| 6933 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6934 | ASSERT_VK_SUCCESS(err); |
| 6935 | |
| 6936 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6937 | dsl_binding.binding = 0; |
| 6938 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6939 | dsl_binding.descriptorCount = 1; |
| 6940 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6941 | |
| 6942 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6943 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6944 | ds_layout_ci.bindingCount = 1; |
| 6945 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6946 | |
| 6947 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6948 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6949 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6950 | ASSERT_VK_SUCCESS(err); |
| 6951 | |
| 6952 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6953 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6954 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6955 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6956 | alloc_info.descriptorPool = ds_pool; |
| 6957 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6958 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6959 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6960 | ASSERT_VK_SUCCESS(err); |
| 6961 | |
| 6962 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6963 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6964 | pipeline_layout_ci.setLayoutCount = 1; |
| 6965 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6966 | |
| 6967 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6968 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6969 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6970 | ASSERT_VK_SUCCESS(err); |
| 6971 | |
| 6972 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6973 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 6974 | vp_state_ci.viewportCount = 1; |
| 6975 | vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error |
| 6976 | vp_state_ci.scissorCount = 1; |
| 6977 | vp_state_ci.pScissors = |
| 6978 | NULL; // Scissor is dynamic (below) so this won't cause error |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6979 | |
| 6980 | VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR; |
| 6981 | // Set scissor as dynamic to avoid that error |
| 6982 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6983 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 6984 | dyn_state_ci.dynamicStateCount = 1; |
| 6985 | dyn_state_ci.pDynamicStates = &sc_state; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6986 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 6987 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6988 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6989 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6990 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 6991 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6992 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 6993 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6994 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6995 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6996 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 6997 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6998 | |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6999 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 7000 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 7001 | vi_ci.pNext = nullptr; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7002 | vi_ci.vertexBindingDescriptionCount = 0; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7003 | vi_ci.pVertexBindingDescriptions = nullptr; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7004 | vi_ci.vertexAttributeDescriptionCount = 0; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7005 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 7006 | |
| 7007 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 7008 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 7009 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 7010 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7011 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7012 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7013 | rs_ci.pNext = nullptr; |
| 7014 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 7015 | VkPipelineColorBlendAttachmentState att = {}; |
| 7016 | att.blendEnable = VK_FALSE; |
| 7017 | att.colorWriteMask = 0xf; |
| 7018 | |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7019 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 7020 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 7021 | cb_ci.pNext = nullptr; |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 7022 | cb_ci.attachmentCount = 1; |
| 7023 | cb_ci.pAttachments = &att; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7024 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7025 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7026 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7027 | gp_ci.stageCount = 2; |
| 7028 | gp_ci.pStages = shaderStages; |
| 7029 | gp_ci.pVertexInputState = &vi_ci; |
| 7030 | gp_ci.pInputAssemblyState = &ia_ci; |
| 7031 | gp_ci.pViewportState = &vp_state_ci; |
| 7032 | gp_ci.pRasterizationState = &rs_ci; |
| 7033 | gp_ci.pColorBlendState = &cb_ci; |
| 7034 | gp_ci.pDynamicState = &dyn_state_ci; |
| 7035 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7036 | gp_ci.layout = pipeline_layout; |
| 7037 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7038 | |
| 7039 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7040 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7041 | |
| 7042 | VkPipeline pipeline; |
| 7043 | VkPipelineCache pipelineCache; |
| 7044 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7045 | err = |
| 7046 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7047 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7048 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7049 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7050 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7051 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7052 | |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7053 | // 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] | 7054 | // First need to successfully create the PSO from above by setting |
| 7055 | // pViewports |
| 7056 | m_errorMonitor->SetDesiredFailureMsg( |
| 7057 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7058 | "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO " |
| 7059 | "scissorCount is 1. These counts must match."); |
| 7060 | |
| 7061 | VkViewport vp = {}; // Just need dummy vp to point to |
| 7062 | vp_state_ci.pViewports = &vp; |
| 7063 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7064 | &gp_ci, NULL, &pipeline); |
| 7065 | ASSERT_VK_SUCCESS(err); |
| 7066 | BeginCommandBuffer(); |
| 7067 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7068 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 7069 | VkRect2D scissors[2] = {}; // don't care about data |
| 7070 | // Count of 2 doesn't match PSO count of 1 |
| 7071 | vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors); |
| 7072 | Draw(1, 0, 0, 0); |
| 7073 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7074 | m_errorMonitor->VerifyFound(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7075 | |
| 7076 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7077 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7078 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7079 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7080 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7081 | } |
| 7082 | // Create PSO w/o non-zero scissorCount but no scissor data |
| 7083 | // Then run second test where dynamic viewportCount doesn't match PSO |
| 7084 | // viewportCount |
| 7085 | TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) { |
| 7086 | VkResult err; |
| 7087 | |
| 7088 | m_errorMonitor->SetDesiredFailureMsg( |
| 7089 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7090 | "Gfx Pipeline scissorCount is 1, but pScissors is NULL. "); |
| 7091 | |
| 7092 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7093 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7094 | |
| 7095 | VkDescriptorPoolSize ds_type_count = {}; |
| 7096 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7097 | ds_type_count.descriptorCount = 1; |
| 7098 | |
| 7099 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 7100 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7101 | ds_pool_ci.maxSets = 1; |
| 7102 | ds_pool_ci.poolSizeCount = 1; |
| 7103 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 7104 | |
| 7105 | VkDescriptorPool ds_pool; |
| 7106 | err = |
| 7107 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 7108 | ASSERT_VK_SUCCESS(err); |
| 7109 | |
| 7110 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 7111 | dsl_binding.binding = 0; |
| 7112 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7113 | dsl_binding.descriptorCount = 1; |
| 7114 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7115 | |
| 7116 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 7117 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7118 | ds_layout_ci.bindingCount = 1; |
| 7119 | ds_layout_ci.pBindings = &dsl_binding; |
| 7120 | |
| 7121 | VkDescriptorSetLayout ds_layout; |
| 7122 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7123 | &ds_layout); |
| 7124 | ASSERT_VK_SUCCESS(err); |
| 7125 | |
| 7126 | VkDescriptorSet descriptorSet; |
| 7127 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 7128 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 7129 | alloc_info.descriptorSetCount = 1; |
| 7130 | alloc_info.descriptorPool = ds_pool; |
| 7131 | alloc_info.pSetLayouts = &ds_layout; |
| 7132 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7133 | &descriptorSet); |
| 7134 | ASSERT_VK_SUCCESS(err); |
| 7135 | |
| 7136 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 7137 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7138 | pipeline_layout_ci.setLayoutCount = 1; |
| 7139 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 7140 | |
| 7141 | VkPipelineLayout pipeline_layout; |
| 7142 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7143 | &pipeline_layout); |
| 7144 | ASSERT_VK_SUCCESS(err); |
| 7145 | |
| 7146 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 7147 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7148 | vp_state_ci.scissorCount = 1; |
| 7149 | vp_state_ci.pScissors = |
| 7150 | NULL; // Null scissor w/ count of 1 should cause error |
| 7151 | vp_state_ci.viewportCount = 1; |
| 7152 | vp_state_ci.pViewports = |
| 7153 | NULL; // vp is dynamic (below) so this won't cause error |
| 7154 | |
| 7155 | VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT; |
| 7156 | // Set scissor as dynamic to avoid that error |
| 7157 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
| 7158 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 7159 | dyn_state_ci.dynamicStateCount = 1; |
| 7160 | dyn_state_ci.pDynamicStates = &vp_state; |
| 7161 | |
| 7162 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
| 7163 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 7164 | |
| 7165 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7166 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7167 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7168 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 7169 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7170 | // but add it to be able to run on more devices |
| 7171 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 7172 | shaderStages[1] = fs.GetStageCreateInfo(); |
| 7173 | |
| 7174 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 7175 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 7176 | vi_ci.pNext = nullptr; |
| 7177 | vi_ci.vertexBindingDescriptionCount = 0; |
| 7178 | vi_ci.pVertexBindingDescriptions = nullptr; |
| 7179 | vi_ci.vertexAttributeDescriptionCount = 0; |
| 7180 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 7181 | |
| 7182 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 7183 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 7184 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 7185 | |
| 7186 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
| 7187 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7188 | rs_ci.pNext = nullptr; |
| 7189 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 7190 | VkPipelineColorBlendAttachmentState att = {}; |
| 7191 | att.blendEnable = VK_FALSE; |
| 7192 | att.colorWriteMask = 0xf; |
| 7193 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7194 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 7195 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 7196 | cb_ci.pNext = nullptr; |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 7197 | cb_ci.attachmentCount = 1; |
| 7198 | cb_ci.pAttachments = &att; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7199 | |
| 7200 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 7201 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7202 | gp_ci.stageCount = 2; |
| 7203 | gp_ci.pStages = shaderStages; |
| 7204 | gp_ci.pVertexInputState = &vi_ci; |
| 7205 | gp_ci.pInputAssemblyState = &ia_ci; |
| 7206 | gp_ci.pViewportState = &vp_state_ci; |
| 7207 | gp_ci.pRasterizationState = &rs_ci; |
| 7208 | gp_ci.pColorBlendState = &cb_ci; |
| 7209 | gp_ci.pDynamicState = &dyn_state_ci; |
| 7210 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7211 | gp_ci.layout = pipeline_layout; |
| 7212 | gp_ci.renderPass = renderPass(); |
| 7213 | |
| 7214 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 7215 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 7216 | |
| 7217 | VkPipeline pipeline; |
| 7218 | VkPipelineCache pipelineCache; |
| 7219 | |
| 7220 | err = |
| 7221 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7222 | ASSERT_VK_SUCCESS(err); |
| 7223 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7224 | &gp_ci, NULL, &pipeline); |
| 7225 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7226 | m_errorMonitor->VerifyFound(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7227 | |
| 7228 | // Now hit second fail case where we set scissor w/ different count than PSO |
| 7229 | // First need to successfully create the PSO from above by setting |
| 7230 | // pViewports |
| 7231 | m_errorMonitor->SetDesiredFailureMsg( |
| 7232 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7233 | "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO " |
| 7234 | "viewportCount is 1. These counts must match."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7235 | |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7236 | VkRect2D sc = {}; // Just need dummy vp to point to |
| 7237 | vp_state_ci.pScissors = ≻ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7238 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7239 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7240 | ASSERT_VK_SUCCESS(err); |
| 7241 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7242 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7243 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7244 | VkViewport viewports[2] = {}; // don't care about data |
| 7245 | // Count of 2 doesn't match PSO count of 1 |
Jon Ashburn | 19d3bf1 | 2015-12-30 14:06:55 -0700 | [diff] [blame] | 7246 | vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7247 | Draw(1, 0, 0, 0); |
| 7248 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7249 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7250 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7251 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7252 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7253 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7254 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7255 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7256 | } |
| 7257 | |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7258 | TEST_F(VkLayerTest, PSOLineWidthInvalid) { |
| 7259 | VkResult err; |
| 7260 | |
| 7261 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7262 | "Attempt to set lineWidth to -1"); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7263 | |
| 7264 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7265 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7266 | |
| 7267 | VkDescriptorPoolSize ds_type_count = {}; |
| 7268 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7269 | ds_type_count.descriptorCount = 1; |
| 7270 | |
| 7271 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 7272 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7273 | ds_pool_ci.maxSets = 1; |
| 7274 | ds_pool_ci.poolSizeCount = 1; |
| 7275 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 7276 | |
| 7277 | VkDescriptorPool ds_pool; |
| 7278 | err = |
| 7279 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 7280 | ASSERT_VK_SUCCESS(err); |
| 7281 | |
| 7282 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 7283 | dsl_binding.binding = 0; |
| 7284 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7285 | dsl_binding.descriptorCount = 1; |
| 7286 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7287 | |
| 7288 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 7289 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7290 | ds_layout_ci.bindingCount = 1; |
| 7291 | ds_layout_ci.pBindings = &dsl_binding; |
| 7292 | |
| 7293 | VkDescriptorSetLayout ds_layout; |
| 7294 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7295 | &ds_layout); |
| 7296 | ASSERT_VK_SUCCESS(err); |
| 7297 | |
| 7298 | VkDescriptorSet descriptorSet; |
| 7299 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 7300 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 7301 | alloc_info.descriptorSetCount = 1; |
| 7302 | alloc_info.descriptorPool = ds_pool; |
| 7303 | alloc_info.pSetLayouts = &ds_layout; |
| 7304 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7305 | &descriptorSet); |
| 7306 | ASSERT_VK_SUCCESS(err); |
| 7307 | |
| 7308 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 7309 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7310 | pipeline_layout_ci.setLayoutCount = 1; |
| 7311 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 7312 | |
| 7313 | VkPipelineLayout pipeline_layout; |
| 7314 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7315 | &pipeline_layout); |
| 7316 | ASSERT_VK_SUCCESS(err); |
| 7317 | |
| 7318 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 7319 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7320 | vp_state_ci.scissorCount = 1; |
| 7321 | vp_state_ci.pScissors = NULL; |
| 7322 | vp_state_ci.viewportCount = 1; |
| 7323 | vp_state_ci.pViewports = NULL; |
| 7324 | |
| 7325 | VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, |
| 7326 | VK_DYNAMIC_STATE_SCISSOR, |
| 7327 | VK_DYNAMIC_STATE_LINE_WIDTH}; |
| 7328 | // Set scissor as dynamic to avoid that error |
| 7329 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
| 7330 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 7331 | dyn_state_ci.dynamicStateCount = 2; |
| 7332 | dyn_state_ci.pDynamicStates = dynamic_states; |
| 7333 | |
| 7334 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
| 7335 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 7336 | |
| 7337 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7338 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7339 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7340 | VK_SHADER_STAGE_FRAGMENT_BIT, |
| 7341 | this); // TODO - We shouldn't need a fragment shader |
| 7342 | // but add it to be able to run on more devices |
| 7343 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 7344 | shaderStages[1] = fs.GetStageCreateInfo(); |
| 7345 | |
| 7346 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 7347 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 7348 | vi_ci.pNext = nullptr; |
| 7349 | vi_ci.vertexBindingDescriptionCount = 0; |
| 7350 | vi_ci.pVertexBindingDescriptions = nullptr; |
| 7351 | vi_ci.vertexAttributeDescriptionCount = 0; |
| 7352 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 7353 | |
| 7354 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 7355 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 7356 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 7357 | |
| 7358 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
| 7359 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7360 | rs_ci.pNext = nullptr; |
| 7361 | |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7362 | // Check too low (line width of -1.0f). |
| 7363 | rs_ci.lineWidth = -1.0f; |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7364 | |
| 7365 | VkPipelineColorBlendAttachmentState att = {}; |
| 7366 | att.blendEnable = VK_FALSE; |
| 7367 | att.colorWriteMask = 0xf; |
| 7368 | |
| 7369 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 7370 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 7371 | cb_ci.pNext = nullptr; |
| 7372 | cb_ci.attachmentCount = 1; |
| 7373 | cb_ci.pAttachments = &att; |
| 7374 | |
| 7375 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 7376 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7377 | gp_ci.stageCount = 2; |
| 7378 | gp_ci.pStages = shaderStages; |
| 7379 | gp_ci.pVertexInputState = &vi_ci; |
| 7380 | gp_ci.pInputAssemblyState = &ia_ci; |
| 7381 | gp_ci.pViewportState = &vp_state_ci; |
| 7382 | gp_ci.pRasterizationState = &rs_ci; |
| 7383 | gp_ci.pColorBlendState = &cb_ci; |
| 7384 | gp_ci.pDynamicState = &dyn_state_ci; |
| 7385 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7386 | gp_ci.layout = pipeline_layout; |
| 7387 | gp_ci.renderPass = renderPass(); |
| 7388 | |
| 7389 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 7390 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 7391 | |
| 7392 | VkPipeline pipeline; |
| 7393 | VkPipelineCache pipelineCache; |
| 7394 | |
| 7395 | err = |
| 7396 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7397 | ASSERT_VK_SUCCESS(err); |
| 7398 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7399 | &gp_ci, NULL, &pipeline); |
| 7400 | |
| 7401 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7402 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7403 | |
| 7404 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7405 | "Attempt to set lineWidth to 65536"); |
| 7406 | |
| 7407 | // Check too high (line width of 65536.0f). |
| 7408 | rs_ci.lineWidth = 65536.0f; |
| 7409 | |
| 7410 | err = |
| 7411 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7412 | ASSERT_VK_SUCCESS(err); |
| 7413 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7414 | &gp_ci, NULL, &pipeline); |
| 7415 | |
| 7416 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7417 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7418 | |
| 7419 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7420 | "Attempt to set lineWidth to -1"); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7421 | |
| 7422 | dyn_state_ci.dynamicStateCount = 3; |
| 7423 | |
| 7424 | rs_ci.lineWidth = 1.0f; |
| 7425 | |
| 7426 | err = |
| 7427 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7428 | ASSERT_VK_SUCCESS(err); |
| 7429 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7430 | &gp_ci, NULL, &pipeline); |
| 7431 | BeginCommandBuffer(); |
| 7432 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7433 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 7434 | |
| 7435 | // Check too low with dynamic setting. |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7436 | vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7437 | m_errorMonitor->VerifyFound(); |
| 7438 | |
| 7439 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7440 | "Attempt to set lineWidth to 65536"); |
| 7441 | |
| 7442 | // Check too high with dynamic setting. |
| 7443 | vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f); |
| 7444 | m_errorMonitor->VerifyFound(); |
| 7445 | EndCommandBuffer(); |
| 7446 | |
| 7447 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7448 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7449 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7450 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7451 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7452 | } |
| 7453 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7454 | TEST_F(VkLayerTest, NullRenderPass) { |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7455 | // Bind a NULL RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7456 | m_errorMonitor->SetDesiredFailureMsg( |
| 7457 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7458 | "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()"); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7459 | |
| 7460 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7461 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7462 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 7463 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7464 | // Don't care about RenderPass handle b/c error should be flagged before |
| 7465 | // that |
| 7466 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, |
| 7467 | VK_SUBPASS_CONTENTS_INLINE); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7468 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7469 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7470 | } |
| 7471 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7472 | TEST_F(VkLayerTest, RenderPassWithinRenderPass) { |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7473 | // Bind a BeginRenderPass within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7474 | m_errorMonitor->SetDesiredFailureMsg( |
| 7475 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7476 | "It is invalid to issue this call inside an active render pass"); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7477 | |
| 7478 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7479 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7480 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 7481 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7482 | // Just create a dummy Renderpass that's non-NULL so we can get to the |
| 7483 | // proper error |
Chris Forbes | 38ae7c4 | 2016-06-21 20:51:44 +1200 | [diff] [blame] | 7484 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7485 | VK_SUBPASS_CONTENTS_INLINE); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7486 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7487 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 7488 | } |
| 7489 | |
Chris Forbes | 2eeabe3 | 2016-06-21 20:52:34 +1200 | [diff] [blame] | 7490 | TEST_F(VkLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) { |
| 7491 | m_errorMonitor->ExpectSuccess(); |
| 7492 | |
| 7493 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7494 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7495 | |
| 7496 | BeginCommandBuffer(); // framework implicitly begins the renderpass. |
| 7497 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // end implicit. |
| 7498 | |
| 7499 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, |
| 7500 | VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS); |
| 7501 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 7502 | m_errorMonitor->VerifyNotFound(); |
| 7503 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, |
| 7504 | VK_SUBPASS_CONTENTS_INLINE); |
| 7505 | m_errorMonitor->VerifyNotFound(); |
| 7506 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 7507 | m_errorMonitor->VerifyNotFound(); |
| 7508 | |
| 7509 | m_commandBuffer->EndCommandBuffer(); |
| 7510 | m_errorMonitor->VerifyNotFound(); |
| 7511 | } |
| 7512 | |
Tobin Ehlis | 5a1c033 | 2016-05-31 13:59:26 -0600 | [diff] [blame] | 7513 | TEST_F(VkLayerTest, RenderPassClearOpMismatch) { |
| 7514 | TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than" |
| 7515 | "the number of renderPass attachments that use loadOp" |
| 7516 | "VK_ATTACHMENT_LOAD_OP_CLEAR."); |
| 7517 | |
| 7518 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7519 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7520 | |
| 7521 | // Create a renderPass with a single attachment that uses loadOp CLEAR |
| 7522 | VkAttachmentReference attach = {}; |
| 7523 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 7524 | VkSubpassDescription subpass = {}; |
| 7525 | subpass.inputAttachmentCount = 1; |
| 7526 | subpass.pInputAttachments = &attach; |
| 7527 | VkRenderPassCreateInfo rpci = {}; |
| 7528 | rpci.subpassCount = 1; |
| 7529 | rpci.pSubpasses = &subpass; |
| 7530 | rpci.attachmentCount = 1; |
| 7531 | VkAttachmentDescription attach_desc = {}; |
| 7532 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 7533 | // Set loadOp to CLEAR |
| 7534 | attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 7535 | rpci.pAttachments = &attach_desc; |
| 7536 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 7537 | VkRenderPass rp; |
| 7538 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 7539 | |
| 7540 | VkCommandBufferInheritanceInfo hinfo = {}; |
| 7541 | hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; |
| 7542 | hinfo.renderPass = VK_NULL_HANDLE; |
| 7543 | hinfo.subpass = 0; |
| 7544 | hinfo.framebuffer = VK_NULL_HANDLE; |
| 7545 | hinfo.occlusionQueryEnable = VK_FALSE; |
| 7546 | hinfo.queryFlags = 0; |
| 7547 | hinfo.pipelineStatistics = 0; |
| 7548 | VkCommandBufferBeginInfo info = {}; |
| 7549 | info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
| 7550 | info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 7551 | info.pInheritanceInfo = &hinfo; |
| 7552 | |
| 7553 | vkBeginCommandBuffer(m_commandBuffer->handle(), &info); |
| 7554 | VkRenderPassBeginInfo rp_begin = {}; |
| 7555 | rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 7556 | rp_begin.pNext = NULL; |
| 7557 | rp_begin.renderPass = renderPass(); |
| 7558 | rp_begin.framebuffer = framebuffer(); |
| 7559 | rp_begin.clearValueCount = 0; // Should be 1 |
| 7560 | |
| 7561 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7562 | " has a clearValueCount of 0 but the " |
| 7563 | "actual number of attachments in " |
| 7564 | "renderPass "); |
| 7565 | |
| 7566 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, |
| 7567 | VK_SUBPASS_CONTENTS_INLINE); |
| 7568 | |
| 7569 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 5c70ebd | 2016-06-09 13:45:00 -0600 | [diff] [blame] | 7570 | |
| 7571 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 5a1c033 | 2016-05-31 13:59:26 -0600 | [diff] [blame] | 7572 | } |
| 7573 | |
Cody Northrop | 3bb4d96 | 2016-05-09 16:15:57 -0600 | [diff] [blame] | 7574 | TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) { |
| 7575 | |
| 7576 | TEST_DESCRIPTION("End a command buffer with an active render pass"); |
| 7577 | |
| 7578 | m_errorMonitor->SetDesiredFailureMsg( |
| 7579 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7580 | "It is invalid to issue this call inside an active render pass"); |
| 7581 | |
| 7582 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7583 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7584 | |
| 7585 | // The framework's BeginCommandBuffer calls CreateRenderPass |
| 7586 | BeginCommandBuffer(); |
| 7587 | |
| 7588 | // Call directly into vkEndCommandBuffer instead of the |
| 7589 | // the framework's EndCommandBuffer, which inserts a |
| 7590 | // vkEndRenderPass |
| 7591 | vkEndCommandBuffer(m_commandBuffer->GetBufferHandle()); |
| 7592 | |
| 7593 | m_errorMonitor->VerifyFound(); |
| 7594 | |
| 7595 | // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY |
| 7596 | // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT |
| 7597 | } |
| 7598 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7599 | TEST_F(VkLayerTest, FillBufferWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7600 | // Call CmdFillBuffer within an active renderpass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7601 | m_errorMonitor->SetDesiredFailureMsg( |
| 7602 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7603 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7604 | |
| 7605 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7606 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7607 | |
| 7608 | // Renderpass is started here |
| 7609 | BeginCommandBuffer(); |
| 7610 | |
| 7611 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7612 | vk_testing::Buffer dstBuffer; |
| 7613 | dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7614 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7615 | m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7616 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7617 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7618 | } |
| 7619 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7620 | TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7621 | // Call CmdUpdateBuffer within an active renderpass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7622 | m_errorMonitor->SetDesiredFailureMsg( |
| 7623 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7624 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7625 | |
| 7626 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7627 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7628 | |
| 7629 | // Renderpass is started here |
| 7630 | BeginCommandBuffer(); |
| 7631 | |
| 7632 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7633 | vk_testing::Buffer dstBuffer; |
| 7634 | dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7635 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7636 | VkDeviceSize dstOffset = 0; |
| 7637 | VkDeviceSize dataSize = 1024; |
| 7638 | const uint32_t *pData = NULL; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7639 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7640 | vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), |
| 7641 | dstOffset, dataSize, pData); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7642 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7643 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7644 | } |
| 7645 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7646 | TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7647 | // Call CmdClearColorImage within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7648 | m_errorMonitor->SetDesiredFailureMsg( |
| 7649 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7650 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7651 | |
| 7652 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7653 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7654 | |
| 7655 | // Renderpass is started here |
| 7656 | BeginCommandBuffer(); |
| 7657 | |
Michael Lentine | 0a369f6 | 2016-02-03 16:51:46 -0600 | [diff] [blame] | 7658 | VkClearColorValue clear_color; |
| 7659 | memset(clear_color.uint32, 0, sizeof(uint32_t) * 4); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7660 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 7661 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 7662 | const int32_t tex_width = 32; |
| 7663 | const int32_t tex_height = 32; |
| 7664 | VkImageCreateInfo image_create_info = {}; |
| 7665 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 7666 | image_create_info.pNext = NULL; |
| 7667 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 7668 | image_create_info.format = tex_format; |
| 7669 | image_create_info.extent.width = tex_width; |
| 7670 | image_create_info.extent.height = tex_height; |
| 7671 | image_create_info.extent.depth = 1; |
| 7672 | image_create_info.mipLevels = 1; |
| 7673 | image_create_info.arrayLayers = 1; |
| 7674 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 7675 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 7676 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7677 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7678 | vk_testing::Image dstImage; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7679 | dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 7680 | reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7681 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7682 | const VkImageSubresourceRange range = vk_testing::Image::subresource_range( |
| 7683 | image_create_info, VK_IMAGE_ASPECT_COLOR_BIT); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7684 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7685 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), |
| 7686 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7687 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7688 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7689 | } |
| 7690 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7691 | TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7692 | // Call CmdClearDepthStencilImage within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7693 | m_errorMonitor->SetDesiredFailureMsg( |
| 7694 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7695 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7696 | |
| 7697 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7698 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7699 | |
| 7700 | // Renderpass is started here |
| 7701 | BeginCommandBuffer(); |
| 7702 | |
| 7703 | VkClearDepthStencilValue clear_value = {0}; |
Dustin Graves | a2e5c94 | 2016-02-11 18:28:06 -0700 | [diff] [blame] | 7704 | VkMemoryPropertyFlags reqs = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7705 | VkImageCreateInfo image_create_info = vk_testing::Image::create_info(); |
| 7706 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 7707 | image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 7708 | image_create_info.extent.width = 64; |
| 7709 | image_create_info.extent.height = 64; |
| 7710 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 7711 | image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7712 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7713 | vk_testing::Image dstImage; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7714 | dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 7715 | reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7716 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7717 | const VkImageSubresourceRange range = vk_testing::Image::subresource_range( |
| 7718 | image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7719 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7720 | vkCmdClearDepthStencilImage( |
| 7721 | m_commandBuffer->GetBufferHandle(), dstImage.handle(), |
| 7722 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, |
| 7723 | &range); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7724 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7725 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7726 | } |
| 7727 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7728 | TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) { |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 7729 | // Call CmdClearAttachmentss outside of an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7730 | VkResult err; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7731 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 7732 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7733 | "vkCmdClearAttachments: This call " |
| 7734 | "must be issued inside an active " |
| 7735 | "render pass"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7736 | |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7737 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7738 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7739 | |
| 7740 | // Start no RenderPass |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7741 | err = m_commandBuffer->BeginCommandBuffer(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7742 | ASSERT_VK_SUCCESS(err); |
| 7743 | |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 7744 | VkClearAttachment color_attachment; |
| 7745 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 7746 | color_attachment.clearValue.color.float32[0] = 0; |
| 7747 | color_attachment.clearValue.color.float32[1] = 0; |
| 7748 | color_attachment.clearValue.color.float32[2] = 0; |
| 7749 | color_attachment.clearValue.color.float32[3] = 0; |
| 7750 | color_attachment.colorAttachment = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7751 | VkClearRect clear_rect = {{{0, 0}, {32, 32}}}; |
| 7752 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 7753 | &color_attachment, 1, &clear_rect); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7754 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7755 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7756 | } |
| 7757 | |
Karl Schultz | 9e66a29 | 2016-04-21 15:57:51 -0600 | [diff] [blame] | 7758 | TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) { |
| 7759 | // Try to add a buffer memory barrier with no buffer. |
| 7760 | m_errorMonitor->SetDesiredFailureMsg( |
| 7761 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7762 | "required parameter pBufferMemoryBarriers[i].buffer specified as VK_NULL_HANDLE"); |
| 7763 | |
| 7764 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7765 | BeginCommandBuffer(); |
| 7766 | |
| 7767 | VkBufferMemoryBarrier buf_barrier = {}; |
| 7768 | buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; |
| 7769 | buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 7770 | buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 7771 | buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7772 | buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7773 | buf_barrier.buffer = VK_NULL_HANDLE; |
| 7774 | buf_barrier.offset = 0; |
| 7775 | buf_barrier.size = VK_WHOLE_SIZE; |
| 7776 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7777 | VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, |
| 7778 | 0, 0, nullptr, 1, &buf_barrier, 0, nullptr); |
| 7779 | |
| 7780 | m_errorMonitor->VerifyFound(); |
| 7781 | } |
| 7782 | |
Tony Barbour | 7fd5c0f | 2016-05-03 16:11:53 -0600 | [diff] [blame] | 7783 | TEST_F(VkLayerTest, InvalidBarriers) { |
| 7784 | TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER "); |
| 7785 | |
| 7786 | m_errorMonitor->SetDesiredFailureMsg( |
| 7787 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass"); |
| 7788 | |
| 7789 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7790 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7791 | |
| 7792 | VkMemoryBarrier mem_barrier = {}; |
| 7793 | mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER; |
| 7794 | mem_barrier.pNext = NULL; |
| 7795 | mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 7796 | mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 7797 | BeginCommandBuffer(); |
| 7798 | // BeginCommandBuffer() starts a render pass |
| 7799 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7800 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7801 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1, |
| 7802 | &mem_barrier, 0, nullptr, 0, nullptr); |
| 7803 | m_errorMonitor->VerifyFound(); |
| 7804 | |
| 7805 | m_errorMonitor->SetDesiredFailureMsg( |
| 7806 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7807 | "Image Layout cannot be transitioned to UNDEFINED"); |
| 7808 | VkImageObj image(m_device); |
| 7809 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 7810 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 7811 | ASSERT_TRUE(image.initialized()); |
| 7812 | VkImageMemoryBarrier img_barrier = {}; |
| 7813 | img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 7814 | img_barrier.pNext = NULL; |
| 7815 | img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 7816 | img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 7817 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 7818 | // New layout can't be UNDEFINED |
| 7819 | img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 7820 | img_barrier.image = image.handle(); |
| 7821 | img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7822 | img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7823 | img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 7824 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 7825 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 7826 | img_barrier.subresourceRange.layerCount = 1; |
| 7827 | img_barrier.subresourceRange.levelCount = 1; |
| 7828 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7829 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7830 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 7831 | nullptr, 1, &img_barrier); |
| 7832 | m_errorMonitor->VerifyFound(); |
| 7833 | img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 7834 | |
| 7835 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7836 | "Subresource must have the sum of the " |
| 7837 | "baseArrayLayer"); |
| 7838 | // baseArrayLayer + layerCount must be <= image's arrayLayers |
| 7839 | img_barrier.subresourceRange.baseArrayLayer = 1; |
| 7840 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7841 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7842 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 7843 | nullptr, 1, &img_barrier); |
| 7844 | m_errorMonitor->VerifyFound(); |
| 7845 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 7846 | |
| 7847 | m_errorMonitor->SetDesiredFailureMsg( |
| 7848 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7849 | "Subresource must have the sum of the baseMipLevel"); |
| 7850 | // baseMipLevel + levelCount must be <= image's mipLevels |
| 7851 | img_barrier.subresourceRange.baseMipLevel = 1; |
| 7852 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7853 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7854 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 7855 | nullptr, 1, &img_barrier); |
| 7856 | m_errorMonitor->VerifyFound(); |
| 7857 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 7858 | |
| 7859 | m_errorMonitor->SetDesiredFailureMsg( |
| 7860 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7861 | "Buffer Barriers cannot be used during a render pass"); |
| 7862 | vk_testing::Buffer buffer; |
| 7863 | buffer.init(*m_device, 256); |
| 7864 | VkBufferMemoryBarrier buf_barrier = {}; |
| 7865 | buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; |
| 7866 | buf_barrier.pNext = NULL; |
| 7867 | buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 7868 | buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 7869 | buf_barrier.buffer = buffer.handle(); |
| 7870 | buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7871 | buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7872 | buf_barrier.offset = 0; |
| 7873 | buf_barrier.size = VK_WHOLE_SIZE; |
| 7874 | // Can't send buffer barrier during a render pass |
| 7875 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7876 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7877 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 7878 | &buf_barrier, 0, nullptr); |
| 7879 | m_errorMonitor->VerifyFound(); |
| 7880 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 7881 | |
| 7882 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7883 | "which is not less than total size"); |
| 7884 | buf_barrier.offset = 257; |
| 7885 | // Offset greater than total size |
| 7886 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7887 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7888 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 7889 | &buf_barrier, 0, nullptr); |
| 7890 | m_errorMonitor->VerifyFound(); |
| 7891 | buf_barrier.offset = 0; |
| 7892 | |
| 7893 | m_errorMonitor->SetDesiredFailureMsg( |
| 7894 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size"); |
| 7895 | buf_barrier.size = 257; |
| 7896 | // Size greater than total size |
| 7897 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7898 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7899 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 7900 | &buf_barrier, 0, nullptr); |
| 7901 | m_errorMonitor->VerifyFound(); |
| 7902 | buf_barrier.size = VK_WHOLE_SIZE; |
| 7903 | |
| 7904 | m_errorMonitor->SetDesiredFailureMsg( |
| 7905 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7906 | "Image is a depth and stencil format and thus must " |
| 7907 | "have both VK_IMAGE_ASPECT_DEPTH_BIT and " |
| 7908 | "VK_IMAGE_ASPECT_STENCIL_BIT set."); |
| 7909 | VkDepthStencilObj ds_image(m_device); |
| 7910 | ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT); |
| 7911 | ASSERT_TRUE(ds_image.initialized()); |
| 7912 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 7913 | img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 7914 | img_barrier.image = ds_image.handle(); |
| 7915 | // Leave aspectMask at COLOR on purpose |
| 7916 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7917 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7918 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 7919 | nullptr, 1, &img_barrier); |
| 7920 | m_errorMonitor->VerifyFound(); |
| 7921 | } |
| 7922 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7923 | TEST_F(VkLayerTest, IdxBufferAlignmentError) { |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7924 | // Bind a BeginRenderPass within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7925 | VkResult err; |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7926 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7927 | m_errorMonitor->SetDesiredFailureMsg( |
| 7928 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7929 | "vkCmdBindIndexBuffer() offset (0x7) does not fall on "); |
| 7930 | |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7931 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7932 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7933 | uint32_t qfi = 0; |
| 7934 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7935 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 7936 | buffCI.size = 1024; |
| 7937 | buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; |
| 7938 | buffCI.queueFamilyIndexCount = 1; |
| 7939 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7940 | |
| 7941 | VkBuffer ib; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7942 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7943 | ASSERT_VK_SUCCESS(err); |
| 7944 | |
| 7945 | BeginCommandBuffer(); |
| 7946 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7947 | // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7948 | // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7949 | // 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] | 7950 | vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, |
| 7951 | VK_INDEX_TYPE_UINT16); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7952 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7953 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 7954 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7955 | vkDestroyBuffer(m_device->device(), ib, NULL); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7956 | } |
| 7957 | |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 7958 | TEST_F(VkLayerTest, InvalidQueueFamilyIndex) { |
| 7959 | // Create an out-of-range queueFamilyIndex |
| 7960 | m_errorMonitor->SetDesiredFailureMsg( |
| 7961 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Dustin Graves | de62853 | 2016-04-21 16:30:17 -0600 | [diff] [blame] | 7962 | "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one " |
| 7963 | "of the indices specified when the device was created, via the " |
| 7964 | "VkDeviceQueueCreateInfo structure."); |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 7965 | |
| 7966 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7967 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7968 | VkBufferCreateInfo buffCI = {}; |
| 7969 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 7970 | buffCI.size = 1024; |
| 7971 | buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; |
| 7972 | buffCI.queueFamilyIndexCount = 1; |
| 7973 | // Introduce failure by specifying invalid queue_family_index |
| 7974 | uint32_t qfi = 777; |
| 7975 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 24aab04 | 2016-03-24 10:54:18 -0600 | [diff] [blame] | 7976 | buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 7977 | |
| 7978 | VkBuffer ib; |
| 7979 | vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib); |
| 7980 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7981 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7982 | vkDestroyBuffer(m_device->device(), ib, NULL); |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 7983 | } |
| 7984 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7985 | TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) { |
| 7986 | // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be |
| 7987 | // secondary) |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7988 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7989 | m_errorMonitor->SetDesiredFailureMsg( |
| 7990 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7991 | "vkCmdExecuteCommands() called w/ Primary Cmd Buffer "); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 7992 | |
| 7993 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7994 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 7995 | |
| 7996 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7997 | // ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7998 | VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle(); |
| 7999 | vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 8000 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8001 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 8002 | } |
| 8003 | |
Tobin Ehlis | 17826bd | 2016-05-25 11:12:50 -0600 | [diff] [blame] | 8004 | TEST_F(VkLayerTest, DSUsageBitsErrors) { |
| 8005 | TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers " |
| 8006 | "that do not have correct usage bits sets."); |
| 8007 | VkResult err; |
| 8008 | |
| 8009 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8010 | VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {}; |
| 8011 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 8012 | ds_type_count[i].type = VkDescriptorType(i); |
| 8013 | ds_type_count[i].descriptorCount = 1; |
| 8014 | } |
| 8015 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 8016 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8017 | ds_pool_ci.pNext = NULL; |
| 8018 | ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 8019 | ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 8020 | ds_pool_ci.pPoolSizes = ds_type_count; |
| 8021 | |
| 8022 | VkDescriptorPool ds_pool; |
| 8023 | err = |
| 8024 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 8025 | ASSERT_VK_SUCCESS(err); |
| 8026 | |
| 8027 | // Create 10 layouts where each has a single descriptor of different type |
| 8028 | VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = |
| 8029 | {}; |
| 8030 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 8031 | dsl_binding[i].binding = 0; |
| 8032 | dsl_binding[i].descriptorType = VkDescriptorType(i); |
| 8033 | dsl_binding[i].descriptorCount = 1; |
| 8034 | dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL; |
| 8035 | dsl_binding[i].pImmutableSamplers = NULL; |
| 8036 | } |
| 8037 | |
| 8038 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 8039 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8040 | ds_layout_ci.pNext = NULL; |
| 8041 | ds_layout_ci.bindingCount = 1; |
| 8042 | VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE]; |
| 8043 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 8044 | ds_layout_ci.pBindings = dsl_binding + i; |
| 8045 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, |
| 8046 | NULL, ds_layouts + i); |
| 8047 | ASSERT_VK_SUCCESS(err); |
| 8048 | } |
| 8049 | VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {}; |
| 8050 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 8051 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 8052 | alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 8053 | alloc_info.descriptorPool = ds_pool; |
| 8054 | alloc_info.pSetLayouts = ds_layouts; |
| 8055 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8056 | descriptor_sets); |
| 8057 | ASSERT_VK_SUCCESS(err); |
| 8058 | |
| 8059 | // Create a buffer & bufferView to be used for invalid updates |
| 8060 | VkBufferCreateInfo buff_ci = {}; |
| 8061 | buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 8062 | // This usage is not valid for any descriptor type |
| 8063 | buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; |
| 8064 | buff_ci.size = 256; |
| 8065 | buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 8066 | VkBuffer buffer; |
| 8067 | err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer); |
| 8068 | ASSERT_VK_SUCCESS(err); |
| 8069 | |
| 8070 | VkBufferViewCreateInfo buff_view_ci = {}; |
| 8071 | buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; |
| 8072 | buff_view_ci.buffer = buffer; |
| 8073 | buff_view_ci.format = VK_FORMAT_R8_UNORM; |
| 8074 | buff_view_ci.range = VK_WHOLE_SIZE; |
| 8075 | VkBufferView buff_view; |
| 8076 | err = |
| 8077 | vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view); |
| 8078 | ASSERT_VK_SUCCESS(err); |
| 8079 | |
| 8080 | // Create an image to be used for invalid updates |
| 8081 | VkImageCreateInfo image_ci = {}; |
| 8082 | image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 8083 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 8084 | image_ci.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 8085 | image_ci.extent.width = 64; |
| 8086 | image_ci.extent.height = 64; |
| 8087 | image_ci.extent.depth = 1; |
| 8088 | image_ci.mipLevels = 1; |
| 8089 | image_ci.arrayLayers = 1; |
| 8090 | image_ci.samples = VK_SAMPLE_COUNT_1_BIT; |
| 8091 | image_ci.tiling = VK_IMAGE_TILING_LINEAR; |
| 8092 | image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 8093 | // This usage is not valid for any descriptor type |
| 8094 | image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 8095 | image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 8096 | VkImage image; |
| 8097 | err = vkCreateImage(m_device->device(), &image_ci, NULL, &image); |
| 8098 | ASSERT_VK_SUCCESS(err); |
| 8099 | // Bind memory to image |
| 8100 | VkMemoryRequirements mem_reqs; |
| 8101 | VkDeviceMemory image_mem; |
| 8102 | bool pass; |
| 8103 | VkMemoryAllocateInfo mem_alloc = {}; |
| 8104 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 8105 | mem_alloc.pNext = NULL; |
| 8106 | mem_alloc.allocationSize = 0; |
| 8107 | mem_alloc.memoryTypeIndex = 0; |
| 8108 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 8109 | mem_alloc.allocationSize = mem_reqs.size; |
| 8110 | pass = |
| 8111 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 8112 | ASSERT_TRUE(pass); |
| 8113 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem); |
| 8114 | ASSERT_VK_SUCCESS(err); |
| 8115 | err = vkBindImageMemory(m_device->device(), image, image_mem, 0); |
| 8116 | ASSERT_VK_SUCCESS(err); |
| 8117 | // Now create view for image |
| 8118 | VkImageViewCreateInfo image_view_ci = {}; |
| 8119 | image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 8120 | image_view_ci.image = image; |
| 8121 | image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 8122 | image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 8123 | image_view_ci.subresourceRange.layerCount = 1; |
| 8124 | image_view_ci.subresourceRange.baseArrayLayer = 0; |
| 8125 | image_view_ci.subresourceRange.levelCount = 1; |
| 8126 | image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 8127 | VkImageView image_view; |
| 8128 | err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, |
| 8129 | &image_view); |
| 8130 | ASSERT_VK_SUCCESS(err); |
| 8131 | |
| 8132 | VkDescriptorBufferInfo buff_info = {}; |
| 8133 | buff_info.buffer = buffer; |
| 8134 | VkDescriptorImageInfo img_info = {}; |
| 8135 | img_info.imageView = image_view; |
| 8136 | VkWriteDescriptorSet descriptor_write = {}; |
| 8137 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 8138 | descriptor_write.dstBinding = 0; |
| 8139 | descriptor_write.descriptorCount = 1; |
| 8140 | descriptor_write.pTexelBufferView = &buff_view; |
| 8141 | descriptor_write.pBufferInfo = &buff_info; |
| 8142 | descriptor_write.pImageInfo = &img_info; |
| 8143 | |
| 8144 | // These error messages align with VkDescriptorType struct |
| 8145 | const char *error_msgs[] = { |
| 8146 | "", // placeholder, no error for SAMPLER descriptor |
| 8147 | " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.", |
| 8148 | " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.", |
| 8149 | " does not have VK_IMAGE_USAGE_STORAGE_BIT set.", |
| 8150 | " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.", |
| 8151 | " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.", |
| 8152 | " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.", |
| 8153 | " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.", |
| 8154 | " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.", |
| 8155 | " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.", |
| 8156 | " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."}; |
| 8157 | // Start loop at 1 as SAMPLER desc type has no usage bit error |
| 8158 | for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 8159 | descriptor_write.descriptorType = VkDescriptorType(i); |
| 8160 | descriptor_write.dstSet = descriptor_sets[i]; |
| 8161 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8162 | error_msgs[i]); |
| 8163 | |
| 8164 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, |
| 8165 | NULL); |
| 8166 | |
| 8167 | m_errorMonitor->VerifyFound(); |
| 8168 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL); |
| 8169 | } |
| 8170 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL); |
| 8171 | vkDestroyImage(m_device->device(), image, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 8172 | vkFreeMemory(m_device->device(), image_mem, NULL); |
Tobin Ehlis | 17826bd | 2016-05-25 11:12:50 -0600 | [diff] [blame] | 8173 | vkDestroyImageView(m_device->device(), image_view, NULL); |
| 8174 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 8175 | vkDestroyBufferView(m_device->device(), buff_view, NULL); |
| 8176 | vkFreeDescriptorSets(m_device->device(), ds_pool, |
| 8177 | VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets); |
| 8178 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 8179 | } |
| 8180 | |
Tobin Ehlis | 2fc296b | 2016-06-15 14:05:27 -0600 | [diff] [blame] | 8181 | TEST_F(VkLayerTest, DSAspectBitsErrors) { |
| 8182 | // TODO : Initially only catching case where DEPTH & STENCIL aspect bits |
| 8183 | // are set, but could expand this test to hit more cases. |
| 8184 | TEST_DESCRIPTION("Attempt to update descriptor sets for images " |
| 8185 | "that do not have correct aspect bits sets."); |
| 8186 | VkResult err; |
| 8187 | |
| 8188 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8189 | VkDescriptorPoolSize ds_type_count = {}; |
| 8190 | ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 8191 | ds_type_count.descriptorCount = 1; |
| 8192 | |
| 8193 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 8194 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8195 | ds_pool_ci.pNext = NULL; |
| 8196 | ds_pool_ci.maxSets = 5; |
| 8197 | ds_pool_ci.poolSizeCount = 1; |
| 8198 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 8199 | |
| 8200 | VkDescriptorPool ds_pool; |
| 8201 | err = |
| 8202 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 8203 | ASSERT_VK_SUCCESS(err); |
| 8204 | |
| 8205 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 8206 | dsl_binding.binding = 0; |
| 8207 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 8208 | dsl_binding.descriptorCount = 1; |
| 8209 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8210 | dsl_binding.pImmutableSamplers = NULL; |
| 8211 | |
| 8212 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 8213 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8214 | ds_layout_ci.pNext = NULL; |
| 8215 | ds_layout_ci.bindingCount = 1; |
| 8216 | ds_layout_ci.pBindings = &dsl_binding; |
| 8217 | VkDescriptorSetLayout ds_layout; |
| 8218 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8219 | &ds_layout); |
| 8220 | ASSERT_VK_SUCCESS(err); |
| 8221 | |
| 8222 | VkDescriptorSet descriptor_set = {}; |
| 8223 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 8224 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 8225 | alloc_info.descriptorSetCount = 1; |
| 8226 | alloc_info.descriptorPool = ds_pool; |
| 8227 | alloc_info.pSetLayouts = &ds_layout; |
| 8228 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8229 | &descriptor_set); |
| 8230 | ASSERT_VK_SUCCESS(err); |
| 8231 | |
| 8232 | // Create an image to be used for invalid updates |
| 8233 | VkImageCreateInfo image_ci = {}; |
| 8234 | image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 8235 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 8236 | image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 8237 | image_ci.extent.width = 64; |
| 8238 | image_ci.extent.height = 64; |
| 8239 | image_ci.extent.depth = 1; |
| 8240 | image_ci.mipLevels = 1; |
| 8241 | image_ci.arrayLayers = 1; |
| 8242 | image_ci.samples = VK_SAMPLE_COUNT_1_BIT; |
| 8243 | image_ci.tiling = VK_IMAGE_TILING_LINEAR; |
| 8244 | image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 8245 | image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 8246 | image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 8247 | VkImage image; |
| 8248 | err = vkCreateImage(m_device->device(), &image_ci, NULL, &image); |
| 8249 | ASSERT_VK_SUCCESS(err); |
| 8250 | // Bind memory to image |
| 8251 | VkMemoryRequirements mem_reqs; |
| 8252 | VkDeviceMemory image_mem; |
| 8253 | bool pass; |
| 8254 | VkMemoryAllocateInfo mem_alloc = {}; |
| 8255 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 8256 | mem_alloc.pNext = NULL; |
| 8257 | mem_alloc.allocationSize = 0; |
| 8258 | mem_alloc.memoryTypeIndex = 0; |
| 8259 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 8260 | mem_alloc.allocationSize = mem_reqs.size; |
| 8261 | pass = |
| 8262 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 8263 | ASSERT_TRUE(pass); |
| 8264 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem); |
| 8265 | ASSERT_VK_SUCCESS(err); |
| 8266 | err = vkBindImageMemory(m_device->device(), image, image_mem, 0); |
| 8267 | ASSERT_VK_SUCCESS(err); |
| 8268 | // Now create view for image |
| 8269 | VkImageViewCreateInfo image_view_ci = {}; |
| 8270 | image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 8271 | image_view_ci.image = image; |
| 8272 | image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 8273 | image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 8274 | image_view_ci.subresourceRange.layerCount = 1; |
| 8275 | image_view_ci.subresourceRange.baseArrayLayer = 0; |
| 8276 | image_view_ci.subresourceRange.levelCount = 1; |
| 8277 | // Setting both depth & stencil aspect bits is illegal for descriptor |
| 8278 | image_view_ci.subresourceRange.aspectMask = |
| 8279 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 8280 | |
| 8281 | VkImageView image_view; |
| 8282 | err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, |
| 8283 | &image_view); |
| 8284 | ASSERT_VK_SUCCESS(err); |
| 8285 | |
| 8286 | VkDescriptorImageInfo img_info = {}; |
| 8287 | img_info.imageView = image_view; |
| 8288 | VkWriteDescriptorSet descriptor_write = {}; |
| 8289 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 8290 | descriptor_write.dstBinding = 0; |
| 8291 | descriptor_write.descriptorCount = 1; |
| 8292 | descriptor_write.pTexelBufferView = NULL; |
| 8293 | descriptor_write.pBufferInfo = NULL; |
| 8294 | descriptor_write.pImageInfo = &img_info; |
| 8295 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 8296 | descriptor_write.dstSet = descriptor_set; |
| 8297 | const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT " |
| 8298 | "or VK_IMAGE_ASPECT_STENCIL_BIT "; |
| 8299 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8300 | error_msg); |
| 8301 | |
| 8302 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8303 | |
| 8304 | m_errorMonitor->VerifyFound(); |
| 8305 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8306 | vkDestroyImage(m_device->device(), image, NULL); |
| 8307 | vkFreeMemory(m_device->device(), image_mem, NULL); |
| 8308 | vkDestroyImageView(m_device->device(), image_view, NULL); |
| 8309 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set); |
| 8310 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 8311 | } |
| 8312 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8313 | TEST_F(VkLayerTest, DSTypeMismatch) { |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8314 | // 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] | 8315 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8316 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8317 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8318 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8319 | " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update " |
| 8320 | "type is VK_DESCRIPTOR_TYPE_SAMPLER"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8321 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8322 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8323 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8324 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8325 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8326 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8327 | |
| 8328 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8329 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8330 | ds_pool_ci.pNext = NULL; |
| 8331 | ds_pool_ci.maxSets = 1; |
| 8332 | ds_pool_ci.poolSizeCount = 1; |
| 8333 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8334 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8335 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8336 | err = |
| 8337 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8338 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8339 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8340 | dsl_binding.binding = 0; |
| 8341 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8342 | dsl_binding.descriptorCount = 1; |
| 8343 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8344 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8345 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8346 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8347 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8348 | ds_layout_ci.pNext = NULL; |
| 8349 | ds_layout_ci.bindingCount = 1; |
| 8350 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8351 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8352 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8353 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8354 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8355 | ASSERT_VK_SUCCESS(err); |
| 8356 | |
| 8357 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8358 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8359 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8360 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8361 | alloc_info.descriptorPool = ds_pool; |
| 8362 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8363 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8364 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8365 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8366 | |
Tobin Ehlis | 30db8f8 | 2016-05-05 08:19:48 -0600 | [diff] [blame] | 8367 | VkSamplerCreateInfo sampler_ci = {}; |
| 8368 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8369 | sampler_ci.pNext = NULL; |
| 8370 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8371 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8372 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8373 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8374 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8375 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8376 | sampler_ci.mipLodBias = 1.0; |
| 8377 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8378 | sampler_ci.maxAnisotropy = 1; |
| 8379 | sampler_ci.compareEnable = VK_FALSE; |
| 8380 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8381 | sampler_ci.minLod = 1.0; |
| 8382 | sampler_ci.maxLod = 1.0; |
| 8383 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8384 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
| 8385 | VkSampler sampler; |
| 8386 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
| 8387 | ASSERT_VK_SUCCESS(err); |
| 8388 | |
| 8389 | VkDescriptorImageInfo info = {}; |
| 8390 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8391 | |
| 8392 | VkWriteDescriptorSet descriptor_write; |
| 8393 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8394 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8395 | descriptor_write.dstSet = descriptorSet; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8396 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8397 | // This is a mismatched type for the layout which expects BUFFER |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8398 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8399 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8400 | |
| 8401 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8402 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8403 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8404 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8405 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8406 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8407 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8408 | } |
| 8409 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8410 | TEST_F(VkLayerTest, DSUpdateOutOfBounds) { |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8411 | // For overlapping Update, have arrayIndex exceed that of layout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8412 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8413 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8414 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8415 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8416 | " binding #0 with 1 total descriptors but update of 1 descriptors " |
| 8417 | "starting at binding offset of 0 combined with update array element " |
| 8418 | "offset of 1 oversteps the size of this descriptor set."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8419 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8420 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8421 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8422 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8423 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8424 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8425 | |
| 8426 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8427 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8428 | ds_pool_ci.pNext = NULL; |
| 8429 | ds_pool_ci.maxSets = 1; |
| 8430 | ds_pool_ci.poolSizeCount = 1; |
| 8431 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8432 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8433 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8434 | err = |
| 8435 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8436 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8437 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8438 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8439 | dsl_binding.binding = 0; |
| 8440 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8441 | dsl_binding.descriptorCount = 1; |
| 8442 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8443 | dsl_binding.pImmutableSamplers = NULL; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8444 | |
| 8445 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8446 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8447 | ds_layout_ci.pNext = NULL; |
| 8448 | ds_layout_ci.bindingCount = 1; |
| 8449 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8450 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8451 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8452 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8453 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8454 | ASSERT_VK_SUCCESS(err); |
| 8455 | |
| 8456 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8457 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8458 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8459 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8460 | alloc_info.descriptorPool = ds_pool; |
| 8461 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8462 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8463 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8464 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8465 | |
Tobin Ehlis | 30db8f8 | 2016-05-05 08:19:48 -0600 | [diff] [blame] | 8466 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 8467 | VkDescriptorBufferInfo buff_info = {}; |
| 8468 | buff_info.buffer = |
| 8469 | VkBuffer(0); // Don't care about buffer handle for this test |
| 8470 | buff_info.offset = 0; |
| 8471 | buff_info.range = 1024; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8472 | |
| 8473 | VkWriteDescriptorSet descriptor_write; |
| 8474 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8475 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8476 | descriptor_write.dstSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8477 | descriptor_write.dstArrayElement = |
| 8478 | 1; /* This index out of bounds for the update */ |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8479 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8480 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8481 | descriptor_write.pBufferInfo = &buff_info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8482 | |
| 8483 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8484 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8485 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8486 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8487 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8488 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8489 | } |
| 8490 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8491 | TEST_F(VkLayerTest, InvalidDSUpdateIndex) { |
| 8492 | // Create layout w/ count of 1 and attempt update to that layout w/ binding |
| 8493 | // index 2 |
| 8494 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8495 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8496 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8497 | " does not have binding 2."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8498 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8499 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8500 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8501 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8502 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8503 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8504 | |
| 8505 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8506 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8507 | ds_pool_ci.pNext = NULL; |
| 8508 | ds_pool_ci.maxSets = 1; |
| 8509 | ds_pool_ci.poolSizeCount = 1; |
| 8510 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 8511 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8512 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8513 | err = |
| 8514 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8515 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8516 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8517 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8518 | dsl_binding.binding = 0; |
| 8519 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8520 | dsl_binding.descriptorCount = 1; |
| 8521 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8522 | dsl_binding.pImmutableSamplers = NULL; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8523 | |
| 8524 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8525 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8526 | ds_layout_ci.pNext = NULL; |
| 8527 | ds_layout_ci.bindingCount = 1; |
| 8528 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8529 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8530 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8531 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8532 | ASSERT_VK_SUCCESS(err); |
| 8533 | |
| 8534 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8535 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8536 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8537 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8538 | alloc_info.descriptorPool = ds_pool; |
| 8539 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8540 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8541 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8542 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8543 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8544 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8545 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8546 | sampler_ci.pNext = NULL; |
| 8547 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8548 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8549 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8550 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8551 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8552 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8553 | sampler_ci.mipLodBias = 1.0; |
| 8554 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8555 | sampler_ci.maxAnisotropy = 1; |
| 8556 | sampler_ci.compareEnable = VK_FALSE; |
| 8557 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8558 | sampler_ci.minLod = 1.0; |
| 8559 | sampler_ci.maxLod = 1.0; |
| 8560 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8561 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8562 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8563 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8564 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8565 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8566 | |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8567 | VkDescriptorImageInfo info = {}; |
| 8568 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8569 | |
| 8570 | VkWriteDescriptorSet descriptor_write; |
| 8571 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8572 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8573 | descriptor_write.dstSet = descriptorSet; |
| 8574 | descriptor_write.dstBinding = 2; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8575 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8576 | // 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] | 8577 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8578 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8579 | |
| 8580 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8581 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8582 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8583 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8584 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8585 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8586 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8587 | } |
| 8588 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8589 | TEST_F(VkLayerTest, InvalidDSUpdateStruct) { |
| 8590 | // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* |
| 8591 | // types |
| 8592 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8593 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 8594 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 660bcdc | 2016-05-17 10:39:46 -0600 | [diff] [blame] | 8595 | ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8596 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8597 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 8598 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8599 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8600 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8601 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8602 | |
| 8603 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8604 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8605 | ds_pool_ci.pNext = NULL; |
| 8606 | ds_pool_ci.maxSets = 1; |
| 8607 | ds_pool_ci.poolSizeCount = 1; |
| 8608 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 8609 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8610 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8611 | err = |
| 8612 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8613 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8614 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8615 | dsl_binding.binding = 0; |
| 8616 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8617 | dsl_binding.descriptorCount = 1; |
| 8618 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8619 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8620 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8621 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8622 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8623 | ds_layout_ci.pNext = NULL; |
| 8624 | ds_layout_ci.bindingCount = 1; |
| 8625 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8626 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8627 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8628 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8629 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8630 | ASSERT_VK_SUCCESS(err); |
| 8631 | |
| 8632 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8633 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8634 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8635 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8636 | alloc_info.descriptorPool = ds_pool; |
| 8637 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8638 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8639 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8640 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8641 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8642 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8643 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8644 | sampler_ci.pNext = NULL; |
| 8645 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8646 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8647 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8648 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8649 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8650 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8651 | sampler_ci.mipLodBias = 1.0; |
| 8652 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8653 | sampler_ci.maxAnisotropy = 1; |
| 8654 | sampler_ci.compareEnable = VK_FALSE; |
| 8655 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8656 | sampler_ci.minLod = 1.0; |
| 8657 | sampler_ci.maxLod = 1.0; |
| 8658 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8659 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8660 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8661 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8662 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8663 | |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8664 | VkDescriptorImageInfo info = {}; |
| 8665 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8666 | |
| 8667 | VkWriteDescriptorSet descriptor_write; |
| 8668 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8669 | descriptor_write.sType = |
| 8670 | (VkStructureType)0x99999999; /* Intentionally broken struct type */ |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8671 | descriptor_write.dstSet = descriptorSet; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8672 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8673 | // 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] | 8674 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8675 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8676 | |
| 8677 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8678 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8679 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8680 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8681 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8682 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8683 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8684 | } |
| 8685 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8686 | TEST_F(VkLayerTest, SampleDescriptorUpdateError) { |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8687 | // Create a single Sampler descriptor and send it an invalid Sampler |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8688 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8689 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8690 | m_errorMonitor->SetDesiredFailureMsg( |
| 8691 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8692 | "Attempted write update to sampler descriptor with invalid sampler"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8693 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8694 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8695 | // TODO : Farm Descriptor setup code to helper function(s) to reduce copied |
| 8696 | // code |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8697 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8698 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8699 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8700 | |
| 8701 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8702 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8703 | ds_pool_ci.pNext = NULL; |
| 8704 | ds_pool_ci.maxSets = 1; |
| 8705 | ds_pool_ci.poolSizeCount = 1; |
| 8706 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8707 | |
| 8708 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8709 | err = |
| 8710 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8711 | ASSERT_VK_SUCCESS(err); |
| 8712 | |
| 8713 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8714 | dsl_binding.binding = 0; |
| 8715 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8716 | dsl_binding.descriptorCount = 1; |
| 8717 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8718 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8719 | |
| 8720 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8721 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8722 | ds_layout_ci.pNext = NULL; |
| 8723 | ds_layout_ci.bindingCount = 1; |
| 8724 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8725 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8726 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8727 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8728 | ASSERT_VK_SUCCESS(err); |
| 8729 | |
| 8730 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8731 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8732 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8733 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8734 | alloc_info.descriptorPool = ds_pool; |
| 8735 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8736 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8737 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8738 | ASSERT_VK_SUCCESS(err); |
| 8739 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8740 | VkSampler sampler = |
| 8741 | (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8742 | |
| 8743 | VkDescriptorImageInfo descriptor_info; |
| 8744 | memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo)); |
| 8745 | descriptor_info.sampler = sampler; |
| 8746 | |
| 8747 | VkWriteDescriptorSet descriptor_write; |
| 8748 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8749 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8750 | descriptor_write.dstSet = descriptorSet; |
| 8751 | descriptor_write.dstBinding = 0; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8752 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8753 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8754 | descriptor_write.pImageInfo = &descriptor_info; |
| 8755 | |
| 8756 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8757 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8758 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8759 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8760 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8761 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8762 | } |
| 8763 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8764 | TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) { |
| 8765 | // Create a single combined Image/Sampler descriptor and send it an invalid |
| 8766 | // imageView |
| 8767 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8768 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8769 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8770 | "Attempted write update to combined " |
| 8771 | "image sampler descriptor failed due " |
Tobin Ehlis | 63c4b8a | 2016-05-09 10:29:34 -0600 | [diff] [blame] | 8772 | "to: Invalid VkImageView:"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8773 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8774 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8775 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8776 | ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 8777 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8778 | |
| 8779 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8780 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8781 | ds_pool_ci.pNext = NULL; |
| 8782 | ds_pool_ci.maxSets = 1; |
| 8783 | ds_pool_ci.poolSizeCount = 1; |
| 8784 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8785 | |
| 8786 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8787 | err = |
| 8788 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8789 | ASSERT_VK_SUCCESS(err); |
| 8790 | |
| 8791 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8792 | dsl_binding.binding = 0; |
| 8793 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 8794 | dsl_binding.descriptorCount = 1; |
| 8795 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8796 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8797 | |
| 8798 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8799 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8800 | ds_layout_ci.pNext = NULL; |
| 8801 | ds_layout_ci.bindingCount = 1; |
| 8802 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8803 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8804 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8805 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8806 | ASSERT_VK_SUCCESS(err); |
| 8807 | |
| 8808 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8809 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8810 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8811 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8812 | alloc_info.descriptorPool = ds_pool; |
| 8813 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8814 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8815 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8816 | ASSERT_VK_SUCCESS(err); |
| 8817 | |
| 8818 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8819 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8820 | sampler_ci.pNext = NULL; |
| 8821 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8822 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8823 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8824 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8825 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8826 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8827 | sampler_ci.mipLodBias = 1.0; |
| 8828 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8829 | sampler_ci.maxAnisotropy = 1; |
| 8830 | sampler_ci.compareEnable = VK_FALSE; |
| 8831 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8832 | sampler_ci.minLod = 1.0; |
| 8833 | sampler_ci.maxLod = 1.0; |
| 8834 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8835 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8836 | |
| 8837 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8838 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8839 | ASSERT_VK_SUCCESS(err); |
| 8840 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8841 | VkImageView view = |
| 8842 | (VkImageView)((size_t)0xbaadbeef); // invalid imageView object |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8843 | |
| 8844 | VkDescriptorImageInfo descriptor_info; |
| 8845 | memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo)); |
| 8846 | descriptor_info.sampler = sampler; |
| 8847 | descriptor_info.imageView = view; |
| 8848 | |
| 8849 | VkWriteDescriptorSet descriptor_write; |
| 8850 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8851 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8852 | descriptor_write.dstSet = descriptorSet; |
| 8853 | descriptor_write.dstBinding = 0; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8854 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8855 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 8856 | descriptor_write.pImageInfo = &descriptor_info; |
| 8857 | |
| 8858 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8859 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8860 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8861 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8862 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8863 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8864 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8865 | } |
| 8866 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8867 | TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) { |
| 8868 | // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update |
| 8869 | // into the other |
| 8870 | VkResult err; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8871 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8872 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8873 | " binding #1 with type " |
| 8874 | "VK_DESCRIPTOR_TYPE_SAMPLER. Types do " |
| 8875 | "not match."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8876 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8877 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8878 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8879 | VkDescriptorPoolSize ds_type_count[2] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8880 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8881 | ds_type_count[0].descriptorCount = 1; |
| 8882 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8883 | ds_type_count[1].descriptorCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8884 | |
| 8885 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8886 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8887 | ds_pool_ci.pNext = NULL; |
| 8888 | ds_pool_ci.maxSets = 1; |
| 8889 | ds_pool_ci.poolSizeCount = 2; |
| 8890 | ds_pool_ci.pPoolSizes = ds_type_count; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8891 | |
| 8892 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8893 | err = |
| 8894 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8895 | ASSERT_VK_SUCCESS(err); |
| 8896 | VkDescriptorSetLayoutBinding dsl_binding[2] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8897 | dsl_binding[0].binding = 0; |
| 8898 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8899 | dsl_binding[0].descriptorCount = 1; |
| 8900 | dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 8901 | dsl_binding[0].pImmutableSamplers = NULL; |
| 8902 | dsl_binding[1].binding = 1; |
| 8903 | dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8904 | dsl_binding[1].descriptorCount = 1; |
| 8905 | dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL; |
| 8906 | dsl_binding[1].pImmutableSamplers = NULL; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8907 | |
| 8908 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8909 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8910 | ds_layout_ci.pNext = NULL; |
| 8911 | ds_layout_ci.bindingCount = 2; |
| 8912 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8913 | |
| 8914 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8915 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8916 | &ds_layout); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8917 | ASSERT_VK_SUCCESS(err); |
| 8918 | |
| 8919 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8920 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8921 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8922 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8923 | alloc_info.descriptorPool = ds_pool; |
| 8924 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8925 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8926 | &descriptorSet); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8927 | ASSERT_VK_SUCCESS(err); |
| 8928 | |
| 8929 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8930 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8931 | sampler_ci.pNext = NULL; |
| 8932 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8933 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8934 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8935 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8936 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8937 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8938 | sampler_ci.mipLodBias = 1.0; |
| 8939 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8940 | sampler_ci.maxAnisotropy = 1; |
| 8941 | sampler_ci.compareEnable = VK_FALSE; |
| 8942 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8943 | sampler_ci.minLod = 1.0; |
| 8944 | sampler_ci.maxLod = 1.0; |
| 8945 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8946 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8947 | |
| 8948 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8949 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8950 | ASSERT_VK_SUCCESS(err); |
| 8951 | |
| 8952 | VkDescriptorImageInfo info = {}; |
| 8953 | info.sampler = sampler; |
| 8954 | |
| 8955 | VkWriteDescriptorSet descriptor_write; |
| 8956 | memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet)); |
| 8957 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8958 | descriptor_write.dstSet = descriptorSet; |
| 8959 | descriptor_write.dstBinding = 1; // SAMPLER binding from layout above |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8960 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8961 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8962 | descriptor_write.pImageInfo = &info; |
| 8963 | // This write update should succeed |
| 8964 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8965 | // Now perform a copy update that fails due to type mismatch |
| 8966 | VkCopyDescriptorSet copy_ds_update; |
| 8967 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 8968 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 8969 | copy_ds_update.srcSet = descriptorSet; |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 8970 | copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8971 | copy_ds_update.dstSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8972 | copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8973 | copy_ds_update.descriptorCount = 1; // copy 1 descriptor |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8974 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 8975 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8976 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8977 | // 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] | 8978 | m_errorMonitor->SetDesiredFailureMsg( |
| 8979 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8980 | " does not have copy update src binding of 3."); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8981 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 8982 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 8983 | copy_ds_update.srcSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8984 | copy_ds_update.srcBinding = |
| 8985 | 3; // ERROR : Invalid binding for matching layout |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8986 | copy_ds_update.dstSet = descriptorSet; |
| 8987 | copy_ds_update.dstBinding = 0; |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 8988 | copy_ds_update.descriptorCount = 1; // Copy 1 descriptor |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8989 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 8990 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8991 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8992 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8993 | // 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] | 8994 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8995 | VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus " |
| 8996 | "update array offset of 0 and update of " |
| 8997 | "5 descriptors oversteps total number " |
| 8998 | "of descriptors in set: 2."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8999 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9000 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 9001 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 9002 | copy_ds_update.srcSet = descriptorSet; |
| 9003 | copy_ds_update.srcBinding = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9004 | copy_ds_update.dstSet = descriptorSet; |
| 9005 | copy_ds_update.dstBinding = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9006 | copy_ds_update.descriptorCount = |
| 9007 | 5; // ERROR copy 5 descriptors (out of bounds for layout) |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9008 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 9009 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9010 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9011 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9012 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 9013 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9014 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 9015 | } |
| 9016 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9017 | TEST_F(VkLayerTest, NumSamplesMismatch) { |
| 9018 | // Create CommandBuffer where MSAA samples doesn't match RenderPass |
| 9019 | // sampleCount |
| 9020 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9021 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9022 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9023 | "Num samples mismatch! "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9024 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9025 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9026 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9027 | VkDescriptorPoolSize ds_type_count = {}; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9028 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9029 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9030 | |
| 9031 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9032 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9033 | ds_pool_ci.pNext = NULL; |
| 9034 | ds_pool_ci.maxSets = 1; |
| 9035 | ds_pool_ci.poolSizeCount = 1; |
| 9036 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 9037 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9038 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9039 | err = |
| 9040 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9041 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9042 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9043 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 9044 | dsl_binding.binding = 0; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9045 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | 0212448 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 9046 | dsl_binding.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9047 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9048 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9049 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9050 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9051 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9052 | ds_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9053 | ds_layout_ci.bindingCount = 1; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 9054 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9055 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9056 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9057 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9058 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9059 | ASSERT_VK_SUCCESS(err); |
| 9060 | |
| 9061 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9062 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9063 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9064 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9065 | alloc_info.descriptorPool = ds_pool; |
| 9066 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9067 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9068 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9069 | ASSERT_VK_SUCCESS(err); |
| 9070 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9071 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9072 | pipe_ms_state_ci.sType = |
| 9073 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9074 | pipe_ms_state_ci.pNext = NULL; |
| 9075 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT; |
| 9076 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9077 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9078 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9079 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9080 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9081 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9082 | pipeline_layout_ci.pNext = NULL; |
| 9083 | pipeline_layout_ci.setLayoutCount = 1; |
| 9084 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9085 | |
| 9086 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9087 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9088 | &pipeline_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9089 | ASSERT_VK_SUCCESS(err); |
| 9090 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9091 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9092 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9093 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9094 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9095 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9096 | // but add it to be able to run on more devices |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9097 | VkPipelineObj pipe(m_device); |
| 9098 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 9099 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9100 | pipe.AddColorAttachment(); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9101 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 9102 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9103 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 9104 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9105 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9106 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9107 | |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9108 | // Render triangle (the error should trigger on the attempt to draw). |
| 9109 | Draw(3, 1, 0, 0); |
| 9110 | |
| 9111 | // Finalize recording of the command buffer |
| 9112 | EndCommandBuffer(); |
| 9113 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9114 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9115 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9116 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9117 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9118 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9119 | } |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9120 | |
Tobin Ehlis | 85aa15a | 2016-06-15 10:52:37 -0600 | [diff] [blame] | 9121 | TEST_F(VkLayerTest, RenderPassIncompatible) { |
| 9122 | TEST_DESCRIPTION("Hit RenderPass incompatible cases. " |
| 9123 | "Initial case is drawing with an active renderpass that's " |
| 9124 | "not compatible with the bound PSO's creation renderpass"); |
| 9125 | VkResult err; |
| 9126 | |
| 9127 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9128 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9129 | |
| 9130 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 9131 | dsl_binding.binding = 0; |
| 9132 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9133 | dsl_binding.descriptorCount = 1; |
| 9134 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9135 | dsl_binding.pImmutableSamplers = NULL; |
| 9136 | |
| 9137 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9138 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9139 | ds_layout_ci.pNext = NULL; |
| 9140 | ds_layout_ci.bindingCount = 1; |
| 9141 | ds_layout_ci.pBindings = &dsl_binding; |
| 9142 | |
| 9143 | VkDescriptorSetLayout ds_layout; |
| 9144 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9145 | &ds_layout); |
| 9146 | ASSERT_VK_SUCCESS(err); |
| 9147 | |
| 9148 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 9149 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9150 | pipeline_layout_ci.pNext = NULL; |
| 9151 | pipeline_layout_ci.setLayoutCount = 1; |
| 9152 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 9153 | |
| 9154 | VkPipelineLayout pipeline_layout; |
| 9155 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9156 | &pipeline_layout); |
| 9157 | ASSERT_VK_SUCCESS(err); |
| 9158 | |
| 9159 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9160 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9161 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9162 | VK_SHADER_STAGE_FRAGMENT_BIT, |
| 9163 | this); // We shouldn't need a fragment shader |
| 9164 | // but add it to be able to run on more devices |
| 9165 | // Create a renderpass that will be incompatible with default renderpass |
| 9166 | VkAttachmentReference attach = {}; |
| 9167 | attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 9168 | VkAttachmentReference color_att = {}; |
| 9169 | color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 9170 | VkSubpassDescription subpass = {}; |
| 9171 | subpass.inputAttachmentCount = 1; |
| 9172 | subpass.pInputAttachments = &attach; |
| 9173 | subpass.colorAttachmentCount = 1; |
| 9174 | subpass.pColorAttachments = &color_att; |
| 9175 | VkRenderPassCreateInfo rpci = {}; |
| 9176 | rpci.subpassCount = 1; |
| 9177 | rpci.pSubpasses = &subpass; |
| 9178 | rpci.attachmentCount = 1; |
| 9179 | VkAttachmentDescription attach_desc = {}; |
| 9180 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
Cody Northrop | bd16af1 | 2016-06-21 09:25:48 -0600 | [diff] [blame] | 9181 | // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM |
| 9182 | attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM; |
Tobin Ehlis | 85aa15a | 2016-06-15 10:52:37 -0600 | [diff] [blame] | 9183 | rpci.pAttachments = &attach_desc; |
| 9184 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 9185 | VkRenderPass rp; |
| 9186 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9187 | VkPipelineObj pipe(m_device); |
| 9188 | pipe.AddShader(&vs); |
| 9189 | pipe.AddShader(&fs); |
| 9190 | pipe.AddColorAttachment(); |
| 9191 | VkViewport view_port = {}; |
| 9192 | m_viewports.push_back(view_port); |
| 9193 | pipe.SetViewport(m_viewports); |
| 9194 | VkRect2D rect = {}; |
| 9195 | m_scissors.push_back(rect); |
| 9196 | pipe.SetScissor(m_scissors); |
| 9197 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 9198 | |
| 9199 | VkCommandBufferInheritanceInfo cbii = {}; |
| 9200 | cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; |
| 9201 | cbii.renderPass = rp; |
| 9202 | cbii.subpass = 0; |
| 9203 | VkCommandBufferBeginInfo cbbi = {}; |
| 9204 | cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 9205 | cbbi.pInheritanceInfo = &cbii; |
| 9206 | vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi); |
| 9207 | VkRenderPassBeginInfo rpbi = {}; |
| 9208 | rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 9209 | rpbi.framebuffer = m_framebuffer; |
| 9210 | rpbi.renderPass = rp; |
| 9211 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, |
| 9212 | VK_SUBPASS_CONTENTS_INLINE); |
| 9213 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9214 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 9215 | |
| 9216 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9217 | " is incompatible w/ gfx pipeline "); |
| 9218 | // Render triangle (the error should trigger on the attempt to draw). |
| 9219 | Draw(3, 1, 0, 0); |
| 9220 | |
| 9221 | // Finalize recording of the command buffer |
| 9222 | EndCommandBuffer(); |
| 9223 | |
| 9224 | m_errorMonitor->VerifyFound(); |
| 9225 | |
| 9226 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9227 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9228 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 9229 | } |
| 9230 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9231 | TEST_F(VkLayerTest, NumBlendAttachMismatch) { |
| 9232 | // Create Pipeline where the number of blend attachments doesn't match the |
| 9233 | // number of color attachments. In this case, we don't add any color |
| 9234 | // blend attachments even though we have a color attachment. |
| 9235 | VkResult err; |
| 9236 | |
| 9237 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9238 | "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] | 9239 | |
| 9240 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9241 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9242 | VkDescriptorPoolSize ds_type_count = {}; |
| 9243 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9244 | ds_type_count.descriptorCount = 1; |
| 9245 | |
| 9246 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 9247 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9248 | ds_pool_ci.pNext = NULL; |
| 9249 | ds_pool_ci.maxSets = 1; |
| 9250 | ds_pool_ci.poolSizeCount = 1; |
| 9251 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 9252 | |
| 9253 | VkDescriptorPool ds_pool; |
| 9254 | err = |
| 9255 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 9256 | ASSERT_VK_SUCCESS(err); |
| 9257 | |
| 9258 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 9259 | dsl_binding.binding = 0; |
| 9260 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9261 | dsl_binding.descriptorCount = 1; |
| 9262 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9263 | dsl_binding.pImmutableSamplers = NULL; |
| 9264 | |
| 9265 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9266 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9267 | ds_layout_ci.pNext = NULL; |
| 9268 | ds_layout_ci.bindingCount = 1; |
| 9269 | ds_layout_ci.pBindings = &dsl_binding; |
| 9270 | |
| 9271 | VkDescriptorSetLayout ds_layout; |
| 9272 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9273 | &ds_layout); |
| 9274 | ASSERT_VK_SUCCESS(err); |
| 9275 | |
| 9276 | VkDescriptorSet descriptorSet; |
| 9277 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 9278 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 9279 | alloc_info.descriptorSetCount = 1; |
| 9280 | alloc_info.descriptorPool = ds_pool; |
| 9281 | alloc_info.pSetLayouts = &ds_layout; |
| 9282 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9283 | &descriptorSet); |
| 9284 | ASSERT_VK_SUCCESS(err); |
| 9285 | |
| 9286 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
| 9287 | pipe_ms_state_ci.sType = |
| 9288 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9289 | pipe_ms_state_ci.pNext = NULL; |
| 9290 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; |
| 9291 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9292 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9293 | pipe_ms_state_ci.pSampleMask = NULL; |
| 9294 | |
| 9295 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 9296 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9297 | pipeline_layout_ci.pNext = NULL; |
| 9298 | pipeline_layout_ci.setLayoutCount = 1; |
| 9299 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 9300 | |
| 9301 | VkPipelineLayout pipeline_layout; |
| 9302 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9303 | &pipeline_layout); |
| 9304 | ASSERT_VK_SUCCESS(err); |
| 9305 | |
| 9306 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9307 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9308 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9309 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9310 | this); // We shouldn't need a fragment shader |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9311 | // but add it to be able to run on more devices |
| 9312 | VkPipelineObj pipe(m_device); |
| 9313 | pipe.AddShader(&vs); |
| 9314 | pipe.AddShader(&fs); |
| 9315 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 9316 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 9317 | |
| 9318 | BeginCommandBuffer(); |
| 9319 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9320 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 9321 | |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9322 | // Render triangle (the error should trigger on the attempt to draw). |
| 9323 | Draw(3, 1, 0, 0); |
| 9324 | |
| 9325 | // Finalize recording of the command buffer |
| 9326 | EndCommandBuffer(); |
| 9327 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9328 | m_errorMonitor->VerifyFound(); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9329 | |
| 9330 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9331 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9332 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 9333 | } |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9334 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 9335 | TEST_F(VkLayerTest, MissingClearAttachment) { |
| 9336 | TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment " |
| 9337 | "structure passed to vkCmdClearAttachments"); |
| 9338 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9339 | "vkCmdClearAttachments() attachment index 1 not found in attachment " |
| 9340 | "reference array of active subpass 0"); |
| 9341 | |
| 9342 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments); |
| 9343 | m_errorMonitor->VerifyFound(); |
| 9344 | } |
| 9345 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9346 | TEST_F(VkLayerTest, ClearCmdNoDraw) { |
| 9347 | // Create CommandBuffer where we add ClearCmd for FB Color attachment prior |
| 9348 | // to issuing a Draw |
| 9349 | VkResult err; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9350 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9351 | m_errorMonitor->SetDesiredFailureMsg( |
Tony Barbour | 7e56d30 | 2016-03-02 15:12:01 -0700 | [diff] [blame] | 9352 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9353 | "vkCmdClearAttachments() issued on CB object "); |
| 9354 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9355 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9356 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9357 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9358 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9359 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9360 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9361 | |
| 9362 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9363 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9364 | ds_pool_ci.pNext = NULL; |
| 9365 | ds_pool_ci.maxSets = 1; |
| 9366 | ds_pool_ci.poolSizeCount = 1; |
| 9367 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9368 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9369 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9370 | err = |
| 9371 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9372 | ASSERT_VK_SUCCESS(err); |
| 9373 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9374 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9375 | dsl_binding.binding = 0; |
| 9376 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9377 | dsl_binding.descriptorCount = 1; |
| 9378 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9379 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9380 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9381 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9382 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9383 | ds_layout_ci.pNext = NULL; |
| 9384 | ds_layout_ci.bindingCount = 1; |
| 9385 | ds_layout_ci.pBindings = &dsl_binding; |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9386 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9387 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9388 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9389 | &ds_layout); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9390 | ASSERT_VK_SUCCESS(err); |
| 9391 | |
| 9392 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9393 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9394 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9395 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9396 | alloc_info.descriptorPool = ds_pool; |
| 9397 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9398 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9399 | &descriptorSet); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9400 | ASSERT_VK_SUCCESS(err); |
| 9401 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9402 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9403 | pipe_ms_state_ci.sType = |
| 9404 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9405 | pipe_ms_state_ci.pNext = NULL; |
| 9406 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT; |
| 9407 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9408 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9409 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9410 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9411 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9412 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9413 | pipeline_layout_ci.pNext = NULL; |
| 9414 | pipeline_layout_ci.setLayoutCount = 1; |
| 9415 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9416 | |
| 9417 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9418 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9419 | &pipeline_layout); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9420 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9421 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9422 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9423 | VK_SHADER_STAGE_VERTEX_BIT, this); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9424 | // 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] | 9425 | // on more devices |
| 9426 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9427 | VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9428 | |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9429 | VkPipelineObj pipe(m_device); |
| 9430 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 9431 | pipe.AddShader(&fs); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9432 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 9433 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 9434 | |
| 9435 | BeginCommandBuffer(); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9436 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9437 | // Main thing we care about for this test is that the VkImage obj we're |
| 9438 | // clearing matches Color Attachment of FB |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9439 | // Also pass down other dummy params to keep driver and paramchecker happy |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 9440 | VkClearAttachment color_attachment; |
| 9441 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9442 | color_attachment.clearValue.color.float32[0] = 1.0; |
| 9443 | color_attachment.clearValue.color.float32[1] = 1.0; |
| 9444 | color_attachment.clearValue.color.float32[2] = 1.0; |
| 9445 | color_attachment.clearValue.color.float32[3] = 1.0; |
| 9446 | color_attachment.colorAttachment = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9447 | VkClearRect clear_rect = { |
| 9448 | {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}}; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9449 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9450 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 9451 | &color_attachment, 1, &clear_rect); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9452 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9453 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9454 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9455 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9456 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9457 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9458 | } |
| 9459 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9460 | TEST_F(VkLayerTest, VtxBufferBadIndex) { |
| 9461 | VkResult err; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9462 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9463 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 9464 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | dfcd9b6 | 2015-12-14 15:14:10 -0700 | [diff] [blame] | 9465 | "but no vertex buffers are attached to this Pipeline State Object"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9466 | |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9467 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 9468 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9469 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9470 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9471 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9472 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9473 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9474 | |
| 9475 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9476 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9477 | ds_pool_ci.pNext = NULL; |
| 9478 | ds_pool_ci.maxSets = 1; |
| 9479 | ds_pool_ci.poolSizeCount = 1; |
| 9480 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9481 | |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 9482 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9483 | err = |
| 9484 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9485 | ASSERT_VK_SUCCESS(err); |
| 9486 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9487 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9488 | dsl_binding.binding = 0; |
| 9489 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9490 | dsl_binding.descriptorCount = 1; |
| 9491 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9492 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9493 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9494 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9495 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9496 | ds_layout_ci.pNext = NULL; |
| 9497 | ds_layout_ci.bindingCount = 1; |
| 9498 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9499 | |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9500 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9501 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9502 | &ds_layout); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9503 | ASSERT_VK_SUCCESS(err); |
| 9504 | |
| 9505 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9506 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9507 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9508 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9509 | alloc_info.descriptorPool = ds_pool; |
| 9510 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9511 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9512 | &descriptorSet); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9513 | ASSERT_VK_SUCCESS(err); |
| 9514 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9515 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9516 | pipe_ms_state_ci.sType = |
| 9517 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9518 | pipe_ms_state_ci.pNext = NULL; |
| 9519 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; |
| 9520 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9521 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9522 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9523 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9524 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9525 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9526 | pipeline_layout_ci.pNext = NULL; |
| 9527 | pipeline_layout_ci.setLayoutCount = 1; |
| 9528 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 9529 | VkPipelineLayout pipeline_layout; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9530 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9531 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9532 | &pipeline_layout); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9533 | ASSERT_VK_SUCCESS(err); |
| 9534 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9535 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9536 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9537 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9538 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9539 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9540 | // but add it to be able to run on more devices |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9541 | VkPipelineObj pipe(m_device); |
| 9542 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 9543 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9544 | pipe.AddColorAttachment(); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9545 | pipe.SetMSAA(&pipe_ms_state_ci); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 9546 | pipe.SetViewport(m_viewports); |
| 9547 | pipe.SetScissor(m_scissors); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9548 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 9549 | |
| 9550 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9551 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9552 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | f7bf450 | 2015-09-09 15:12:35 -0600 | [diff] [blame] | 9553 | // Don't care about actual data, just need to get to draw to flag error |
| 9554 | static const float vbo_data[3] = {1.f, 0.f, 1.f}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9555 | VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), |
| 9556 | (const void *)&vbo_data); |
Tobin Ehlis | f7bf450 | 2015-09-09 15:12:35 -0600 | [diff] [blame] | 9557 | 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] | 9558 | Draw(1, 0, 0, 0); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9559 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9560 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9561 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9562 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9563 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9564 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9565 | } |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 9566 | // INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here) |
| 9567 | TEST_F(VkLayerTest, InvalidImageLayout) { |
| 9568 | TEST_DESCRIPTION("Hit all possible validation checks associated with the " |
| 9569 | "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having" |
| 9570 | "images in the wrong layout when they're copied or transitioned."); |
| 9571 | // 3 in ValidateCmdBufImageLayouts |
| 9572 | // * -1 Attempt to submit cmd buf w/ deleted image |
| 9573 | // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource |
| 9574 | // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource |
| 9575 | m_errorMonitor->SetDesiredFailureMsg( |
| 9576 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9577 | "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL."); |
| 9578 | |
| 9579 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9580 | // Create src & dst images to use for copy operations |
| 9581 | VkImage src_image; |
| 9582 | VkImage dst_image; |
| 9583 | |
| 9584 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 9585 | const int32_t tex_width = 32; |
| 9586 | const int32_t tex_height = 32; |
| 9587 | |
| 9588 | VkImageCreateInfo image_create_info = {}; |
| 9589 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 9590 | image_create_info.pNext = NULL; |
| 9591 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 9592 | image_create_info.format = tex_format; |
| 9593 | image_create_info.extent.width = tex_width; |
| 9594 | image_create_info.extent.height = tex_height; |
| 9595 | image_create_info.extent.depth = 1; |
| 9596 | image_create_info.mipLevels = 1; |
| 9597 | image_create_info.arrayLayers = 4; |
| 9598 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 9599 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 9600 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 9601 | image_create_info.flags = 0; |
| 9602 | |
| 9603 | VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image); |
| 9604 | ASSERT_VK_SUCCESS(err); |
| 9605 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image); |
| 9606 | ASSERT_VK_SUCCESS(err); |
| 9607 | |
| 9608 | BeginCommandBuffer(); |
| 9609 | VkImageCopy copyRegion; |
| 9610 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9611 | copyRegion.srcSubresource.mipLevel = 0; |
| 9612 | copyRegion.srcSubresource.baseArrayLayer = 0; |
| 9613 | copyRegion.srcSubresource.layerCount = 1; |
| 9614 | copyRegion.srcOffset.x = 0; |
| 9615 | copyRegion.srcOffset.y = 0; |
| 9616 | copyRegion.srcOffset.z = 0; |
| 9617 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9618 | copyRegion.dstSubresource.mipLevel = 0; |
| 9619 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 9620 | copyRegion.dstSubresource.layerCount = 1; |
| 9621 | copyRegion.dstOffset.x = 0; |
| 9622 | copyRegion.dstOffset.y = 0; |
| 9623 | copyRegion.dstOffset.z = 0; |
| 9624 | copyRegion.extent.width = 1; |
| 9625 | copyRegion.extent.height = 1; |
| 9626 | copyRegion.extent.depth = 1; |
| 9627 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9628 | m_errorMonitor->VerifyFound(); |
| 9629 | // Now cause error due to src image layout changing |
| 9630 | m_errorMonitor->SetDesiredFailureMsg( |
| 9631 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9632 | "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL."); |
| 9633 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9634 | m_errorMonitor->VerifyFound(); |
| 9635 | // Final src error is due to bad layout type |
| 9636 | m_errorMonitor->SetDesiredFailureMsg( |
| 9637 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9638 | "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL."); |
| 9639 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9640 | m_errorMonitor->VerifyFound(); |
| 9641 | // Now verify same checks for dst |
| 9642 | m_errorMonitor->SetDesiredFailureMsg( |
| 9643 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9644 | "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL."); |
| 9645 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9646 | m_errorMonitor->VerifyFound(); |
| 9647 | // Now cause error due to src image layout changing |
| 9648 | m_errorMonitor->SetDesiredFailureMsg( |
| 9649 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9650 | "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL."); |
| 9651 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, ©Region); |
| 9652 | m_errorMonitor->VerifyFound(); |
| 9653 | m_errorMonitor->SetDesiredFailureMsg( |
| 9654 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9655 | "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL."); |
| 9656 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, ©Region); |
| 9657 | m_errorMonitor->VerifyFound(); |
| 9658 | // Now cause error due to bad image layout transition in PipelineBarrier |
| 9659 | VkImageMemoryBarrier image_barrier[1] = {}; |
| 9660 | image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 9661 | image_barrier[0].image = src_image; |
| 9662 | image_barrier[0].subresourceRange.layerCount = 2; |
| 9663 | image_barrier[0].subresourceRange.levelCount = 2; |
| 9664 | image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9665 | m_errorMonitor->SetDesiredFailureMsg( |
| 9666 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9667 | "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL."); |
| 9668 | vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier); |
| 9669 | m_errorMonitor->VerifyFound(); |
| 9670 | |
| 9671 | // Finally some layout errors at RenderPass create time |
| 9672 | // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing. |
| 9673 | VkAttachmentReference attach = {}; |
| 9674 | // perf warning for GENERAL layout w/ non-DS input attachment |
| 9675 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 9676 | VkSubpassDescription subpass = {}; |
| 9677 | subpass.inputAttachmentCount = 1; |
| 9678 | subpass.pInputAttachments = &attach; |
| 9679 | VkRenderPassCreateInfo rpci = {}; |
| 9680 | rpci.subpassCount = 1; |
| 9681 | rpci.pSubpasses = &subpass; |
| 9682 | rpci.attachmentCount = 1; |
| 9683 | VkAttachmentDescription attach_desc = {}; |
| 9684 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 9685 | rpci.pAttachments = &attach_desc; |
Tobin Ehlis | 1efce02 | 2016-05-11 10:40:34 -0600 | [diff] [blame] | 9686 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 9687 | VkRenderPass rp; |
| 9688 | m_errorMonitor->SetDesiredFailureMsg( |
| 9689 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9690 | "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL."); |
| 9691 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9692 | m_errorMonitor->VerifyFound(); |
| 9693 | // error w/ non-general layout |
| 9694 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 9695 | |
| 9696 | m_errorMonitor->SetDesiredFailureMsg( |
| 9697 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9698 | "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL."); |
| 9699 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9700 | m_errorMonitor->VerifyFound(); |
| 9701 | subpass.inputAttachmentCount = 0; |
| 9702 | subpass.colorAttachmentCount = 1; |
| 9703 | subpass.pColorAttachments = &attach; |
| 9704 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 9705 | // perf warning for GENERAL layout on color attachment |
| 9706 | m_errorMonitor->SetDesiredFailureMsg( |
| 9707 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9708 | "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL."); |
| 9709 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9710 | m_errorMonitor->VerifyFound(); |
| 9711 | // error w/ non-color opt or GENERAL layout for color attachment |
| 9712 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 9713 | m_errorMonitor->SetDesiredFailureMsg( |
| 9714 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9715 | "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL."); |
| 9716 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9717 | m_errorMonitor->VerifyFound(); |
| 9718 | subpass.colorAttachmentCount = 0; |
| 9719 | subpass.pDepthStencilAttachment = &attach; |
| 9720 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 9721 | // perf warning for GENERAL layout on DS attachment |
| 9722 | m_errorMonitor->SetDesiredFailureMsg( |
| 9723 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9724 | "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL."); |
| 9725 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9726 | m_errorMonitor->VerifyFound(); |
| 9727 | // error w/ non-ds opt or GENERAL layout for color attachment |
| 9728 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 9729 | m_errorMonitor->SetDesiredFailureMsg( |
| 9730 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9731 | "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL."); |
| 9732 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9733 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 1efce02 | 2016-05-11 10:40:34 -0600 | [diff] [blame] | 9734 | // For this error we need a valid renderpass so create default one |
| 9735 | attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 9736 | attach.attachment = 0; |
| 9737 | attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 9738 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
| 9739 | attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE; |
| 9740 | attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 9741 | attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 9742 | // Can't do a CLEAR load on READ_ONLY initialLayout |
| 9743 | attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 9744 | attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 9745 | attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 9746 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9747 | " with invalid first layout " |
| 9748 | "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_" |
| 9749 | "ONLY_OPTIMAL"); |
| 9750 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9751 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 9752 | |
| 9753 | vkDestroyImage(m_device->device(), src_image, NULL); |
| 9754 | vkDestroyImage(m_device->device(), dst_image, NULL); |
| 9755 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9756 | #endif // DRAW_STATE_TESTS |
| 9757 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 9758 | #if THREADING_TESTS |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9759 | #if GTEST_IS_THREADSAFE |
| 9760 | struct thread_data_struct { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9761 | VkCommandBuffer commandBuffer; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9762 | VkEvent event; |
| 9763 | bool bailout; |
| 9764 | }; |
| 9765 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9766 | extern "C" void *AddToCommandBuffer(void *arg) { |
| 9767 | struct thread_data_struct *data = (struct thread_data_struct *)arg; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9768 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9769 | for (int i = 0; i < 10000; i++) { |
| 9770 | vkCmdSetEvent(data->commandBuffer, data->event, |
| 9771 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9772 | if (data->bailout) { |
| 9773 | break; |
| 9774 | } |
| 9775 | } |
| 9776 | return NULL; |
| 9777 | } |
| 9778 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9779 | TEST_F(VkLayerTest, ThreadCommandBufferCollision) { |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 9780 | test_platform_thread thread; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9781 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9782 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9783 | "THREADING ERROR"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9784 | |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9785 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9786 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 9787 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9788 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9789 | // Calls AllocateCommandBuffers |
| 9790 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
Mark Lobodzinski | 5495d13 | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 9791 | |
| 9792 | // Avoid creating RenderPass |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9793 | commandBuffer.BeginCommandBuffer(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9794 | |
| 9795 | VkEventCreateInfo event_info; |
| 9796 | VkEvent event; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9797 | VkResult err; |
| 9798 | |
| 9799 | memset(&event_info, 0, sizeof(event_info)); |
| 9800 | event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 9801 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9802 | err = vkCreateEvent(device(), &event_info, NULL, &event); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9803 | ASSERT_VK_SUCCESS(err); |
| 9804 | |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9805 | err = vkResetEvent(device(), event); |
| 9806 | ASSERT_VK_SUCCESS(err); |
| 9807 | |
| 9808 | struct thread_data_struct data; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9809 | data.commandBuffer = commandBuffer.GetBufferHandle(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9810 | data.event = event; |
| 9811 | data.bailout = false; |
| 9812 | m_errorMonitor->SetBailout(&data.bailout); |
| 9813 | // Add many entries to command buffer from another thread. |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 9814 | test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9815 | // Add many entries to command buffer from this thread at the same time. |
| 9816 | AddToCommandBuffer(&data); |
Mark Lobodzinski | 5495d13 | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 9817 | |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 9818 | test_platform_thread_join(thread, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9819 | commandBuffer.EndCommandBuffer(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9820 | |
Mike Stroyan | 10b8cb7 | 2016-01-22 15:22:03 -0700 | [diff] [blame] | 9821 | m_errorMonitor->SetBailout(NULL); |
| 9822 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9823 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9824 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9825 | vkDestroyEvent(device(), event, NULL); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9826 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9827 | #endif // GTEST_IS_THREADSAFE |
| 9828 | #endif // THREADING_TESTS |
| 9829 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9830 | #if SHADER_CHECKER_TESTS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9831 | TEST_F(VkLayerTest, InvalidSPIRVCodeSize) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9832 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9833 | "Invalid SPIR-V header"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9834 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9835 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9836 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9837 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9838 | VkShaderModule module; |
| 9839 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 9840 | struct icd_spv_header spv; |
| 9841 | |
| 9842 | spv.magic = ICD_SPV_MAGIC; |
| 9843 | spv.version = ICD_SPV_VERSION; |
| 9844 | spv.gen_magic = 0; |
| 9845 | |
| 9846 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 9847 | moduleCreateInfo.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9848 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9849 | moduleCreateInfo.codeSize = 4; |
| 9850 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9851 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9852 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9853 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9854 | } |
| 9855 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9856 | TEST_F(VkLayerTest, InvalidSPIRVMagic) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9857 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9858 | "Invalid SPIR-V magic number"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9859 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9860 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9861 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9862 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9863 | VkShaderModule module; |
| 9864 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 9865 | struct icd_spv_header spv; |
| 9866 | |
| 9867 | spv.magic = ~ICD_SPV_MAGIC; |
| 9868 | spv.version = ICD_SPV_VERSION; |
| 9869 | spv.gen_magic = 0; |
| 9870 | |
| 9871 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 9872 | moduleCreateInfo.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9873 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9874 | moduleCreateInfo.codeSize = sizeof(spv) + 10; |
| 9875 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9876 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9877 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9878 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9879 | } |
| 9880 | |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9881 | #if 0 |
| 9882 | // Not currently covered by SPIRV-Tools validator |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9883 | TEST_F(VkLayerTest, InvalidSPIRVVersion) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9884 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9885 | "Invalid SPIR-V header"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9886 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9887 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9888 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9889 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9890 | VkShaderModule module; |
| 9891 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 9892 | struct icd_spv_header spv; |
| 9893 | |
| 9894 | spv.magic = ICD_SPV_MAGIC; |
| 9895 | spv.version = ~ICD_SPV_VERSION; |
| 9896 | spv.gen_magic = 0; |
| 9897 | |
| 9898 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 9899 | moduleCreateInfo.pNext = NULL; |
| 9900 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9901 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9902 | moduleCreateInfo.codeSize = sizeof(spv) + 10; |
| 9903 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9904 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9905 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9906 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9907 | } |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9908 | #endif |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9909 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9910 | TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 9911 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9912 | "not consumed by fragment shader"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9913 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9914 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 9915 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9916 | |
| 9917 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9918 | "#version 450\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9919 | "\n" |
| 9920 | "layout(location=0) out float x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 9921 | "out gl_PerVertex {\n" |
| 9922 | " vec4 gl_Position;\n" |
| 9923 | "};\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9924 | "void main(){\n" |
| 9925 | " gl_Position = vec4(1);\n" |
| 9926 | " x = 0;\n" |
| 9927 | "}\n"; |
| 9928 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9929 | "#version 450\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9930 | "\n" |
| 9931 | "layout(location=0) out vec4 color;\n" |
| 9932 | "void main(){\n" |
| 9933 | " color = vec4(1);\n" |
| 9934 | "}\n"; |
| 9935 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 9936 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9937 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9938 | |
| 9939 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 9940 | pipe.AddColorAttachment(); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9941 | pipe.AddShader(&vs); |
| 9942 | pipe.AddShader(&fs); |
| 9943 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9944 | VkDescriptorSetObj descriptorSet(m_device); |
| 9945 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9946 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9947 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 9948 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9949 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9950 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9951 | } |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9952 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9953 | TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9954 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9955 | "not written by vertex shader"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9956 | |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9957 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 9958 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9959 | |
| 9960 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9961 | "#version 450\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9962 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 9963 | "out gl_PerVertex {\n" |
| 9964 | " vec4 gl_Position;\n" |
| 9965 | "};\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9966 | "void main(){\n" |
| 9967 | " gl_Position = vec4(1);\n" |
| 9968 | "}\n"; |
| 9969 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9970 | "#version 450\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9971 | "\n" |
| 9972 | "layout(location=0) in float x;\n" |
| 9973 | "layout(location=0) out vec4 color;\n" |
| 9974 | "void main(){\n" |
| 9975 | " color = vec4(x);\n" |
| 9976 | "}\n"; |
| 9977 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 9978 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9979 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9980 | |
| 9981 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 9982 | pipe.AddColorAttachment(); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9983 | pipe.AddShader(&vs); |
| 9984 | pipe.AddShader(&fs); |
| 9985 | |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9986 | VkDescriptorSetObj descriptorSet(m_device); |
| 9987 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9988 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9989 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 9990 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9991 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9992 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9993 | } |
| 9994 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9995 | TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) { |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9996 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9997 | "not written by vertex shader"); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9998 | |
| 9999 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10000 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10001 | |
| 10002 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10003 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10004 | "\n" |
| 10005 | "out gl_PerVertex {\n" |
| 10006 | " vec4 gl_Position;\n" |
| 10007 | "};\n" |
| 10008 | "void main(){\n" |
| 10009 | " gl_Position = vec4(1);\n" |
| 10010 | "}\n"; |
| 10011 | char const *fsSource = |
| 10012 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10013 | "\n" |
| 10014 | "in block { layout(location=0) float x; } ins;\n" |
| 10015 | "layout(location=0) out vec4 color;\n" |
| 10016 | "void main(){\n" |
| 10017 | " color = vec4(ins.x);\n" |
| 10018 | "}\n"; |
| 10019 | |
| 10020 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10021 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10022 | |
| 10023 | VkPipelineObj pipe(m_device); |
| 10024 | pipe.AddColorAttachment(); |
| 10025 | pipe.AddShader(&vs); |
| 10026 | pipe.AddShader(&fs); |
| 10027 | |
| 10028 | VkDescriptorSetObj descriptorSet(m_device); |
| 10029 | descriptorSet.AppendDummy(); |
| 10030 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10031 | |
| 10032 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10033 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10034 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10035 | } |
| 10036 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10037 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) { |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10038 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10039 | "Type mismatch on location 0.0: 'ptr to " |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10040 | "output arr[2] of float32' vs 'ptr to " |
| 10041 | "input arr[3] of float32'"); |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10042 | |
| 10043 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10044 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10045 | |
| 10046 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10047 | "#version 450\n" |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10048 | "\n" |
| 10049 | "layout(location=0) out float x[2];\n" |
| 10050 | "out gl_PerVertex {\n" |
| 10051 | " vec4 gl_Position;\n" |
| 10052 | "};\n" |
| 10053 | "void main(){\n" |
| 10054 | " x[0] = 0; x[1] = 0;\n" |
| 10055 | " gl_Position = vec4(1);\n" |
| 10056 | "}\n"; |
| 10057 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10058 | "#version 450\n" |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10059 | "\n" |
| 10060 | "layout(location=0) in float x[3];\n" |
| 10061 | "layout(location=0) out vec4 color;\n" |
| 10062 | "void main(){\n" |
| 10063 | " color = vec4(x[0] + x[1] + x[2]);\n" |
| 10064 | "}\n"; |
| 10065 | |
| 10066 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10067 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10068 | |
| 10069 | VkPipelineObj pipe(m_device); |
| 10070 | pipe.AddColorAttachment(); |
| 10071 | pipe.AddShader(&vs); |
| 10072 | pipe.AddShader(&fs); |
| 10073 | |
| 10074 | VkDescriptorSetObj descriptorSet(m_device); |
| 10075 | descriptorSet.AppendDummy(); |
| 10076 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10077 | |
| 10078 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10079 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10080 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10081 | } |
| 10082 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10083 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10084 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10085 | "Type mismatch on location 0"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10086 | |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10087 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10088 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10089 | |
| 10090 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10091 | "#version 450\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10092 | "\n" |
| 10093 | "layout(location=0) out int x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10094 | "out gl_PerVertex {\n" |
| 10095 | " vec4 gl_Position;\n" |
| 10096 | "};\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10097 | "void main(){\n" |
| 10098 | " x = 0;\n" |
| 10099 | " gl_Position = vec4(1);\n" |
| 10100 | "}\n"; |
| 10101 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10102 | "#version 450\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10103 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10104 | "layout(location=0) in float x;\n" /* VS writes int */ |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10105 | "layout(location=0) out vec4 color;\n" |
| 10106 | "void main(){\n" |
| 10107 | " color = vec4(x);\n" |
| 10108 | "}\n"; |
| 10109 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10110 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10111 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10112 | |
| 10113 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10114 | pipe.AddColorAttachment(); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10115 | pipe.AddShader(&vs); |
| 10116 | pipe.AddShader(&fs); |
| 10117 | |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10118 | VkDescriptorSetObj descriptorSet(m_device); |
| 10119 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10120 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10121 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10122 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10123 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10124 | m_errorMonitor->VerifyFound(); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10125 | } |
| 10126 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10127 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) { |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10128 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10129 | "Type mismatch on location 0"); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10130 | |
| 10131 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10132 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10133 | |
| 10134 | char const *vsSource = |
| 10135 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10136 | "\n" |
| 10137 | "out block { layout(location=0) int x; } outs;\n" |
| 10138 | "out gl_PerVertex {\n" |
| 10139 | " vec4 gl_Position;\n" |
| 10140 | "};\n" |
| 10141 | "void main(){\n" |
| 10142 | " outs.x = 0;\n" |
| 10143 | " gl_Position = vec4(1);\n" |
| 10144 | "}\n"; |
| 10145 | char const *fsSource = |
| 10146 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10147 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10148 | "in block { layout(location=0) float x; } ins;\n" /* VS writes int */ |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10149 | "layout(location=0) out vec4 color;\n" |
| 10150 | "void main(){\n" |
| 10151 | " color = vec4(ins.x);\n" |
| 10152 | "}\n"; |
| 10153 | |
| 10154 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10155 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10156 | |
| 10157 | VkPipelineObj pipe(m_device); |
| 10158 | pipe.AddColorAttachment(); |
| 10159 | pipe.AddShader(&vs); |
| 10160 | pipe.AddShader(&fs); |
| 10161 | |
| 10162 | VkDescriptorSetObj descriptorSet(m_device); |
| 10163 | descriptorSet.AppendDummy(); |
| 10164 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10165 | |
| 10166 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10167 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10168 | m_errorMonitor->VerifyFound(); |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10169 | } |
| 10170 | |
| 10171 | TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) { |
| 10172 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10173 | "location 0.0 which is not written by vertex shader"); |
| 10174 | |
| 10175 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10176 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10177 | |
| 10178 | char const *vsSource = |
| 10179 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10180 | "\n" |
| 10181 | "out block { layout(location=1) float x; } outs;\n" |
| 10182 | "out gl_PerVertex {\n" |
| 10183 | " vec4 gl_Position;\n" |
| 10184 | "};\n" |
| 10185 | "void main(){\n" |
| 10186 | " outs.x = 0;\n" |
| 10187 | " gl_Position = vec4(1);\n" |
| 10188 | "}\n"; |
| 10189 | char const *fsSource = |
| 10190 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10191 | "\n" |
| 10192 | "in block { layout(location=0) float x; } ins;\n" |
| 10193 | "layout(location=0) out vec4 color;\n" |
| 10194 | "void main(){\n" |
| 10195 | " color = vec4(ins.x);\n" |
| 10196 | "}\n"; |
| 10197 | |
| 10198 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10199 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10200 | |
| 10201 | VkPipelineObj pipe(m_device); |
| 10202 | pipe.AddColorAttachment(); |
| 10203 | pipe.AddShader(&vs); |
| 10204 | pipe.AddShader(&fs); |
| 10205 | |
| 10206 | VkDescriptorSetObj descriptorSet(m_device); |
| 10207 | descriptorSet.AppendDummy(); |
| 10208 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10209 | |
| 10210 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10211 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10212 | m_errorMonitor->VerifyFound(); |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10213 | } |
| 10214 | |
| 10215 | TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) { |
| 10216 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10217 | "location 0.1 which is not written by vertex shader"); |
| 10218 | |
| 10219 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10220 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10221 | |
| 10222 | char const *vsSource = |
| 10223 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10224 | "\n" |
| 10225 | "out block { layout(location=0, component=0) float x; } outs;\n" |
| 10226 | "out gl_PerVertex {\n" |
| 10227 | " vec4 gl_Position;\n" |
| 10228 | "};\n" |
| 10229 | "void main(){\n" |
| 10230 | " outs.x = 0;\n" |
| 10231 | " gl_Position = vec4(1);\n" |
| 10232 | "}\n"; |
| 10233 | char const *fsSource = |
| 10234 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10235 | "\n" |
| 10236 | "in block { layout(location=0, component=1) float x; } ins;\n" |
| 10237 | "layout(location=0) out vec4 color;\n" |
| 10238 | "void main(){\n" |
| 10239 | " color = vec4(ins.x);\n" |
| 10240 | "}\n"; |
| 10241 | |
| 10242 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10243 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10244 | |
| 10245 | VkPipelineObj pipe(m_device); |
| 10246 | pipe.AddColorAttachment(); |
| 10247 | pipe.AddShader(&vs); |
| 10248 | pipe.AddShader(&fs); |
| 10249 | |
| 10250 | VkDescriptorSetObj descriptorSet(m_device); |
| 10251 | descriptorSet.AppendDummy(); |
| 10252 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10253 | |
| 10254 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10255 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10256 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10257 | } |
| 10258 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10259 | TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 10260 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10261 | "location 0 not consumed by VS"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10262 | |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10263 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10264 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10265 | |
| 10266 | VkVertexInputBindingDescription input_binding; |
| 10267 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10268 | |
| 10269 | VkVertexInputAttributeDescription input_attrib; |
| 10270 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10271 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10272 | |
| 10273 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10274 | "#version 450\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10275 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10276 | "out gl_PerVertex {\n" |
| 10277 | " vec4 gl_Position;\n" |
| 10278 | "};\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10279 | "void main(){\n" |
| 10280 | " gl_Position = vec4(1);\n" |
| 10281 | "}\n"; |
| 10282 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10283 | "#version 450\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10284 | "\n" |
| 10285 | "layout(location=0) out vec4 color;\n" |
| 10286 | "void main(){\n" |
| 10287 | " color = vec4(1);\n" |
| 10288 | "}\n"; |
| 10289 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10290 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10291 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10292 | |
| 10293 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10294 | pipe.AddColorAttachment(); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10295 | pipe.AddShader(&vs); |
| 10296 | pipe.AddShader(&fs); |
| 10297 | |
| 10298 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10299 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10300 | |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10301 | VkDescriptorSetObj descriptorSet(m_device); |
| 10302 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10303 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10304 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10305 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10306 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10307 | m_errorMonitor->VerifyFound(); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10308 | } |
| 10309 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10310 | TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 10311 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10312 | "location 0 not consumed by VS"); |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10313 | |
| 10314 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10315 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10316 | |
| 10317 | VkVertexInputBindingDescription input_binding; |
| 10318 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10319 | |
| 10320 | VkVertexInputAttributeDescription input_attrib; |
| 10321 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10322 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10323 | |
| 10324 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10325 | "#version 450\n" |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10326 | "\n" |
| 10327 | "layout(location=1) in float x;\n" |
| 10328 | "out gl_PerVertex {\n" |
| 10329 | " vec4 gl_Position;\n" |
| 10330 | "};\n" |
| 10331 | "void main(){\n" |
| 10332 | " gl_Position = vec4(x);\n" |
| 10333 | "}\n"; |
| 10334 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10335 | "#version 450\n" |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10336 | "\n" |
| 10337 | "layout(location=0) out vec4 color;\n" |
| 10338 | "void main(){\n" |
| 10339 | " color = vec4(1);\n" |
| 10340 | "}\n"; |
| 10341 | |
| 10342 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10343 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10344 | |
| 10345 | VkPipelineObj pipe(m_device); |
| 10346 | pipe.AddColorAttachment(); |
| 10347 | pipe.AddShader(&vs); |
| 10348 | pipe.AddShader(&fs); |
| 10349 | |
| 10350 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10351 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10352 | |
| 10353 | VkDescriptorSetObj descriptorSet(m_device); |
| 10354 | descriptorSet.AppendDummy(); |
| 10355 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10356 | |
| 10357 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10358 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10359 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10360 | } |
| 10361 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10362 | TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) { |
| 10363 | m_errorMonitor->SetDesiredFailureMsg( |
| 10364 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10365 | "VS consumes input at location 0 but not provided"); |
| 10366 | |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10367 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10368 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10369 | |
| 10370 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10371 | "#version 450\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10372 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10373 | "layout(location=0) in vec4 x;\n" /* not provided */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10374 | "out gl_PerVertex {\n" |
| 10375 | " vec4 gl_Position;\n" |
| 10376 | "};\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10377 | "void main(){\n" |
| 10378 | " gl_Position = x;\n" |
| 10379 | "}\n"; |
| 10380 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10381 | "#version 450\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10382 | "\n" |
| 10383 | "layout(location=0) out vec4 color;\n" |
| 10384 | "void main(){\n" |
| 10385 | " color = vec4(1);\n" |
| 10386 | "}\n"; |
| 10387 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10388 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10389 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10390 | |
| 10391 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10392 | pipe.AddColorAttachment(); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10393 | pipe.AddShader(&vs); |
| 10394 | pipe.AddShader(&fs); |
| 10395 | |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10396 | VkDescriptorSetObj descriptorSet(m_device); |
| 10397 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10398 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10399 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10400 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10401 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10402 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10403 | } |
| 10404 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10405 | TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) { |
| 10406 | m_errorMonitor->SetDesiredFailureMsg( |
| 10407 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10408 | "location 0 does not match VS input type"); |
| 10409 | |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10410 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10411 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10412 | |
| 10413 | VkVertexInputBindingDescription input_binding; |
| 10414 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10415 | |
| 10416 | VkVertexInputAttributeDescription input_attrib; |
| 10417 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10418 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10419 | |
| 10420 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10421 | "#version 450\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10422 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10423 | "layout(location=0) in int x;\n" /* attrib provided float */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10424 | "out gl_PerVertex {\n" |
| 10425 | " vec4 gl_Position;\n" |
| 10426 | "};\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10427 | "void main(){\n" |
| 10428 | " gl_Position = vec4(x);\n" |
| 10429 | "}\n"; |
| 10430 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10431 | "#version 450\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10432 | "\n" |
| 10433 | "layout(location=0) out vec4 color;\n" |
| 10434 | "void main(){\n" |
| 10435 | " color = vec4(1);\n" |
| 10436 | "}\n"; |
| 10437 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10438 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10439 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10440 | |
| 10441 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10442 | pipe.AddColorAttachment(); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10443 | pipe.AddShader(&vs); |
| 10444 | pipe.AddShader(&fs); |
| 10445 | |
| 10446 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10447 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10448 | |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10449 | VkDescriptorSetObj descriptorSet(m_device); |
| 10450 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10451 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10452 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10453 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10454 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10455 | m_errorMonitor->VerifyFound(); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10456 | } |
| 10457 | |
Chris Forbes | c68b43c | 2016-04-06 11:18:47 +1200 | [diff] [blame] | 10458 | TEST_F(VkLayerTest, CreatePipelineDuplicateStage) { |
| 10459 | m_errorMonitor->SetDesiredFailureMsg( |
| 10460 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10461 | "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT"); |
| 10462 | |
| 10463 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10464 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10465 | |
| 10466 | char const *vsSource = |
| 10467 | "#version 450\n" |
| 10468 | "\n" |
| 10469 | "out gl_PerVertex {\n" |
| 10470 | " vec4 gl_Position;\n" |
| 10471 | "};\n" |
| 10472 | "void main(){\n" |
| 10473 | " gl_Position = vec4(1);\n" |
| 10474 | "}\n"; |
| 10475 | char const *fsSource = |
| 10476 | "#version 450\n" |
| 10477 | "\n" |
| 10478 | "layout(location=0) out vec4 color;\n" |
| 10479 | "void main(){\n" |
| 10480 | " color = vec4(1);\n" |
| 10481 | "}\n"; |
| 10482 | |
| 10483 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10484 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10485 | |
| 10486 | VkPipelineObj pipe(m_device); |
| 10487 | pipe.AddColorAttachment(); |
| 10488 | pipe.AddShader(&vs); |
| 10489 | pipe.AddShader(&vs); |
| 10490 | pipe.AddShader(&fs); |
| 10491 | |
| 10492 | VkDescriptorSetObj descriptorSet(m_device); |
| 10493 | descriptorSet.AppendDummy(); |
| 10494 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10495 | |
| 10496 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10497 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10498 | m_errorMonitor->VerifyFound(); |
Chris Forbes | c68b43c | 2016-04-06 11:18:47 +1200 | [diff] [blame] | 10499 | } |
| 10500 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10501 | TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10502 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10503 | |
| 10504 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10505 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10506 | |
| 10507 | VkVertexInputBindingDescription input_binding; |
| 10508 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10509 | |
| 10510 | VkVertexInputAttributeDescription input_attribs[2]; |
| 10511 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 10512 | |
| 10513 | for (int i = 0; i < 2; i++) { |
| 10514 | input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 10515 | input_attribs[i].location = i; |
| 10516 | } |
| 10517 | |
| 10518 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10519 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10520 | "\n" |
| 10521 | "layout(location=0) in mat2x4 x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10522 | "out gl_PerVertex {\n" |
| 10523 | " vec4 gl_Position;\n" |
| 10524 | "};\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10525 | "void main(){\n" |
| 10526 | " gl_Position = x[0] + x[1];\n" |
| 10527 | "}\n"; |
| 10528 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10529 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10530 | "\n" |
| 10531 | "layout(location=0) out vec4 color;\n" |
| 10532 | "void main(){\n" |
| 10533 | " color = vec4(1);\n" |
| 10534 | "}\n"; |
| 10535 | |
| 10536 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10537 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10538 | |
| 10539 | VkPipelineObj pipe(m_device); |
| 10540 | pipe.AddColorAttachment(); |
| 10541 | pipe.AddShader(&vs); |
| 10542 | pipe.AddShader(&fs); |
| 10543 | |
| 10544 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10545 | pipe.AddVertexInputAttribs(input_attribs, 2); |
| 10546 | |
| 10547 | VkDescriptorSetObj descriptorSet(m_device); |
| 10548 | descriptorSet.AppendDummy(); |
| 10549 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10550 | |
| 10551 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10552 | |
| 10553 | /* expect success */ |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10554 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10555 | } |
| 10556 | |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10557 | TEST_F(VkLayerTest, CreatePipelineAttribArrayType) |
| 10558 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10559 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10560 | |
| 10561 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10562 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10563 | |
| 10564 | VkVertexInputBindingDescription input_binding; |
| 10565 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10566 | |
| 10567 | VkVertexInputAttributeDescription input_attribs[2]; |
| 10568 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 10569 | |
| 10570 | for (int i = 0; i < 2; i++) { |
| 10571 | input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 10572 | input_attribs[i].location = i; |
| 10573 | } |
| 10574 | |
| 10575 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10576 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10577 | "\n" |
| 10578 | "layout(location=0) in vec4 x[2];\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10579 | "out gl_PerVertex {\n" |
| 10580 | " vec4 gl_Position;\n" |
| 10581 | "};\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10582 | "void main(){\n" |
| 10583 | " gl_Position = x[0] + x[1];\n" |
| 10584 | "}\n"; |
| 10585 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10586 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10587 | "\n" |
| 10588 | "layout(location=0) out vec4 color;\n" |
| 10589 | "void main(){\n" |
| 10590 | " color = vec4(1);\n" |
| 10591 | "}\n"; |
| 10592 | |
| 10593 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10594 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10595 | |
| 10596 | VkPipelineObj pipe(m_device); |
| 10597 | pipe.AddColorAttachment(); |
| 10598 | pipe.AddShader(&vs); |
| 10599 | pipe.AddShader(&fs); |
| 10600 | |
| 10601 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10602 | pipe.AddVertexInputAttribs(input_attribs, 2); |
| 10603 | |
| 10604 | VkDescriptorSetObj descriptorSet(m_device); |
| 10605 | descriptorSet.AppendDummy(); |
| 10606 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10607 | |
| 10608 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10609 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10610 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10611 | } |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10612 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10613 | TEST_F(VkLayerTest, CreatePipelineSimplePositive) |
| 10614 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10615 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10616 | |
| 10617 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10618 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10619 | |
| 10620 | char const *vsSource = |
| 10621 | "#version 450\n" |
| 10622 | "out gl_PerVertex {\n" |
| 10623 | " vec4 gl_Position;\n" |
| 10624 | "};\n" |
| 10625 | "void main(){\n" |
| 10626 | " gl_Position = vec4(0);\n" |
| 10627 | "}\n"; |
| 10628 | char const *fsSource = |
| 10629 | "#version 450\n" |
| 10630 | "\n" |
| 10631 | "layout(location=0) out vec4 color;\n" |
| 10632 | "void main(){\n" |
| 10633 | " color = vec4(1);\n" |
| 10634 | "}\n"; |
| 10635 | |
| 10636 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10637 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10638 | |
| 10639 | VkPipelineObj pipe(m_device); |
| 10640 | pipe.AddColorAttachment(); |
| 10641 | pipe.AddShader(&vs); |
| 10642 | pipe.AddShader(&fs); |
| 10643 | |
| 10644 | VkDescriptorSetObj descriptorSet(m_device); |
| 10645 | descriptorSet.AppendDummy(); |
| 10646 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10647 | |
| 10648 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10649 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10650 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10651 | } |
| 10652 | |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 10653 | TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch) |
| 10654 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10655 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 10656 | |
| 10657 | // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block |
| 10658 | |
| 10659 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10660 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10661 | |
| 10662 | char const *vsSource = |
| 10663 | "#version 450\n" |
| 10664 | "out gl_PerVertex {\n" |
| 10665 | " vec4 gl_Position;\n" |
| 10666 | "};\n" |
| 10667 | "layout(location=0) out vec3 x;\n" |
| 10668 | "layout(location=1) out ivec3 y;\n" |
| 10669 | "layout(location=2) out vec3 z;\n" |
| 10670 | "void main(){\n" |
| 10671 | " gl_Position = vec4(0);\n" |
| 10672 | " x = vec3(0); y = ivec3(0); z = vec3(0);\n" |
| 10673 | "}\n"; |
| 10674 | char const *fsSource = |
| 10675 | "#version 450\n" |
| 10676 | "\n" |
| 10677 | "layout(location=0) out vec4 color;\n" |
| 10678 | "layout(location=0) in float x;\n" |
| 10679 | "layout(location=1) flat in int y;\n" |
| 10680 | "layout(location=2) in vec2 z;\n" |
| 10681 | "void main(){\n" |
| 10682 | " color = vec4(1 + x + y + z.x);\n" |
| 10683 | "}\n"; |
| 10684 | |
| 10685 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10686 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10687 | |
| 10688 | VkPipelineObj pipe(m_device); |
| 10689 | pipe.AddColorAttachment(); |
| 10690 | pipe.AddShader(&vs); |
| 10691 | pipe.AddShader(&fs); |
| 10692 | |
| 10693 | VkDescriptorSetObj descriptorSet(m_device); |
| 10694 | descriptorSet.AppendDummy(); |
| 10695 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10696 | |
| 10697 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10698 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10699 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 10700 | } |
| 10701 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10702 | TEST_F(VkLayerTest, CreatePipelineTessPerVertex) |
| 10703 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10704 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10705 | |
| 10706 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10707 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10708 | |
Chris Forbes | c1e852d | 2016-04-04 19:26:42 +1200 | [diff] [blame] | 10709 | if (!m_device->phy().features().tessellationShader) { |
| 10710 | printf("Device does not support tessellation shaders; skipped.\n"); |
| 10711 | return; |
| 10712 | } |
| 10713 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10714 | char const *vsSource = |
| 10715 | "#version 450\n" |
| 10716 | "void main(){}\n"; |
| 10717 | char const *tcsSource = |
| 10718 | "#version 450\n" |
| 10719 | "layout(location=0) out int x[];\n" |
| 10720 | "layout(vertices=3) out;\n" |
| 10721 | "void main(){\n" |
| 10722 | " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n" |
| 10723 | " gl_TessLevelInner[0] = 1;\n" |
| 10724 | " x[gl_InvocationID] = gl_InvocationID;\n" |
| 10725 | "}\n"; |
| 10726 | char const *tesSource = |
| 10727 | "#version 450\n" |
| 10728 | "layout(triangles, equal_spacing, cw) in;\n" |
| 10729 | "layout(location=0) in int x[];\n" |
| 10730 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 10731 | "void main(){\n" |
| 10732 | " gl_Position.xyz = gl_TessCoord;\n" |
| 10733 | " gl_Position.w = x[0] + x[1] + x[2];\n" |
| 10734 | "}\n"; |
| 10735 | char const *fsSource = |
| 10736 | "#version 450\n" |
| 10737 | "layout(location=0) out vec4 color;\n" |
| 10738 | "void main(){\n" |
| 10739 | " color = vec4(1);\n" |
| 10740 | "}\n"; |
| 10741 | |
| 10742 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10743 | VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this); |
| 10744 | VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this); |
| 10745 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10746 | |
| 10747 | VkPipelineInputAssemblyStateCreateInfo iasci{ |
| 10748 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, |
| 10749 | nullptr, |
| 10750 | 0, |
| 10751 | VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, |
| 10752 | VK_FALSE}; |
| 10753 | |
Chris Forbes | b4cacb6 | 2016-04-04 19:15:00 +1200 | [diff] [blame] | 10754 | VkPipelineTessellationStateCreateInfo tsci{ |
| 10755 | VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, |
| 10756 | nullptr, |
| 10757 | 0, |
| 10758 | 3}; |
| 10759 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10760 | VkPipelineObj pipe(m_device); |
| 10761 | pipe.SetInputAssembly(&iasci); |
Chris Forbes | b4cacb6 | 2016-04-04 19:15:00 +1200 | [diff] [blame] | 10762 | pipe.SetTessellation(&tsci); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10763 | pipe.AddColorAttachment(); |
| 10764 | pipe.AddShader(&vs); |
| 10765 | pipe.AddShader(&tcs); |
| 10766 | pipe.AddShader(&tes); |
| 10767 | pipe.AddShader(&fs); |
| 10768 | |
| 10769 | VkDescriptorSetObj descriptorSet(m_device); |
| 10770 | descriptorSet.AppendDummy(); |
| 10771 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10772 | |
| 10773 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10774 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10775 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10776 | } |
| 10777 | |
Chris Forbes | a0ab815 | 2016-04-20 13:34:27 +1200 | [diff] [blame] | 10778 | TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive) |
| 10779 | { |
| 10780 | m_errorMonitor->ExpectSuccess(); |
| 10781 | |
| 10782 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10783 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10784 | |
| 10785 | if (!m_device->phy().features().geometryShader) { |
| 10786 | printf("Device does not support geometry shaders; skipped.\n"); |
| 10787 | return; |
| 10788 | } |
| 10789 | |
| 10790 | char const *vsSource = |
| 10791 | "#version 450\n" |
| 10792 | "layout(location=0) out VertexData { vec4 x; } vs_out;\n" |
| 10793 | "void main(){\n" |
| 10794 | " vs_out.x = vec4(1);\n" |
| 10795 | "}\n"; |
| 10796 | char const *gsSource = |
| 10797 | "#version 450\n" |
| 10798 | "layout(triangles) in;\n" |
| 10799 | "layout(triangle_strip, max_vertices=3) out;\n" |
| 10800 | "layout(location=0) in VertexData { vec4 x; } gs_in[];\n" |
| 10801 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 10802 | "void main() {\n" |
| 10803 | " gl_Position = gs_in[0].x;\n" |
| 10804 | " EmitVertex();\n" |
| 10805 | "}\n"; |
| 10806 | char const *fsSource = |
| 10807 | "#version 450\n" |
| 10808 | "layout(location=0) out vec4 color;\n" |
| 10809 | "void main(){\n" |
| 10810 | " color = vec4(1);\n" |
| 10811 | "}\n"; |
| 10812 | |
| 10813 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10814 | VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this); |
| 10815 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10816 | |
| 10817 | VkPipelineObj pipe(m_device); |
| 10818 | pipe.AddColorAttachment(); |
| 10819 | pipe.AddShader(&vs); |
| 10820 | pipe.AddShader(&gs); |
| 10821 | pipe.AddShader(&fs); |
| 10822 | |
| 10823 | VkDescriptorSetObj descriptorSet(m_device); |
| 10824 | descriptorSet.AppendDummy(); |
| 10825 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10826 | |
| 10827 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10828 | |
| 10829 | m_errorMonitor->VerifyNotFound(); |
| 10830 | } |
| 10831 | |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 10832 | TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) |
| 10833 | { |
| 10834 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10835 | "is per-vertex in tessellation control shader stage " |
| 10836 | "but per-patch in tessellation evaluation shader stage"); |
| 10837 | |
| 10838 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10839 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10840 | |
Chris Forbes | c1e852d | 2016-04-04 19:26:42 +1200 | [diff] [blame] | 10841 | if (!m_device->phy().features().tessellationShader) { |
| 10842 | printf("Device does not support tessellation shaders; skipped.\n"); |
| 10843 | return; |
| 10844 | } |
| 10845 | |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 10846 | char const *vsSource = |
| 10847 | "#version 450\n" |
| 10848 | "void main(){}\n"; |
| 10849 | char const *tcsSource = |
| 10850 | "#version 450\n" |
| 10851 | "layout(location=0) out int x[];\n" |
| 10852 | "layout(vertices=3) out;\n" |
| 10853 | "void main(){\n" |
| 10854 | " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n" |
| 10855 | " gl_TessLevelInner[0] = 1;\n" |
| 10856 | " x[gl_InvocationID] = gl_InvocationID;\n" |
| 10857 | "}\n"; |
| 10858 | char const *tesSource = |
| 10859 | "#version 450\n" |
| 10860 | "layout(triangles, equal_spacing, cw) in;\n" |
| 10861 | "layout(location=0) patch in int x;\n" |
| 10862 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 10863 | "void main(){\n" |
| 10864 | " gl_Position.xyz = gl_TessCoord;\n" |
| 10865 | " gl_Position.w = x;\n" |
| 10866 | "}\n"; |
| 10867 | char const *fsSource = |
| 10868 | "#version 450\n" |
| 10869 | "layout(location=0) out vec4 color;\n" |
| 10870 | "void main(){\n" |
| 10871 | " color = vec4(1);\n" |
| 10872 | "}\n"; |
| 10873 | |
| 10874 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10875 | VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this); |
| 10876 | VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this); |
| 10877 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10878 | |
| 10879 | VkPipelineInputAssemblyStateCreateInfo iasci{ |
| 10880 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, |
| 10881 | nullptr, |
| 10882 | 0, |
| 10883 | VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, |
| 10884 | VK_FALSE}; |
| 10885 | |
| 10886 | VkPipelineTessellationStateCreateInfo tsci{ |
| 10887 | VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, |
| 10888 | nullptr, |
| 10889 | 0, |
| 10890 | 3}; |
| 10891 | |
| 10892 | VkPipelineObj pipe(m_device); |
| 10893 | pipe.SetInputAssembly(&iasci); |
| 10894 | pipe.SetTessellation(&tsci); |
| 10895 | pipe.AddColorAttachment(); |
| 10896 | pipe.AddShader(&vs); |
| 10897 | pipe.AddShader(&tcs); |
| 10898 | pipe.AddShader(&tes); |
| 10899 | pipe.AddShader(&fs); |
| 10900 | |
| 10901 | VkDescriptorSetObj descriptorSet(m_device); |
| 10902 | descriptorSet.AppendDummy(); |
| 10903 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10904 | |
| 10905 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10906 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10907 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 10908 | } |
| 10909 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10910 | TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) { |
| 10911 | m_errorMonitor->SetDesiredFailureMsg( |
| 10912 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10913 | "Duplicate vertex input binding descriptions for binding 0"); |
| 10914 | |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10915 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10916 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10917 | |
| 10918 | /* Two binding descriptions for binding 0 */ |
| 10919 | VkVertexInputBindingDescription input_bindings[2]; |
| 10920 | memset(input_bindings, 0, sizeof(input_bindings)); |
| 10921 | |
| 10922 | VkVertexInputAttributeDescription input_attrib; |
| 10923 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10924 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10925 | |
| 10926 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10927 | "#version 450\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10928 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10929 | "layout(location=0) in float x;\n" /* attrib provided float */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10930 | "out gl_PerVertex {\n" |
| 10931 | " vec4 gl_Position;\n" |
| 10932 | "};\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10933 | "void main(){\n" |
| 10934 | " gl_Position = vec4(x);\n" |
| 10935 | "}\n"; |
| 10936 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10937 | "#version 450\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10938 | "\n" |
| 10939 | "layout(location=0) out vec4 color;\n" |
| 10940 | "void main(){\n" |
| 10941 | " color = vec4(1);\n" |
| 10942 | "}\n"; |
| 10943 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10944 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10945 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10946 | |
| 10947 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10948 | pipe.AddColorAttachment(); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10949 | pipe.AddShader(&vs); |
| 10950 | pipe.AddShader(&fs); |
| 10951 | |
| 10952 | pipe.AddVertexInputBindings(input_bindings, 2); |
| 10953 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10954 | |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10955 | VkDescriptorSetObj descriptorSet(m_device); |
| 10956 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10957 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10958 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10959 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10960 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10961 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10962 | } |
Chris Forbes | 8f68b56 | 2015-05-25 11:13:32 +1200 | [diff] [blame] | 10963 | |
Chris Forbes | 35efec7 | 2016-04-21 14:32:08 +1200 | [diff] [blame] | 10964 | TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) { |
| 10965 | m_errorMonitor->ExpectSuccess(); |
| 10966 | |
| 10967 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10968 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10969 | |
| 10970 | if (!m_device->phy().features().tessellationShader) { |
| 10971 | printf("Device does not support 64bit vertex attributes; skipped.\n"); |
| 10972 | return; |
| 10973 | } |
| 10974 | |
| 10975 | VkVertexInputBindingDescription input_bindings[1]; |
| 10976 | memset(input_bindings, 0, sizeof(input_bindings)); |
| 10977 | |
| 10978 | VkVertexInputAttributeDescription input_attribs[4]; |
| 10979 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 10980 | input_attribs[0].location = 0; |
| 10981 | input_attribs[0].offset = 0; |
| 10982 | input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 10983 | input_attribs[1].location = 2; |
| 10984 | input_attribs[1].offset = 32; |
| 10985 | input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 10986 | input_attribs[2].location = 4; |
| 10987 | input_attribs[2].offset = 64; |
| 10988 | input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 10989 | input_attribs[3].location = 6; |
| 10990 | input_attribs[3].offset = 96; |
| 10991 | input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 10992 | |
| 10993 | char const *vsSource = |
| 10994 | "#version 450\n" |
| 10995 | "\n" |
| 10996 | "layout(location=0) in dmat4 x;\n" |
| 10997 | "out gl_PerVertex {\n" |
| 10998 | " vec4 gl_Position;\n" |
| 10999 | "};\n" |
| 11000 | "void main(){\n" |
| 11001 | " gl_Position = vec4(x[0][0]);\n" |
| 11002 | "}\n"; |
| 11003 | char const *fsSource = |
| 11004 | "#version 450\n" |
| 11005 | "\n" |
| 11006 | "layout(location=0) out vec4 color;\n" |
| 11007 | "void main(){\n" |
| 11008 | " color = vec4(1);\n" |
| 11009 | "}\n"; |
| 11010 | |
| 11011 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11012 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11013 | |
| 11014 | VkPipelineObj pipe(m_device); |
| 11015 | pipe.AddColorAttachment(); |
| 11016 | pipe.AddShader(&vs); |
| 11017 | pipe.AddShader(&fs); |
| 11018 | |
| 11019 | pipe.AddVertexInputBindings(input_bindings, 1); |
| 11020 | pipe.AddVertexInputAttribs(input_attribs, 4); |
| 11021 | |
| 11022 | VkDescriptorSetObj descriptorSet(m_device); |
| 11023 | descriptorSet.AppendDummy(); |
| 11024 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11025 | |
| 11026 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11027 | |
| 11028 | m_errorMonitor->VerifyNotFound(); |
| 11029 | } |
| 11030 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11031 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11032 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11033 | "Attachment 0 not written by FS"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11034 | |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11035 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11036 | |
| 11037 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11038 | "#version 450\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11039 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11040 | "out gl_PerVertex {\n" |
| 11041 | " vec4 gl_Position;\n" |
| 11042 | "};\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11043 | "void main(){\n" |
| 11044 | " gl_Position = vec4(1);\n" |
| 11045 | "}\n"; |
| 11046 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11047 | "#version 450\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11048 | "\n" |
| 11049 | "void main(){\n" |
| 11050 | "}\n"; |
| 11051 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11052 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11053 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11054 | |
| 11055 | VkPipelineObj pipe(m_device); |
| 11056 | pipe.AddShader(&vs); |
| 11057 | pipe.AddShader(&fs); |
| 11058 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11059 | /* set up CB 0, not written */ |
| 11060 | pipe.AddColorAttachment(); |
| 11061 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11062 | |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11063 | VkDescriptorSetObj descriptorSet(m_device); |
| 11064 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11065 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11066 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11067 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11068 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11069 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11070 | } |
| 11071 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11072 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11073 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 11074 | VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11075 | "FS writes to output location 1 with no matching attachment"); |
| 11076 | |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11077 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11078 | |
| 11079 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11080 | "#version 450\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11081 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11082 | "out gl_PerVertex {\n" |
| 11083 | " vec4 gl_Position;\n" |
| 11084 | "};\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11085 | "void main(){\n" |
| 11086 | " gl_Position = vec4(1);\n" |
| 11087 | "}\n"; |
| 11088 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11089 | "#version 450\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11090 | "\n" |
| 11091 | "layout(location=0) out vec4 x;\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11092 | "layout(location=1) out vec4 y;\n" /* no matching attachment for this */ |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11093 | "void main(){\n" |
| 11094 | " x = vec4(1);\n" |
| 11095 | " y = vec4(1);\n" |
| 11096 | "}\n"; |
| 11097 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11098 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11099 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11100 | |
| 11101 | VkPipelineObj pipe(m_device); |
| 11102 | pipe.AddShader(&vs); |
| 11103 | pipe.AddShader(&fs); |
| 11104 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11105 | /* set up CB 0, not written */ |
| 11106 | pipe.AddColorAttachment(); |
| 11107 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11108 | /* FS writes CB 1, but we don't configure it */ |
| 11109 | |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11110 | VkDescriptorSetObj descriptorSet(m_device); |
| 11111 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11112 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11113 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11114 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11115 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11116 | m_errorMonitor->VerifyFound(); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11117 | } |
| 11118 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11119 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11120 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11121 | "does not match FS output type"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11122 | |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11123 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11124 | |
| 11125 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11126 | "#version 450\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11127 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11128 | "out gl_PerVertex {\n" |
| 11129 | " vec4 gl_Position;\n" |
| 11130 | "};\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11131 | "void main(){\n" |
| 11132 | " gl_Position = vec4(1);\n" |
| 11133 | "}\n"; |
| 11134 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11135 | "#version 450\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11136 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11137 | "layout(location=0) out ivec4 x;\n" /* not UNORM */ |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11138 | "void main(){\n" |
| 11139 | " x = ivec4(1);\n" |
| 11140 | "}\n"; |
| 11141 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11142 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11143 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11144 | |
| 11145 | VkPipelineObj pipe(m_device); |
| 11146 | pipe.AddShader(&vs); |
| 11147 | pipe.AddShader(&fs); |
| 11148 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11149 | /* set up CB 0; type is UNORM by default */ |
| 11150 | pipe.AddColorAttachment(); |
| 11151 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11152 | |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11153 | VkDescriptorSetObj descriptorSet(m_device); |
| 11154 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11155 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11156 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11157 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11158 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11159 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11160 | } |
Chris Forbes | 7b1b893 | 2015-06-05 14:43:36 +1200 | [diff] [blame] | 11161 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11162 | TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11163 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11164 | "not declared in pipeline layout"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11165 | |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11166 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11167 | |
| 11168 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11169 | "#version 450\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11170 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11171 | "out gl_PerVertex {\n" |
| 11172 | " vec4 gl_Position;\n" |
| 11173 | "};\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11174 | "void main(){\n" |
| 11175 | " gl_Position = vec4(1);\n" |
| 11176 | "}\n"; |
| 11177 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11178 | "#version 450\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11179 | "\n" |
| 11180 | "layout(location=0) out vec4 x;\n" |
| 11181 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 11182 | "void main(){\n" |
| 11183 | " x = vec4(bar.y);\n" |
| 11184 | "}\n"; |
| 11185 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11186 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11187 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11188 | |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11189 | VkPipelineObj pipe(m_device); |
| 11190 | pipe.AddShader(&vs); |
| 11191 | pipe.AddShader(&fs); |
| 11192 | |
| 11193 | /* set up CB 0; type is UNORM by default */ |
| 11194 | pipe.AddColorAttachment(); |
| 11195 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11196 | |
| 11197 | VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11198 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11199 | |
| 11200 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11201 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11202 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11203 | } |
| 11204 | |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11205 | TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) { |
| 11206 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11207 | "not declared in layout"); |
| 11208 | |
| 11209 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11210 | |
| 11211 | char const *vsSource = |
| 11212 | "#version 450\n" |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11213 | "\n" |
| 11214 | "layout(push_constant, std430) uniform foo { float x; } consts;\n" |
| 11215 | "out gl_PerVertex {\n" |
| 11216 | " vec4 gl_Position;\n" |
| 11217 | "};\n" |
| 11218 | "void main(){\n" |
| 11219 | " gl_Position = vec4(consts.x);\n" |
| 11220 | "}\n"; |
| 11221 | char const *fsSource = |
| 11222 | "#version 450\n" |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11223 | "\n" |
| 11224 | "layout(location=0) out vec4 x;\n" |
| 11225 | "void main(){\n" |
| 11226 | " x = vec4(1);\n" |
| 11227 | "}\n"; |
| 11228 | |
| 11229 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11230 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11231 | |
| 11232 | VkPipelineObj pipe(m_device); |
| 11233 | pipe.AddShader(&vs); |
| 11234 | pipe.AddShader(&fs); |
| 11235 | |
| 11236 | /* set up CB 0; type is UNORM by default */ |
| 11237 | pipe.AddColorAttachment(); |
| 11238 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11239 | |
| 11240 | VkDescriptorSetObj descriptorSet(m_device); |
| 11241 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11242 | |
| 11243 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11244 | |
| 11245 | /* should have generated an error -- no push constant ranges provided! */ |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11246 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11247 | } |
| 11248 | |
Chris Forbes | 10eb9ae | 2016-05-31 16:09:42 +1200 | [diff] [blame] | 11249 | TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) { |
| 11250 | m_errorMonitor->SetDesiredFailureMsg( |
| 11251 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11252 | "Shader uses descriptor slot 0.0"); |
| 11253 | |
| 11254 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11255 | |
| 11256 | char const *csSource = |
| 11257 | "#version 450\n" |
| 11258 | "\n" |
| 11259 | "layout(local_size_x=1) in;\n" |
| 11260 | "layout(set=0, binding=0) buffer block { vec4 x; };\n" |
| 11261 | "void main(){\n" |
| 11262 | " x = vec4(1);\n" |
| 11263 | "}\n"; |
| 11264 | |
| 11265 | VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this); |
| 11266 | |
| 11267 | VkDescriptorSetObj descriptorSet(m_device); |
| 11268 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11269 | |
| 11270 | VkComputePipelineCreateInfo cpci = { |
| 11271 | VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, |
| 11272 | nullptr, 0, { |
| 11273 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 11274 | nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, |
| 11275 | cs.handle(), "main", nullptr |
| 11276 | }, |
| 11277 | descriptorSet.GetPipelineLayout(), |
| 11278 | VK_NULL_HANDLE, -1 |
| 11279 | }; |
| 11280 | |
| 11281 | VkPipeline pipe; |
| 11282 | VkResult err = vkCreateComputePipelines( |
| 11283 | m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe); |
| 11284 | |
| 11285 | m_errorMonitor->VerifyFound(); |
| 11286 | |
| 11287 | if (err == VK_SUCCESS) { |
| 11288 | vkDestroyPipeline(m_device->device(), pipe, nullptr); |
| 11289 | } |
| 11290 | } |
| 11291 | |
| 11292 | TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) { |
| 11293 | m_errorMonitor->ExpectSuccess(); |
| 11294 | |
| 11295 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11296 | |
| 11297 | char const *csSource = |
| 11298 | "#version 450\n" |
| 11299 | "\n" |
| 11300 | "layout(local_size_x=1) in;\n" |
| 11301 | "layout(set=0, binding=0) buffer block { vec4 x; };\n" |
| 11302 | "void main(){\n" |
| 11303 | " // x is not used.\n" |
| 11304 | "}\n"; |
| 11305 | |
| 11306 | VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this); |
| 11307 | |
| 11308 | VkDescriptorSetObj descriptorSet(m_device); |
| 11309 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11310 | |
| 11311 | VkComputePipelineCreateInfo cpci = { |
| 11312 | VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, |
| 11313 | nullptr, 0, { |
| 11314 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 11315 | nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, |
| 11316 | cs.handle(), "main", nullptr |
| 11317 | }, |
| 11318 | descriptorSet.GetPipelineLayout(), |
| 11319 | VK_NULL_HANDLE, -1 |
| 11320 | }; |
| 11321 | |
| 11322 | VkPipeline pipe; |
| 11323 | VkResult err = vkCreateComputePipelines( |
| 11324 | m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe); |
| 11325 | |
| 11326 | m_errorMonitor->VerifyNotFound(); |
| 11327 | |
| 11328 | if (err == VK_SUCCESS) { |
| 11329 | vkDestroyPipeline(m_device->device(), pipe, nullptr); |
| 11330 | } |
| 11331 | } |
| 11332 | |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 11333 | #endif // SHADER_CHECKER_TESTS |
| 11334 | |
| 11335 | #if DEVICE_LIMITS_TESTS |
Mark Young | c48c4c1 | 2016-04-11 14:26:49 -0600 | [diff] [blame] | 11336 | TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11337 | m_errorMonitor->SetDesiredFailureMsg( |
| 11338 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11339 | "CreateImage extents exceed allowable limits for format"); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11340 | |
| 11341 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11342 | |
| 11343 | // Create an image |
| 11344 | VkImage image; |
| 11345 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11346 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11347 | const int32_t tex_width = 32; |
| 11348 | const int32_t tex_height = 32; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11349 | |
| 11350 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11351 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11352 | image_create_info.pNext = NULL; |
| 11353 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11354 | image_create_info.format = tex_format; |
| 11355 | image_create_info.extent.width = tex_width; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11356 | image_create_info.extent.height = tex_height; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11357 | image_create_info.extent.depth = 1; |
| 11358 | image_create_info.mipLevels = 1; |
| 11359 | image_create_info.arrayLayers = 1; |
| 11360 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11361 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11362 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 11363 | image_create_info.flags = 0; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11364 | |
| 11365 | // Introduce error by sending down a bogus width extent |
| 11366 | image_create_info.extent.width = 65536; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11367 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11368 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11369 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11370 | } |
| 11371 | |
Mark Young | c48c4c1 | 2016-04-11 14:26:49 -0600 | [diff] [blame] | 11372 | TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) { |
| 11373 | m_errorMonitor->SetDesiredFailureMsg( |
| 11374 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11375 | "CreateImage extents is 0 for at least one required dimension"); |
| 11376 | |
| 11377 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11378 | |
| 11379 | // Create an image |
| 11380 | VkImage image; |
| 11381 | |
| 11382 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11383 | const int32_t tex_width = 32; |
| 11384 | const int32_t tex_height = 32; |
| 11385 | |
| 11386 | VkImageCreateInfo image_create_info = {}; |
| 11387 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11388 | image_create_info.pNext = NULL; |
| 11389 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11390 | image_create_info.format = tex_format; |
| 11391 | image_create_info.extent.width = tex_width; |
| 11392 | image_create_info.extent.height = tex_height; |
| 11393 | image_create_info.extent.depth = 1; |
| 11394 | image_create_info.mipLevels = 1; |
| 11395 | image_create_info.arrayLayers = 1; |
| 11396 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11397 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11398 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 11399 | image_create_info.flags = 0; |
| 11400 | |
| 11401 | // Introduce error by sending down a bogus width extent |
| 11402 | image_create_info.extent.width = 0; |
| 11403 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 11404 | |
| 11405 | m_errorMonitor->VerifyFound(); |
| 11406 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 11407 | #endif // DEVICE_LIMITS_TESTS |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11408 | |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11409 | #if IMAGE_TESTS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11410 | TEST_F(VkLayerTest, InvalidImageView) { |
| 11411 | VkResult err; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11412 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11413 | m_errorMonitor->SetDesiredFailureMsg( |
| 11414 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11415 | "vkCreateImageView called with baseMipLevel 10 "); |
| 11416 | |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11417 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11418 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11419 | // Create an image and try to create a view with bad baseMipLevel |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11420 | VkImage image; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11421 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11422 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11423 | const int32_t tex_width = 32; |
| 11424 | const int32_t tex_height = 32; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11425 | |
| 11426 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11427 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11428 | image_create_info.pNext = NULL; |
| 11429 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11430 | image_create_info.format = tex_format; |
| 11431 | image_create_info.extent.width = tex_width; |
| 11432 | image_create_info.extent.height = tex_height; |
| 11433 | image_create_info.extent.depth = 1; |
| 11434 | image_create_info.mipLevels = 1; |
| 11435 | image_create_info.arrayLayers = 1; |
| 11436 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11437 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11438 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 11439 | image_create_info.flags = 0; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11440 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11441 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11442 | ASSERT_VK_SUCCESS(err); |
| 11443 | |
| 11444 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11445 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11446 | image_view_create_info.image = image; |
| 11447 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 11448 | image_view_create_info.format = tex_format; |
| 11449 | image_view_create_info.subresourceRange.layerCount = 1; |
| 11450 | image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error |
| 11451 | image_view_create_info.subresourceRange.levelCount = 1; |
| 11452 | image_view_create_info.subresourceRange.aspectMask = |
| 11453 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11454 | |
| 11455 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11456 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 11457 | &view); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11458 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11459 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 11460 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11461 | } |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11462 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11463 | TEST_F(VkLayerTest, InvalidImageViewAspect) { |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11464 | TEST_DESCRIPTION( |
| 11465 | "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] | 11466 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11467 | "vkCreateImageView: Color image " |
| 11468 | "formats must have ONLY the " |
| 11469 | "VK_IMAGE_ASPECT_COLOR_BIT set"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11470 | |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11471 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11472 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11473 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11474 | VkImageObj image(m_device); |
| 11475 | image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, |
| 11476 | VK_IMAGE_TILING_LINEAR, 0); |
| 11477 | ASSERT_TRUE(image.initialized()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11478 | |
| 11479 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11480 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11481 | image_view_create_info.image = image.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11482 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 11483 | image_view_create_info.format = tex_format; |
| 11484 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 11485 | image_view_create_info.subresourceRange.levelCount = 1; |
| 11486 | // Cause an error by setting an invalid image aspect |
| 11487 | image_view_create_info.subresourceRange.aspectMask = |
| 11488 | VK_IMAGE_ASPECT_METADATA_BIT; |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11489 | |
| 11490 | VkImageView view; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11491 | vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11492 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11493 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11494 | } |
| 11495 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11496 | TEST_F(VkLayerTest, CopyImageLayerCountMismatch) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11497 | VkResult err; |
| 11498 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11499 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11500 | m_errorMonitor->SetDesiredFailureMsg( |
| 11501 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11502 | "vkCmdCopyImage: number of layers in source and destination subresources for pRegions"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11503 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11504 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11505 | |
| 11506 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11507 | VkImage srcImage; |
| 11508 | VkImage dstImage; |
| 11509 | VkDeviceMemory srcMem; |
| 11510 | VkDeviceMemory destMem; |
| 11511 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11512 | |
| 11513 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11514 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11515 | image_create_info.pNext = NULL; |
| 11516 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11517 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11518 | image_create_info.extent.width = 32; |
| 11519 | image_create_info.extent.height = 32; |
| 11520 | image_create_info.extent.depth = 1; |
| 11521 | image_create_info.mipLevels = 1; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11522 | image_create_info.arrayLayers = 4; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11523 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11524 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 11525 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11526 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11527 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11528 | err = |
| 11529 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11530 | ASSERT_VK_SUCCESS(err); |
| 11531 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11532 | err = |
| 11533 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11534 | ASSERT_VK_SUCCESS(err); |
| 11535 | |
| 11536 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11537 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11538 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 11539 | memAlloc.pNext = NULL; |
| 11540 | memAlloc.allocationSize = 0; |
| 11541 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11542 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 11543 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11544 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11545 | pass = |
| 11546 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 11547 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11548 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11549 | ASSERT_VK_SUCCESS(err); |
| 11550 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11551 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11552 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11553 | pass = |
| 11554 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11555 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11556 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11557 | ASSERT_VK_SUCCESS(err); |
| 11558 | |
| 11559 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 11560 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11561 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11562 | ASSERT_VK_SUCCESS(err); |
| 11563 | |
| 11564 | BeginCommandBuffer(); |
| 11565 | VkImageCopy copyRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11566 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11567 | copyRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 11568 | copyRegion.srcSubresource.baseArrayLayer = 0; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11569 | copyRegion.srcSubresource.layerCount = 1; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11570 | copyRegion.srcOffset.x = 0; |
| 11571 | copyRegion.srcOffset.y = 0; |
| 11572 | copyRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11573 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11574 | copyRegion.dstSubresource.mipLevel = 0; |
| 11575 | copyRegion.dstSubresource.baseArrayLayer = 0; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11576 | // Introduce failure by forcing the dst layerCount to differ from src |
| 11577 | copyRegion.dstSubresource.layerCount = 3; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11578 | copyRegion.dstOffset.x = 0; |
| 11579 | copyRegion.dstOffset.y = 0; |
| 11580 | copyRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11581 | copyRegion.extent.width = 1; |
| 11582 | copyRegion.extent.height = 1; |
| 11583 | copyRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11584 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 11585 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11586 | EndCommandBuffer(); |
| 11587 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11588 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11589 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11590 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11591 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11592 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 11593 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11594 | } |
| 11595 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11596 | TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) { |
| 11597 | |
| 11598 | TEST_DESCRIPTION("Creating images with unsuported formats "); |
| 11599 | |
| 11600 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11601 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11602 | VkImageObj image(m_device); |
| 11603 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 11604 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 11605 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 11606 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 11607 | ASSERT_TRUE(image.initialized()); |
| 11608 | |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11609 | // Create image with unsupported format - Expect FORMAT_UNSUPPORTED |
| 11610 | VkImageCreateInfo image_create_info; |
| 11611 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11612 | image_create_info.pNext = NULL; |
| 11613 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11614 | image_create_info.format = VK_FORMAT_UNDEFINED; |
| 11615 | image_create_info.extent.width = 32; |
| 11616 | image_create_info.extent.height = 32; |
| 11617 | image_create_info.extent.depth = 1; |
| 11618 | image_create_info.mipLevels = 1; |
| 11619 | image_create_info.arrayLayers = 1; |
| 11620 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11621 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 11622 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11623 | image_create_info.flags = 0; |
| 11624 | |
| 11625 | m_errorMonitor->SetDesiredFailureMsg( |
| 11626 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11627 | "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED"); |
| 11628 | |
| 11629 | VkImage localImage; |
| 11630 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage); |
| 11631 | m_errorMonitor->VerifyFound(); |
| 11632 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11633 | VkFormat unsupported = VK_FORMAT_UNDEFINED; |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11634 | // Look for a format that is COMPLETELY unsupported with this hardware |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11635 | for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) { |
| 11636 | VkFormat format = static_cast<VkFormat>(f); |
| 11637 | VkFormatProperties fProps = m_device->format_properties(format); |
| 11638 | if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && |
| 11639 | fProps.optimalTilingFeatures == 0) { |
| 11640 | unsupported = format; |
| 11641 | break; |
| 11642 | } |
| 11643 | } |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11644 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11645 | if (unsupported != VK_FORMAT_UNDEFINED) { |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11646 | image_create_info.format = unsupported; |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11647 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11648 | "is an unsupported format"); |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11649 | |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11650 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage); |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11651 | m_errorMonitor->VerifyFound(); |
| 11652 | } |
| 11653 | } |
| 11654 | |
| 11655 | TEST_F(VkLayerTest, ImageLayerViewTests) { |
| 11656 | VkResult ret; |
| 11657 | TEST_DESCRIPTION("Passing bad parameters to CreateImageView"); |
| 11658 | |
| 11659 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11660 | |
| 11661 | VkImageObj image(m_device); |
| 11662 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 11663 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 11664 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 11665 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 11666 | ASSERT_TRUE(image.initialized()); |
| 11667 | |
| 11668 | VkImageView imgView; |
| 11669 | VkImageViewCreateInfo imgViewInfo = {}; |
| 11670 | imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 11671 | imgViewInfo.image = image.handle(); |
| 11672 | imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 11673 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11674 | imgViewInfo.subresourceRange.layerCount = 1; |
| 11675 | imgViewInfo.subresourceRange.baseMipLevel = 0; |
| 11676 | imgViewInfo.subresourceRange.levelCount = 1; |
| 11677 | imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11678 | |
| 11679 | m_errorMonitor->SetDesiredFailureMsg( |
| 11680 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11681 | "vkCreateImageView called with baseMipLevel"); |
| 11682 | // View can't have baseMipLevel >= image's mipLevels - Expect |
| 11683 | // VIEW_CREATE_ERROR |
| 11684 | imgViewInfo.subresourceRange.baseMipLevel = 1; |
| 11685 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11686 | m_errorMonitor->VerifyFound(); |
| 11687 | imgViewInfo.subresourceRange.baseMipLevel = 0; |
| 11688 | |
| 11689 | m_errorMonitor->SetDesiredFailureMsg( |
| 11690 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11691 | "vkCreateImageView called with baseArrayLayer"); |
| 11692 | // View can't have baseArrayLayer >= image's arraySize - Expect |
| 11693 | // VIEW_CREATE_ERROR |
| 11694 | imgViewInfo.subresourceRange.baseArrayLayer = 1; |
| 11695 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11696 | m_errorMonitor->VerifyFound(); |
| 11697 | imgViewInfo.subresourceRange.baseArrayLayer = 0; |
| 11698 | |
| 11699 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11700 | "vkCreateImageView called with 0 in " |
| 11701 | "pCreateInfo->subresourceRange." |
| 11702 | "levelCount"); |
| 11703 | // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR |
| 11704 | imgViewInfo.subresourceRange.levelCount = 0; |
| 11705 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11706 | m_errorMonitor->VerifyFound(); |
| 11707 | imgViewInfo.subresourceRange.levelCount = 1; |
| 11708 | |
| 11709 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11710 | "vkCreateImageView called with 0 in " |
| 11711 | "pCreateInfo->subresourceRange." |
| 11712 | "layerCount"); |
| 11713 | // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR |
| 11714 | imgViewInfo.subresourceRange.layerCount = 0; |
| 11715 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11716 | m_errorMonitor->VerifyFound(); |
| 11717 | imgViewInfo.subresourceRange.layerCount = 1; |
| 11718 | |
| 11719 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11720 | "but both must be color formats"); |
| 11721 | // Can't use depth format for view into color image - Expect INVALID_FORMAT |
| 11722 | imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 11723 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11724 | m_errorMonitor->VerifyFound(); |
| 11725 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11726 | |
| 11727 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11728 | "Formats MUST be IDENTICAL unless " |
| 11729 | "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT " |
| 11730 | "was set on image creation."); |
| 11731 | // Same compatibility class but no MUTABLE_FORMAT bit - Expect |
| 11732 | // VIEW_CREATE_ERROR |
| 11733 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT; |
| 11734 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11735 | m_errorMonitor->VerifyFound(); |
| 11736 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11737 | |
| 11738 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11739 | "can support ImageViews with " |
| 11740 | "differing formats but they must be " |
| 11741 | "in the same compatibility class."); |
| 11742 | // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect |
| 11743 | // VIEW_CREATE_ERROR |
| 11744 | VkImageCreateInfo mutImgInfo = image.create_info(); |
| 11745 | VkImage mutImage; |
| 11746 | mutImgInfo.format = VK_FORMAT_R8_UINT; |
| 11747 | assert( |
| 11748 | m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & |
| 11749 | VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT); |
| 11750 | mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; |
| 11751 | mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 11752 | ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage); |
| 11753 | ASSERT_VK_SUCCESS(ret); |
| 11754 | imgViewInfo.image = mutImage; |
| 11755 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11756 | m_errorMonitor->VerifyFound(); |
| 11757 | imgViewInfo.image = image.handle(); |
| 11758 | vkDestroyImage(m_device->handle(), mutImage, NULL); |
| 11759 | } |
| 11760 | |
| 11761 | TEST_F(VkLayerTest, MiscImageLayerTests) { |
| 11762 | |
| 11763 | TEST_DESCRIPTION("Image layer tests that don't belong elsewhare"); |
| 11764 | |
| 11765 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11766 | |
| 11767 | VkImageObj image(m_device); |
| 11768 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 11769 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 11770 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 11771 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 11772 | ASSERT_TRUE(image.initialized()); |
| 11773 | |
| 11774 | m_errorMonitor->SetDesiredFailureMsg( |
| 11775 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11776 | "number of layers in image subresource is zero"); |
| 11777 | vk_testing::Buffer buffer; |
| 11778 | VkMemoryPropertyFlags reqs = 0; |
| 11779 | buffer.init_as_src(*m_device, 128 * 128 * 4, reqs); |
| 11780 | VkBufferImageCopy region = {}; |
| 11781 | region.bufferRowLength = 128; |
| 11782 | region.bufferImageHeight = 128; |
| 11783 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11784 | // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT |
| 11785 | region.imageSubresource.layerCount = 0; |
| 11786 | region.imageExtent.height = 4; |
| 11787 | region.imageExtent.width = 4; |
| 11788 | region.imageExtent.depth = 1; |
| 11789 | m_commandBuffer->BeginCommandBuffer(); |
| 11790 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 11791 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 11792 | 1, ®ion); |
| 11793 | m_errorMonitor->VerifyFound(); |
| 11794 | region.imageSubresource.layerCount = 1; |
| 11795 | |
| 11796 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11797 | "aspectMasks for each region must " |
| 11798 | "specify only COLOR or DEPTH or " |
| 11799 | "STENCIL"); |
| 11800 | // Expect MISMATCHED_IMAGE_ASPECT |
| 11801 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT; |
| 11802 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 11803 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 11804 | 1, ®ion); |
| 11805 | m_errorMonitor->VerifyFound(); |
| 11806 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11807 | |
| 11808 | m_errorMonitor->SetDesiredFailureMsg( |
| 11809 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11810 | "If the format of srcImage is a depth, stencil, depth stencil or " |
| 11811 | "integer-based format then filter must be VK_FILTER_NEAREST"); |
| 11812 | // Expect INVALID_FILTER |
| 11813 | VkImageObj intImage1(m_device); |
| 11814 | intImage1.init(128, 128, VK_FORMAT_R8_UINT, |
| 11815 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, |
| 11816 | 0); |
| 11817 | VkImageObj intImage2(m_device); |
| 11818 | intImage2.init(128, 128, VK_FORMAT_R8_UINT, |
| 11819 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, |
| 11820 | 0); |
| 11821 | VkImageBlit blitRegion = {}; |
| 11822 | blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11823 | blitRegion.srcSubresource.baseArrayLayer = 0; |
| 11824 | blitRegion.srcSubresource.layerCount = 1; |
| 11825 | blitRegion.srcSubresource.mipLevel = 0; |
| 11826 | blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11827 | blitRegion.dstSubresource.baseArrayLayer = 0; |
| 11828 | blitRegion.dstSubresource.layerCount = 1; |
| 11829 | blitRegion.dstSubresource.mipLevel = 0; |
| 11830 | |
| 11831 | vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), |
| 11832 | intImage1.layout(), intImage2.handle(), intImage2.layout(), |
| 11833 | 16, &blitRegion, VK_FILTER_LINEAR); |
| 11834 | m_errorMonitor->VerifyFound(); |
| 11835 | |
| 11836 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11837 | "called with 0 in ppMemoryBarriers"); |
| 11838 | VkImageMemoryBarrier img_barrier; |
| 11839 | img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 11840 | img_barrier.pNext = NULL; |
| 11841 | img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 11842 | img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 11843 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 11844 | img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 11845 | img_barrier.image = image.handle(); |
| 11846 | img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 11847 | img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 11848 | img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11849 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 11850 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 11851 | // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE |
| 11852 | img_barrier.subresourceRange.layerCount = 0; |
| 11853 | img_barrier.subresourceRange.levelCount = 1; |
| 11854 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 11855 | VK_PIPELINE_STAGE_HOST_BIT, |
| 11856 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 11857 | nullptr, 1, &img_barrier); |
| 11858 | m_errorMonitor->VerifyFound(); |
| 11859 | img_barrier.subresourceRange.layerCount = 1; |
| 11860 | } |
| 11861 | |
| 11862 | TEST_F(VkLayerTest, ImageFormatLimits) { |
| 11863 | |
| 11864 | TEST_DESCRIPTION("Exceed the limits of image format "); |
| 11865 | |
| 11866 | m_errorMonitor->SetDesiredFailureMsg( |
| 11867 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11868 | "CreateImage extents exceed allowable limits for format"); |
| 11869 | VkImageCreateInfo image_create_info = {}; |
| 11870 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11871 | image_create_info.pNext = NULL; |
| 11872 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11873 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11874 | image_create_info.extent.width = 32; |
| 11875 | image_create_info.extent.height = 32; |
| 11876 | image_create_info.extent.depth = 1; |
| 11877 | image_create_info.mipLevels = 1; |
| 11878 | image_create_info.arrayLayers = 1; |
| 11879 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11880 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11881 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11882 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 11883 | image_create_info.flags = 0; |
| 11884 | |
| 11885 | VkImage nullImg; |
| 11886 | VkImageFormatProperties imgFmtProps; |
| 11887 | vkGetPhysicalDeviceImageFormatProperties( |
| 11888 | gpu(), image_create_info.format, image_create_info.imageType, |
| 11889 | image_create_info.tiling, image_create_info.usage, |
| 11890 | image_create_info.flags, &imgFmtProps); |
| 11891 | image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1; |
| 11892 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 11893 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11894 | m_errorMonitor->VerifyFound(); |
| 11895 | image_create_info.extent.depth = 1; |
| 11896 | |
| 11897 | m_errorMonitor->SetDesiredFailureMsg( |
| 11898 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11899 | "exceeds allowable maximum supported by format of"); |
| 11900 | image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1; |
| 11901 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 11902 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11903 | m_errorMonitor->VerifyFound(); |
| 11904 | image_create_info.mipLevels = 1; |
| 11905 | |
| 11906 | m_errorMonitor->SetDesiredFailureMsg( |
| 11907 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11908 | "exceeds allowable maximum supported by format of"); |
| 11909 | image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1; |
| 11910 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 11911 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11912 | m_errorMonitor->VerifyFound(); |
| 11913 | image_create_info.arrayLayers = 1; |
| 11914 | |
| 11915 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11916 | "is not supported by format"); |
| 11917 | int samples = imgFmtProps.sampleCounts >> 1; |
| 11918 | image_create_info.samples = (VkSampleCountFlagBits)samples; |
| 11919 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 11920 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11921 | m_errorMonitor->VerifyFound(); |
| 11922 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11923 | |
| 11924 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11925 | "pCreateInfo->initialLayout, must be " |
| 11926 | "VK_IMAGE_LAYOUT_UNDEFINED or " |
| 11927 | "VK_IMAGE_LAYOUT_PREINITIALIZED"); |
| 11928 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 11929 | // Expect INVALID_LAYOUT |
| 11930 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11931 | m_errorMonitor->VerifyFound(); |
| 11932 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 11933 | } |
| 11934 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11935 | TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 11936 | VkResult err; |
| 11937 | bool pass; |
| 11938 | |
| 11939 | // Create color images with different format sizes and try to copy between them |
| 11940 | m_errorMonitor->SetDesiredFailureMsg( |
| 11941 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11942 | "vkCmdCopyImage called with unmatched source and dest image format sizes"); |
| 11943 | |
| 11944 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11945 | |
| 11946 | // Create two images of different types and try to copy between them |
| 11947 | VkImage srcImage; |
| 11948 | VkImage dstImage; |
| 11949 | VkDeviceMemory srcMem; |
| 11950 | VkDeviceMemory destMem; |
| 11951 | VkMemoryRequirements memReqs; |
| 11952 | |
| 11953 | VkImageCreateInfo image_create_info = {}; |
| 11954 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11955 | image_create_info.pNext = NULL; |
| 11956 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11957 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11958 | image_create_info.extent.width = 32; |
| 11959 | image_create_info.extent.height = 32; |
| 11960 | image_create_info.extent.depth = 1; |
| 11961 | image_create_info.mipLevels = 1; |
| 11962 | image_create_info.arrayLayers = 1; |
| 11963 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11964 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11965 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11966 | image_create_info.flags = 0; |
| 11967 | |
| 11968 | err = |
| 11969 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
| 11970 | ASSERT_VK_SUCCESS(err); |
| 11971 | |
| 11972 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 11973 | // Introduce failure by creating second image with a different-sized format. |
| 11974 | image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16; |
| 11975 | |
| 11976 | err = |
| 11977 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
| 11978 | ASSERT_VK_SUCCESS(err); |
| 11979 | |
| 11980 | // Allocate memory |
| 11981 | VkMemoryAllocateInfo memAlloc = {}; |
| 11982 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 11983 | memAlloc.pNext = NULL; |
| 11984 | memAlloc.allocationSize = 0; |
| 11985 | memAlloc.memoryTypeIndex = 0; |
| 11986 | |
| 11987 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
| 11988 | memAlloc.allocationSize = memReqs.size; |
| 11989 | pass = |
| 11990 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
| 11991 | ASSERT_TRUE(pass); |
| 11992 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
| 11993 | ASSERT_VK_SUCCESS(err); |
| 11994 | |
| 11995 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
| 11996 | memAlloc.allocationSize = memReqs.size; |
| 11997 | pass = |
| 11998 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
| 11999 | ASSERT_TRUE(pass); |
| 12000 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
| 12001 | ASSERT_VK_SUCCESS(err); |
| 12002 | |
| 12003 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12004 | ASSERT_VK_SUCCESS(err); |
| 12005 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
| 12006 | ASSERT_VK_SUCCESS(err); |
| 12007 | |
| 12008 | BeginCommandBuffer(); |
| 12009 | VkImageCopy copyRegion; |
| 12010 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 12011 | copyRegion.srcSubresource.mipLevel = 0; |
| 12012 | copyRegion.srcSubresource.baseArrayLayer = 0; |
| 12013 | copyRegion.srcSubresource.layerCount = 0; |
| 12014 | copyRegion.srcOffset.x = 0; |
| 12015 | copyRegion.srcOffset.y = 0; |
| 12016 | copyRegion.srcOffset.z = 0; |
| 12017 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 12018 | copyRegion.dstSubresource.mipLevel = 0; |
| 12019 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 12020 | copyRegion.dstSubresource.layerCount = 0; |
| 12021 | copyRegion.dstOffset.x = 0; |
| 12022 | copyRegion.dstOffset.y = 0; |
| 12023 | copyRegion.dstOffset.z = 0; |
| 12024 | copyRegion.extent.width = 1; |
| 12025 | copyRegion.extent.height = 1; |
| 12026 | copyRegion.extent.depth = 1; |
| 12027 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12028 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 12029 | EndCommandBuffer(); |
| 12030 | |
| 12031 | m_errorMonitor->VerifyFound(); |
| 12032 | |
| 12033 | vkDestroyImage(m_device->device(), srcImage, NULL); |
| 12034 | vkDestroyImage(m_device->device(), dstImage, NULL); |
| 12035 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12036 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12037 | } |
| 12038 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12039 | TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) { |
| 12040 | VkResult err; |
| 12041 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12042 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12043 | // 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] | 12044 | m_errorMonitor->SetDesiredFailureMsg( |
| 12045 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12046 | "vkCmdCopyImage called with unmatched source and dest image depth"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12047 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12048 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12049 | |
| 12050 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12051 | VkImage srcImage; |
| 12052 | VkImage dstImage; |
| 12053 | VkDeviceMemory srcMem; |
| 12054 | VkDeviceMemory destMem; |
| 12055 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12056 | |
| 12057 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12058 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12059 | image_create_info.pNext = NULL; |
| 12060 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12061 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12062 | image_create_info.extent.width = 32; |
| 12063 | image_create_info.extent.height = 32; |
| 12064 | image_create_info.extent.depth = 1; |
| 12065 | image_create_info.mipLevels = 1; |
| 12066 | image_create_info.arrayLayers = 1; |
| 12067 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12068 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12069 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 12070 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12071 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12072 | err = |
| 12073 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12074 | ASSERT_VK_SUCCESS(err); |
| 12075 | |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 12076 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 12077 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12078 | // Introduce failure by creating second image with a depth/stencil format |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12079 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12080 | image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 12081 | image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12082 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12083 | err = |
| 12084 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12085 | ASSERT_VK_SUCCESS(err); |
| 12086 | |
| 12087 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12088 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12089 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12090 | memAlloc.pNext = NULL; |
| 12091 | memAlloc.allocationSize = 0; |
| 12092 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12093 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12094 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12095 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12096 | pass = |
| 12097 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12098 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12099 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12100 | ASSERT_VK_SUCCESS(err); |
| 12101 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12102 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12103 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12104 | pass = |
| 12105 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12106 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12107 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12108 | ASSERT_VK_SUCCESS(err); |
| 12109 | |
| 12110 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12111 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12112 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12113 | ASSERT_VK_SUCCESS(err); |
| 12114 | |
| 12115 | BeginCommandBuffer(); |
| 12116 | VkImageCopy copyRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12117 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12118 | copyRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12119 | copyRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12120 | copyRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12121 | copyRegion.srcOffset.x = 0; |
| 12122 | copyRegion.srcOffset.y = 0; |
| 12123 | copyRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12124 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12125 | copyRegion.dstSubresource.mipLevel = 0; |
| 12126 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 12127 | copyRegion.dstSubresource.layerCount = 0; |
| 12128 | copyRegion.dstOffset.x = 0; |
| 12129 | copyRegion.dstOffset.y = 0; |
| 12130 | copyRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12131 | copyRegion.extent.width = 1; |
| 12132 | copyRegion.extent.height = 1; |
| 12133 | copyRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12134 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12135 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12136 | EndCommandBuffer(); |
| 12137 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12138 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12139 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12140 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12141 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12142 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12143 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12144 | } |
| 12145 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12146 | TEST_F(VkLayerTest, ResolveImageLowSampleCount) { |
| 12147 | VkResult err; |
| 12148 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12149 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12150 | m_errorMonitor->SetDesiredFailureMsg( |
| 12151 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12152 | "vkCmdResolveImage called with source sample count less than 2."); |
| 12153 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12154 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12155 | |
| 12156 | // 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] | 12157 | VkImage srcImage; |
| 12158 | VkImage dstImage; |
| 12159 | VkDeviceMemory srcMem; |
| 12160 | VkDeviceMemory destMem; |
| 12161 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12162 | |
| 12163 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12164 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12165 | image_create_info.pNext = NULL; |
| 12166 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12167 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12168 | image_create_info.extent.width = 32; |
| 12169 | image_create_info.extent.height = 1; |
| 12170 | image_create_info.extent.depth = 1; |
| 12171 | image_create_info.mipLevels = 1; |
| 12172 | image_create_info.arrayLayers = 1; |
| 12173 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12174 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12175 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 12176 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12177 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12178 | err = |
| 12179 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12180 | ASSERT_VK_SUCCESS(err); |
| 12181 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12182 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12183 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12184 | err = |
| 12185 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12186 | ASSERT_VK_SUCCESS(err); |
| 12187 | |
| 12188 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12189 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12190 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12191 | memAlloc.pNext = NULL; |
| 12192 | memAlloc.allocationSize = 0; |
| 12193 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12194 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12195 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12196 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12197 | pass = |
| 12198 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12199 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12200 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12201 | ASSERT_VK_SUCCESS(err); |
| 12202 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12203 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12204 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12205 | pass = |
| 12206 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12207 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12208 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12209 | ASSERT_VK_SUCCESS(err); |
| 12210 | |
| 12211 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12212 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12213 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12214 | ASSERT_VK_SUCCESS(err); |
| 12215 | |
| 12216 | BeginCommandBuffer(); |
| 12217 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12218 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12219 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12220 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12221 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12222 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12223 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12224 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12225 | resolveRegion.srcOffset.x = 0; |
| 12226 | resolveRegion.srcOffset.y = 0; |
| 12227 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12228 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12229 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12230 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12231 | resolveRegion.dstSubresource.layerCount = 0; |
| 12232 | resolveRegion.dstOffset.x = 0; |
| 12233 | resolveRegion.dstOffset.y = 0; |
| 12234 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12235 | resolveRegion.extent.width = 1; |
| 12236 | resolveRegion.extent.height = 1; |
| 12237 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12238 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12239 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12240 | EndCommandBuffer(); |
| 12241 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12242 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12243 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12244 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12245 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12246 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12247 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12248 | } |
| 12249 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12250 | TEST_F(VkLayerTest, ResolveImageHighSampleCount) { |
| 12251 | VkResult err; |
| 12252 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12253 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12254 | m_errorMonitor->SetDesiredFailureMsg( |
| 12255 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12256 | "vkCmdResolveImage called with dest sample count greater than 1."); |
| 12257 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12258 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12259 | |
Chris Forbes | a753069 | 2016-05-08 12:35:39 +1200 | [diff] [blame] | 12260 | // 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] | 12261 | VkImage srcImage; |
| 12262 | VkImage dstImage; |
| 12263 | VkDeviceMemory srcMem; |
| 12264 | VkDeviceMemory destMem; |
| 12265 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12266 | |
| 12267 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12268 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12269 | image_create_info.pNext = NULL; |
| 12270 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12271 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12272 | image_create_info.extent.width = 32; |
| 12273 | image_create_info.extent.height = 1; |
| 12274 | image_create_info.extent.depth = 1; |
| 12275 | image_create_info.mipLevels = 1; |
| 12276 | image_create_info.arrayLayers = 1; |
Chris Forbes | a753069 | 2016-05-08 12:35:39 +1200 | [diff] [blame] | 12277 | image_create_info.samples = VK_SAMPLE_COUNT_4_BIT; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12278 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12279 | // Note: Some implementations expect color attachment usage for any |
| 12280 | // multisample surface |
| 12281 | image_create_info.usage = |
| 12282 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12283 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12284 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12285 | err = |
| 12286 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12287 | ASSERT_VK_SUCCESS(err); |
| 12288 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12289 | // Note: Some implementations expect color attachment usage for any |
| 12290 | // multisample surface |
| 12291 | image_create_info.usage = |
| 12292 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12293 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12294 | err = |
| 12295 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12296 | ASSERT_VK_SUCCESS(err); |
| 12297 | |
| 12298 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12299 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12300 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12301 | memAlloc.pNext = NULL; |
| 12302 | memAlloc.allocationSize = 0; |
| 12303 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12304 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12305 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12306 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12307 | pass = |
| 12308 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12309 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12310 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12311 | ASSERT_VK_SUCCESS(err); |
| 12312 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12313 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12314 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12315 | pass = |
| 12316 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12317 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12318 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12319 | ASSERT_VK_SUCCESS(err); |
| 12320 | |
| 12321 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12322 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12323 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12324 | ASSERT_VK_SUCCESS(err); |
| 12325 | |
| 12326 | BeginCommandBuffer(); |
| 12327 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12328 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12329 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12330 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12331 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12332 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12333 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12334 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12335 | resolveRegion.srcOffset.x = 0; |
| 12336 | resolveRegion.srcOffset.y = 0; |
| 12337 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12338 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12339 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12340 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12341 | resolveRegion.dstSubresource.layerCount = 0; |
| 12342 | resolveRegion.dstOffset.x = 0; |
| 12343 | resolveRegion.dstOffset.y = 0; |
| 12344 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12345 | resolveRegion.extent.width = 1; |
| 12346 | resolveRegion.extent.height = 1; |
| 12347 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12348 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12349 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12350 | EndCommandBuffer(); |
| 12351 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12352 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12353 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12354 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12355 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12356 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12357 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12358 | } |
| 12359 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12360 | TEST_F(VkLayerTest, ResolveImageFormatMismatch) { |
| 12361 | VkResult err; |
| 12362 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12363 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12364 | m_errorMonitor->SetDesiredFailureMsg( |
| 12365 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12366 | "vkCmdResolveImage called with unmatched source and dest formats."); |
| 12367 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12368 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12369 | |
| 12370 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12371 | VkImage srcImage; |
| 12372 | VkImage dstImage; |
| 12373 | VkDeviceMemory srcMem; |
| 12374 | VkDeviceMemory destMem; |
| 12375 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12376 | |
| 12377 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12378 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12379 | image_create_info.pNext = NULL; |
| 12380 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12381 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12382 | image_create_info.extent.width = 32; |
| 12383 | image_create_info.extent.height = 1; |
| 12384 | image_create_info.extent.depth = 1; |
| 12385 | image_create_info.mipLevels = 1; |
| 12386 | image_create_info.arrayLayers = 1; |
| 12387 | image_create_info.samples = VK_SAMPLE_COUNT_2_BIT; |
| 12388 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12389 | // Note: Some implementations expect color attachment usage for any |
| 12390 | // multisample surface |
| 12391 | image_create_info.usage = |
| 12392 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_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 | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12399 | // Set format to something other than source image |
| 12400 | image_create_info.format = VK_FORMAT_R32_SFLOAT; |
| 12401 | // Note: Some implementations expect color attachment usage for any |
| 12402 | // multisample surface |
| 12403 | image_create_info.usage = |
| 12404 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12405 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12406 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12407 | err = |
| 12408 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12409 | ASSERT_VK_SUCCESS(err); |
| 12410 | |
| 12411 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12412 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12413 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12414 | memAlloc.pNext = NULL; |
| 12415 | memAlloc.allocationSize = 0; |
| 12416 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12417 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12418 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12419 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12420 | pass = |
| 12421 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12422 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12423 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12424 | ASSERT_VK_SUCCESS(err); |
| 12425 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12426 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12427 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12428 | pass = |
| 12429 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12430 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12431 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12432 | ASSERT_VK_SUCCESS(err); |
| 12433 | |
| 12434 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12435 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12436 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12437 | ASSERT_VK_SUCCESS(err); |
| 12438 | |
| 12439 | BeginCommandBuffer(); |
| 12440 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12441 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12442 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12443 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12444 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12445 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12446 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12447 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12448 | resolveRegion.srcOffset.x = 0; |
| 12449 | resolveRegion.srcOffset.y = 0; |
| 12450 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12451 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12452 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12453 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12454 | resolveRegion.dstSubresource.layerCount = 0; |
| 12455 | resolveRegion.dstOffset.x = 0; |
| 12456 | resolveRegion.dstOffset.y = 0; |
| 12457 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12458 | resolveRegion.extent.width = 1; |
| 12459 | resolveRegion.extent.height = 1; |
| 12460 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12461 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12462 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12463 | EndCommandBuffer(); |
| 12464 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12465 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12466 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12467 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12468 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12469 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12470 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12471 | } |
| 12472 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12473 | TEST_F(VkLayerTest, ResolveImageTypeMismatch) { |
| 12474 | VkResult err; |
| 12475 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12476 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12477 | m_errorMonitor->SetDesiredFailureMsg( |
| 12478 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12479 | "vkCmdResolveImage called with unmatched source and dest image types."); |
| 12480 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12481 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12482 | |
| 12483 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12484 | VkImage srcImage; |
| 12485 | VkImage dstImage; |
| 12486 | VkDeviceMemory srcMem; |
| 12487 | VkDeviceMemory destMem; |
| 12488 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12489 | |
| 12490 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12491 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12492 | image_create_info.pNext = NULL; |
| 12493 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12494 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12495 | image_create_info.extent.width = 32; |
| 12496 | image_create_info.extent.height = 1; |
| 12497 | image_create_info.extent.depth = 1; |
| 12498 | image_create_info.mipLevels = 1; |
| 12499 | image_create_info.arrayLayers = 1; |
| 12500 | image_create_info.samples = VK_SAMPLE_COUNT_2_BIT; |
| 12501 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12502 | // Note: Some implementations expect color attachment usage for any |
| 12503 | // multisample surface |
| 12504 | image_create_info.usage = |
| 12505 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12506 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12507 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12508 | err = |
| 12509 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12510 | ASSERT_VK_SUCCESS(err); |
| 12511 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12512 | image_create_info.imageType = VK_IMAGE_TYPE_1D; |
| 12513 | // Note: Some implementations expect color attachment usage for any |
| 12514 | // multisample surface |
| 12515 | image_create_info.usage = |
| 12516 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12517 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12518 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12519 | err = |
| 12520 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12521 | ASSERT_VK_SUCCESS(err); |
| 12522 | |
| 12523 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12524 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12525 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12526 | memAlloc.pNext = NULL; |
| 12527 | memAlloc.allocationSize = 0; |
| 12528 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12529 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12530 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12531 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12532 | pass = |
| 12533 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12534 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12535 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12536 | ASSERT_VK_SUCCESS(err); |
| 12537 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12538 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12539 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12540 | pass = |
| 12541 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12542 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12543 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12544 | ASSERT_VK_SUCCESS(err); |
| 12545 | |
| 12546 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12547 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12548 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12549 | ASSERT_VK_SUCCESS(err); |
| 12550 | |
| 12551 | BeginCommandBuffer(); |
| 12552 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12553 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12554 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12555 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12556 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12557 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12558 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12559 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12560 | resolveRegion.srcOffset.x = 0; |
| 12561 | resolveRegion.srcOffset.y = 0; |
| 12562 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12563 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12564 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12565 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12566 | resolveRegion.dstSubresource.layerCount = 0; |
| 12567 | resolveRegion.dstOffset.x = 0; |
| 12568 | resolveRegion.dstOffset.y = 0; |
| 12569 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12570 | resolveRegion.extent.width = 1; |
| 12571 | resolveRegion.extent.height = 1; |
| 12572 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12573 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12574 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12575 | EndCommandBuffer(); |
| 12576 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12577 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12578 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12579 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12580 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12581 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12582 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12583 | } |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12584 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12585 | TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) { |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12586 | // 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] | 12587 | // to using a DS format, then cause it to hit error due to COLOR_BIT not |
| 12588 | // set in aspect |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12589 | // The image format check comes 2nd in validation so we trigger it first, |
| 12590 | // 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] | 12591 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12592 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12593 | m_errorMonitor->SetDesiredFailureMsg( |
| 12594 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12595 | "Combination depth/stencil image formats can have only the "); |
| 12596 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12597 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12598 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 12599 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12600 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 12601 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12602 | |
| 12603 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12604 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 12605 | ds_pool_ci.pNext = NULL; |
| 12606 | ds_pool_ci.maxSets = 1; |
| 12607 | ds_pool_ci.poolSizeCount = 1; |
| 12608 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12609 | |
| 12610 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12611 | err = |
| 12612 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12613 | ASSERT_VK_SUCCESS(err); |
| 12614 | |
| 12615 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12616 | dsl_binding.binding = 0; |
| 12617 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 12618 | dsl_binding.descriptorCount = 1; |
| 12619 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 12620 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12621 | |
| 12622 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12623 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 12624 | ds_layout_ci.pNext = NULL; |
| 12625 | ds_layout_ci.bindingCount = 1; |
| 12626 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12627 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12628 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 12629 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12630 | ASSERT_VK_SUCCESS(err); |
| 12631 | |
| 12632 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12633 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 12634 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 12635 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12636 | alloc_info.descriptorPool = ds_pool; |
| 12637 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12638 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 12639 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12640 | ASSERT_VK_SUCCESS(err); |
| 12641 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12642 | VkImage image_bad; |
| 12643 | VkImage image_good; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12644 | // One bad format and one good format for Color attachment |
Tobin Ehlis | 269f032 | 2016-05-25 16:24:21 -0600 | [diff] [blame] | 12645 | const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12646 | const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12647 | const int32_t tex_width = 32; |
| 12648 | const int32_t tex_height = 32; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12649 | |
| 12650 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12651 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12652 | image_create_info.pNext = NULL; |
| 12653 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12654 | image_create_info.format = tex_format_bad; |
| 12655 | image_create_info.extent.width = tex_width; |
| 12656 | image_create_info.extent.height = tex_height; |
| 12657 | image_create_info.extent.depth = 1; |
| 12658 | image_create_info.mipLevels = 1; |
| 12659 | image_create_info.arrayLayers = 1; |
| 12660 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12661 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12662 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | |
| 12663 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 12664 | image_create_info.flags = 0; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12665 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12666 | err = |
| 12667 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12668 | ASSERT_VK_SUCCESS(err); |
| 12669 | image_create_info.format = tex_format_good; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12670 | image_create_info.usage = |
| 12671 | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12672 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, |
| 12673 | &image_good); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12674 | ASSERT_VK_SUCCESS(err); |
| 12675 | |
| 12676 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12677 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12678 | image_view_create_info.image = image_bad; |
| 12679 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 12680 | image_view_create_info.format = tex_format_bad; |
| 12681 | image_view_create_info.subresourceRange.baseArrayLayer = 0; |
| 12682 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 12683 | image_view_create_info.subresourceRange.layerCount = 1; |
| 12684 | image_view_create_info.subresourceRange.levelCount = 1; |
| 12685 | image_view_create_info.subresourceRange.aspectMask = |
| 12686 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12687 | |
| 12688 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12689 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 12690 | &view); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12691 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12692 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12693 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12694 | vkDestroyImage(m_device->device(), image_bad, NULL); |
| 12695 | vkDestroyImage(m_device->device(), image_good, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12696 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 12697 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12698 | } |
Tobin Ehlis | 6e23d77 | 2016-05-19 11:08:34 -0600 | [diff] [blame] | 12699 | |
| 12700 | TEST_F(VkLayerTest, ClearImageErrors) { |
| 12701 | TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and " |
| 12702 | "ClearDepthStencilImage with a color image."); |
| 12703 | |
| 12704 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12705 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 12706 | |
| 12707 | // Renderpass is started here so end it as Clear cmds can't be in renderpass |
| 12708 | BeginCommandBuffer(); |
| 12709 | m_commandBuffer->EndRenderPass(); |
| 12710 | |
| 12711 | // Color image |
| 12712 | VkClearColorValue clear_color; |
| 12713 | memset(clear_color.uint32, 0, sizeof(uint32_t) * 4); |
| 12714 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 12715 | const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12716 | const int32_t img_width = 32; |
| 12717 | const int32_t img_height = 32; |
| 12718 | VkImageCreateInfo image_create_info = {}; |
| 12719 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12720 | image_create_info.pNext = NULL; |
| 12721 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12722 | image_create_info.format = color_format; |
| 12723 | image_create_info.extent.width = img_width; |
| 12724 | image_create_info.extent.height = img_height; |
| 12725 | image_create_info.extent.depth = 1; |
| 12726 | image_create_info.mipLevels = 1; |
| 12727 | image_create_info.arrayLayers = 1; |
| 12728 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12729 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12730 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 12731 | |
| 12732 | vk_testing::Image color_image; |
| 12733 | color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 12734 | reqs); |
| 12735 | |
| 12736 | const VkImageSubresourceRange color_range = |
| 12737 | vk_testing::Image::subresource_range(image_create_info, |
| 12738 | VK_IMAGE_ASPECT_COLOR_BIT); |
| 12739 | |
| 12740 | // Depth/Stencil image |
| 12741 | VkClearDepthStencilValue clear_value = {0}; |
| 12742 | reqs = 0; // don't need HOST_VISIBLE DS image |
| 12743 | VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info(); |
| 12744 | ds_image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12745 | ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 12746 | ds_image_create_info.extent.width = 64; |
| 12747 | ds_image_create_info.extent.height = 64; |
| 12748 | ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12749 | ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 12750 | |
| 12751 | vk_testing::Image ds_image; |
| 12752 | ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, |
| 12753 | reqs); |
| 12754 | |
| 12755 | const VkImageSubresourceRange ds_range = |
| 12756 | vk_testing::Image::subresource_range(ds_image_create_info, |
| 12757 | VK_IMAGE_ASPECT_DEPTH_BIT); |
| 12758 | |
| 12759 | m_errorMonitor->SetDesiredFailureMsg( |
| 12760 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12761 | "vkCmdClearColorImage called with depth/stencil image."); |
| 12762 | |
| 12763 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), |
| 12764 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, |
| 12765 | &color_range); |
| 12766 | |
| 12767 | m_errorMonitor->VerifyFound(); |
| 12768 | |
Tony Barbour | 26434b9 | 2016-06-02 09:43:50 -0600 | [diff] [blame] | 12769 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12770 | "vkCmdClearColorImage called with " |
| 12771 | "image created without " |
| 12772 | "VK_IMAGE_USAGE_TRANSFER_DST_BIT"); |
| 12773 | |
| 12774 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), |
| 12775 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, |
| 12776 | &color_range); |
| 12777 | |
| 12778 | m_errorMonitor->VerifyFound(); |
| 12779 | |
Tobin Ehlis | 6e23d77 | 2016-05-19 11:08:34 -0600 | [diff] [blame] | 12780 | // Call CmdClearDepthStencilImage with color image |
| 12781 | m_errorMonitor->SetDesiredFailureMsg( |
| 12782 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12783 | "vkCmdClearDepthStencilImage called without a depth/stencil image."); |
| 12784 | |
| 12785 | vkCmdClearDepthStencilImage( |
| 12786 | m_commandBuffer->GetBufferHandle(), color_image.handle(), |
| 12787 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, |
| 12788 | &ds_range); |
| 12789 | |
| 12790 | m_errorMonitor->VerifyFound(); |
| 12791 | } |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12792 | #endif // IMAGE_TESTS |
| 12793 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 12794 | int main(int argc, char **argv) { |
| 12795 | int result; |
| 12796 | |
Cody Northrop | 8e54a40 | 2016-03-08 22:25:52 -0700 | [diff] [blame] | 12797 | #ifdef ANDROID |
| 12798 | int vulkanSupport = InitVulkan(); |
| 12799 | if (vulkanSupport == 0) |
| 12800 | return 1; |
| 12801 | #endif |
| 12802 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 12803 | ::testing::InitGoogleTest(&argc, argv); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 12804 | VkTestFramework::InitArgs(&argc, argv); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 12805 | |
| 12806 | ::testing::AddGlobalTestEnvironment(new TestEnvironment); |
| 12807 | |
| 12808 | result = RUN_ALL_TESTS(); |
| 12809 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 12810 | VkTestFramework::Finish(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 12811 | return result; |
| 12812 | } |