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" |
| 3231 | " 6. FB attachment where dimensions don't match\n"); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3232 | |
| 3233 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3234 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 3235 | |
| 3236 | m_errorMonitor->SetDesiredFailureMsg( |
| 3237 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3238 | "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 " |
| 3239 | "does not match attachmentCount of 1 of "); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3240 | |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3241 | // Create a renderPass with a single color attachment |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3242 | VkAttachmentReference attach = {}; |
| 3243 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 3244 | VkSubpassDescription subpass = {}; |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3245 | subpass.pColorAttachments = &attach; |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3246 | VkRenderPassCreateInfo rpci = {}; |
| 3247 | rpci.subpassCount = 1; |
| 3248 | rpci.pSubpasses = &subpass; |
| 3249 | rpci.attachmentCount = 1; |
| 3250 | VkAttachmentDescription attach_desc = {}; |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 3251 | attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM; |
Tobin Ehlis | 77d717c | 2016-06-22 14:19:19 -0600 | [diff] [blame] | 3252 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3253 | rpci.pAttachments = &attach_desc; |
| 3254 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 3255 | VkRenderPass rp; |
| 3256 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3257 | ASSERT_VK_SUCCESS(err); |
| 3258 | |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3259 | VkImageView ivs[2]; |
| 3260 | ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM); |
| 3261 | ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3262 | VkFramebufferCreateInfo fb_info = {}; |
| 3263 | fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
| 3264 | fb_info.pNext = NULL; |
| 3265 | fb_info.renderPass = rp; |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3266 | // Set mis-matching attachmentCount |
| 3267 | fb_info.attachmentCount = 2; |
| 3268 | fb_info.pAttachments = ivs; |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3269 | fb_info.width = 100; |
| 3270 | fb_info.height = 100; |
| 3271 | fb_info.layers = 1; |
| 3272 | |
| 3273 | VkFramebuffer fb; |
| 3274 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3275 | |
| 3276 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3277 | if (err == VK_SUCCESS) { |
| 3278 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3279 | } |
| 3280 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3281 | |
| 3282 | // Create a renderPass with a depth-stencil attachment created with |
| 3283 | // IMAGE_USAGE_COLOR_ATTACHMENT |
| 3284 | // Add our color attachment to pDepthStencilAttachment |
| 3285 | subpass.pDepthStencilAttachment = &attach; |
| 3286 | subpass.pColorAttachments = NULL; |
| 3287 | VkRenderPass rp_ds; |
| 3288 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds); |
| 3289 | ASSERT_VK_SUCCESS(err); |
| 3290 | // Set correct attachment count, but attachment has COLOR usage bit set |
| 3291 | fb_info.attachmentCount = 1; |
| 3292 | fb_info.renderPass = rp_ds; |
| 3293 | |
| 3294 | m_errorMonitor->SetDesiredFailureMsg( |
| 3295 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3296 | " conflicts with the image's IMAGE_USAGE flags "); |
| 3297 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3298 | |
| 3299 | m_errorMonitor->VerifyFound(); |
| 3300 | if (err == VK_SUCCESS) { |
| 3301 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3302 | } |
| 3303 | vkDestroyRenderPass(m_device->device(), rp_ds, NULL); |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 3304 | |
| 3305 | // Create new renderpass with alternate attachment format from fb |
| 3306 | attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 3307 | subpass.pDepthStencilAttachment = NULL; |
| 3308 | subpass.pColorAttachments = &attach; |
| 3309 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3310 | ASSERT_VK_SUCCESS(err); |
| 3311 | |
| 3312 | // Cause error due to mis-matched formats between rp & fb |
| 3313 | // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8 |
| 3314 | fb_info.renderPass = rp; |
| 3315 | m_errorMonitor->SetDesiredFailureMsg( |
| 3316 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3317 | " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match "); |
| 3318 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3319 | |
| 3320 | m_errorMonitor->VerifyFound(); |
| 3321 | if (err == VK_SUCCESS) { |
| 3322 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3323 | } |
Tobin Ehlis | 77d717c | 2016-06-22 14:19:19 -0600 | [diff] [blame] | 3324 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 3325 | |
| 3326 | // Create new renderpass with alternate sample count from fb |
| 3327 | attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 3328 | attach_desc.samples = VK_SAMPLE_COUNT_4_BIT; |
| 3329 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3330 | ASSERT_VK_SUCCESS(err); |
| 3331 | |
| 3332 | // Cause error due to mis-matched sample count between rp & fb |
| 3333 | fb_info.renderPass = rp; |
| 3334 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3335 | " has VK_SAMPLE_COUNT_1_BIT samples " |
| 3336 | "that do not match the " |
| 3337 | "VK_SAMPLE_COUNT_4_BIT "); |
| 3338 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3339 | |
| 3340 | m_errorMonitor->VerifyFound(); |
| 3341 | if (err == VK_SUCCESS) { |
| 3342 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3343 | } |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 3344 | |
| 3345 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 3346 | |
| 3347 | // Create a custom imageView with non-1 mip levels |
| 3348 | VkImageObj image(m_device); |
| 3349 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 3350 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 3351 | ASSERT_TRUE(image.initialized()); |
| 3352 | |
| 3353 | VkImageView view; |
| 3354 | VkImageViewCreateInfo ivci = {}; |
| 3355 | ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 3356 | ivci.image = image.handle(); |
| 3357 | ivci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 3358 | ivci.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 3359 | ivci.subresourceRange.layerCount = 1; |
| 3360 | ivci.subresourceRange.baseMipLevel = 0; |
| 3361 | // Set level count 2 (only 1 is allowed for FB attachment) |
| 3362 | ivci.subresourceRange.levelCount = 2; |
| 3363 | ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 3364 | err = vkCreateImageView(m_device->device(), &ivci, NULL, &view); |
| 3365 | ASSERT_VK_SUCCESS(err); |
| 3366 | // Re-create renderpass to have matching sample count |
| 3367 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
| 3368 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3369 | ASSERT_VK_SUCCESS(err); |
| 3370 | |
| 3371 | fb_info.renderPass = rp; |
| 3372 | fb_info.pAttachments = &view; |
| 3373 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3374 | " has mip levelCount of 2 but only "); |
| 3375 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3376 | |
| 3377 | m_errorMonitor->VerifyFound(); |
| 3378 | if (err == VK_SUCCESS) { |
| 3379 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3380 | } |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 3381 | vkDestroyImageView(m_device->device(), view, NULL); |
Tobin Ehlis | 27f2ae8 | 2016-06-23 07:36:57 -0600 | [diff] [blame] | 3382 | // Update view to original color buffer and grow FB dimensions too big |
| 3383 | fb_info.pAttachments = ivs; |
| 3384 | fb_info.height = 1024; |
| 3385 | fb_info.width = 1024; |
| 3386 | fb_info.layers = 2; |
| 3387 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3388 | " Attachment dimensions must be at " |
| 3389 | "least as large. "); |
| 3390 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3391 | |
| 3392 | m_errorMonitor->VerifyFound(); |
| 3393 | if (err == VK_SUCCESS) { |
| 3394 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3395 | } |
| 3396 | |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 3397 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3398 | } |
| 3399 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3400 | // This is a positive test. No errors should be generated. |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3401 | TEST_F(VkLayerTest, WaitEventThenSet) { |
| 3402 | TEST_DESCRIPTION( |
| 3403 | "Wait on a event then set it after the wait has been submitted."); |
| 3404 | |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3405 | m_errorMonitor->ExpectSuccess(); |
| 3406 | |
| 3407 | VkEvent event; |
| 3408 | VkEventCreateInfo event_create_info{}; |
| 3409 | event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 3410 | vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event); |
| 3411 | |
| 3412 | VkCommandPool command_pool; |
| 3413 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3414 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3415 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3416 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3417 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3418 | &command_pool); |
| 3419 | |
| 3420 | VkCommandBuffer command_buffer; |
| 3421 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3422 | command_buffer_allocate_info.sType = |
| 3423 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3424 | command_buffer_allocate_info.commandPool = command_pool; |
| 3425 | command_buffer_allocate_info.commandBufferCount = 1; |
| 3426 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3427 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3428 | &command_buffer); |
| 3429 | |
| 3430 | VkQueue queue = VK_NULL_HANDLE; |
| 3431 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
Tony Barbour | fe302c0 | 2016-06-06 13:05:19 -0600 | [diff] [blame] | 3432 | 0, &queue); |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3433 | |
| 3434 | { |
| 3435 | VkCommandBufferBeginInfo begin_info{}; |
| 3436 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3437 | vkBeginCommandBuffer(command_buffer, &begin_info); |
| 3438 | |
| 3439 | vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, |
| 3440 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, |
| 3441 | nullptr, 0, nullptr); |
| 3442 | vkCmdResetEvent(command_buffer, event, |
| 3443 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 3444 | vkEndCommandBuffer(command_buffer); |
| 3445 | } |
| 3446 | { |
| 3447 | VkSubmitInfo submit_info{}; |
| 3448 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3449 | submit_info.commandBufferCount = 1; |
| 3450 | submit_info.pCommandBuffers = &command_buffer; |
| 3451 | submit_info.signalSemaphoreCount = 0; |
| 3452 | submit_info.pSignalSemaphores = nullptr; |
| 3453 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3454 | } |
| 3455 | { vkSetEvent(m_device->device(), event); } |
| 3456 | |
| 3457 | vkQueueWaitIdle(queue); |
| 3458 | |
| 3459 | vkDestroyEvent(m_device->device(), event, nullptr); |
| 3460 | vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer); |
| 3461 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3462 | |
| 3463 | m_errorMonitor->VerifyNotFound(); |
| 3464 | } |
Michael Lentine | 5627e69 | 2016-05-20 17:45:02 -0500 | [diff] [blame] | 3465 | // This is a positive test. No errors should be generated. |
| 3466 | TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) { |
| 3467 | TEST_DESCRIPTION( |
| 3468 | "Issue a query and copy from it on a second command buffer."); |
| 3469 | |
| 3470 | if ((m_device->queue_props.empty()) || |
| 3471 | (m_device->queue_props[0].queueCount < 2)) |
| 3472 | return; |
| 3473 | |
| 3474 | m_errorMonitor->ExpectSuccess(); |
| 3475 | |
| 3476 | VkQueryPool query_pool; |
| 3477 | VkQueryPoolCreateInfo query_pool_create_info{}; |
| 3478 | query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; |
| 3479 | query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP; |
| 3480 | query_pool_create_info.queryCount = 1; |
| 3481 | vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, |
| 3482 | &query_pool); |
| 3483 | |
| 3484 | VkCommandPool command_pool; |
| 3485 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3486 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3487 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3488 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3489 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3490 | &command_pool); |
| 3491 | |
| 3492 | VkCommandBuffer command_buffer[2]; |
| 3493 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3494 | command_buffer_allocate_info.sType = |
| 3495 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3496 | command_buffer_allocate_info.commandPool = command_pool; |
| 3497 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3498 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3499 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3500 | command_buffer); |
| 3501 | |
| 3502 | VkQueue queue = VK_NULL_HANDLE; |
| 3503 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3504 | 1, &queue); |
| 3505 | |
| 3506 | uint32_t qfi = 0; |
| 3507 | VkBufferCreateInfo buff_create_info = {}; |
| 3508 | buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 3509 | buff_create_info.size = 1024; |
| 3510 | buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT; |
| 3511 | buff_create_info.queueFamilyIndexCount = 1; |
| 3512 | buff_create_info.pQueueFamilyIndices = &qfi; |
| 3513 | |
| 3514 | VkResult err; |
| 3515 | VkBuffer buffer; |
| 3516 | err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer); |
| 3517 | ASSERT_VK_SUCCESS(err); |
| 3518 | VkMemoryAllocateInfo mem_alloc = {}; |
| 3519 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 3520 | mem_alloc.pNext = NULL; |
| 3521 | mem_alloc.allocationSize = 1024; |
| 3522 | mem_alloc.memoryTypeIndex = 0; |
| 3523 | |
| 3524 | VkMemoryRequirements memReqs; |
| 3525 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs); |
| 3526 | bool pass = |
| 3527 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0); |
| 3528 | if (!pass) { |
| 3529 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 3530 | return; |
| 3531 | } |
| 3532 | |
| 3533 | VkDeviceMemory mem; |
| 3534 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 3535 | ASSERT_VK_SUCCESS(err); |
| 3536 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 3537 | ASSERT_VK_SUCCESS(err); |
| 3538 | |
| 3539 | { |
| 3540 | VkCommandBufferBeginInfo begin_info{}; |
| 3541 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3542 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3543 | |
| 3544 | vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1); |
| 3545 | vkCmdWriteTimestamp(command_buffer[0], |
| 3546 | VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0); |
| 3547 | |
| 3548 | vkEndCommandBuffer(command_buffer[0]); |
| 3549 | |
| 3550 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3551 | |
| 3552 | vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, |
| 3553 | 0, 0, 0); |
| 3554 | |
| 3555 | vkEndCommandBuffer(command_buffer[1]); |
| 3556 | } |
| 3557 | { |
| 3558 | VkSubmitInfo submit_info{}; |
| 3559 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3560 | submit_info.commandBufferCount = 2; |
| 3561 | submit_info.pCommandBuffers = command_buffer; |
| 3562 | submit_info.signalSemaphoreCount = 0; |
| 3563 | submit_info.pSignalSemaphores = nullptr; |
| 3564 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3565 | } |
| 3566 | |
| 3567 | vkQueueWaitIdle(queue); |
| 3568 | |
| 3569 | vkDestroyQueryPool(m_device->device(), query_pool, nullptr); |
| 3570 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer); |
| 3571 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 3572 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 3573 | vkFreeMemory(m_device->device(), mem, NULL); |
Michael Lentine | 5627e69 | 2016-05-20 17:45:02 -0500 | [diff] [blame] | 3574 | |
| 3575 | m_errorMonitor->VerifyNotFound(); |
| 3576 | } |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3577 | |
| 3578 | TEST_F(VkLayerTest, ResetEventThenSet) { |
| 3579 | TEST_DESCRIPTION( |
| 3580 | "Reset an event then set it after the reset has been submitted."); |
| 3581 | |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3582 | m_errorMonitor->ExpectSuccess(); |
| 3583 | |
| 3584 | VkEvent event; |
| 3585 | VkEventCreateInfo event_create_info{}; |
| 3586 | event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 3587 | vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event); |
| 3588 | |
| 3589 | VkCommandPool command_pool; |
| 3590 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3591 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3592 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3593 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3594 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3595 | &command_pool); |
| 3596 | |
| 3597 | VkCommandBuffer command_buffer; |
| 3598 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3599 | command_buffer_allocate_info.sType = |
| 3600 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3601 | command_buffer_allocate_info.commandPool = command_pool; |
| 3602 | command_buffer_allocate_info.commandBufferCount = 1; |
| 3603 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3604 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3605 | &command_buffer); |
| 3606 | |
| 3607 | VkQueue queue = VK_NULL_HANDLE; |
| 3608 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
Tony Barbour | fe302c0 | 2016-06-06 13:05:19 -0600 | [diff] [blame] | 3609 | 0, &queue); |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3610 | |
| 3611 | { |
| 3612 | VkCommandBufferBeginInfo begin_info{}; |
| 3613 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3614 | vkBeginCommandBuffer(command_buffer, &begin_info); |
| 3615 | |
| 3616 | vkCmdResetEvent(command_buffer, event, |
| 3617 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 3618 | vkCmdWaitEvents(command_buffer, 1, &event, |
| 3619 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3620 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, |
| 3621 | nullptr, 0, nullptr); |
| 3622 | vkEndCommandBuffer(command_buffer); |
| 3623 | } |
| 3624 | { |
| 3625 | VkSubmitInfo submit_info{}; |
| 3626 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3627 | submit_info.commandBufferCount = 1; |
| 3628 | submit_info.pCommandBuffers = &command_buffer; |
| 3629 | submit_info.signalSemaphoreCount = 0; |
| 3630 | submit_info.pSignalSemaphores = nullptr; |
| 3631 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3632 | } |
| 3633 | { |
| 3634 | m_errorMonitor->SetDesiredFailureMsg( |
| 3635 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkSetEvent() on event " |
| 3636 | "0x1 that is already in use by a " |
| 3637 | "command buffer."); |
| 3638 | vkSetEvent(m_device->device(), event); |
| 3639 | m_errorMonitor->VerifyFound(); |
| 3640 | } |
| 3641 | |
| 3642 | vkQueueWaitIdle(queue); |
| 3643 | |
| 3644 | vkDestroyEvent(m_device->device(), event, nullptr); |
| 3645 | vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer); |
| 3646 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3647 | } |
| 3648 | |
| 3649 | // This is a positive test. No errors should be generated. |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3650 | TEST_F(VkLayerTest, TwoFencesThreeFrames) { |
| 3651 | TEST_DESCRIPTION("Two command buffers with two separate fences are each " |
| 3652 | "run through a Submit & WaitForFences cycle 3 times. This " |
| 3653 | "previously revealed a bug so running this positive test " |
| 3654 | "to prevent a regression."); |
| 3655 | m_errorMonitor->ExpectSuccess(); |
| 3656 | |
| 3657 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3658 | VkQueue queue = VK_NULL_HANDLE; |
| 3659 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3660 | 0, &queue); |
| 3661 | |
| 3662 | static const uint32_t NUM_OBJECTS = 2; |
| 3663 | static const uint32_t NUM_FRAMES = 3; |
| 3664 | VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {}; |
| 3665 | VkFence fences[NUM_OBJECTS] = {}; |
| 3666 | |
| 3667 | VkCommandPool cmd_pool; |
| 3668 | VkCommandPoolCreateInfo cmd_pool_ci = {}; |
| 3669 | cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3670 | cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3671 | cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3672 | VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, |
| 3673 | nullptr, &cmd_pool); |
| 3674 | ASSERT_VK_SUCCESS(err); |
| 3675 | |
| 3676 | VkCommandBufferAllocateInfo cmd_buf_info = {}; |
| 3677 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3678 | cmd_buf_info.commandPool = cmd_pool; |
| 3679 | cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3680 | cmd_buf_info.commandBufferCount = 1; |
| 3681 | |
| 3682 | VkFenceCreateInfo fence_ci = {}; |
| 3683 | fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3684 | fence_ci.pNext = nullptr; |
| 3685 | fence_ci.flags = 0; |
| 3686 | |
| 3687 | for (uint32_t i = 0; i < NUM_OBJECTS; ++i) { |
| 3688 | err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, |
| 3689 | &cmd_buffers[i]); |
| 3690 | ASSERT_VK_SUCCESS(err); |
| 3691 | err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]); |
| 3692 | ASSERT_VK_SUCCESS(err); |
| 3693 | } |
| 3694 | |
| 3695 | for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) { |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 3696 | for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) { |
| 3697 | // Create empty cmd buffer |
| 3698 | VkCommandBufferBeginInfo cmdBufBeginDesc = {}; |
| 3699 | cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3700 | |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 3701 | err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc); |
| 3702 | ASSERT_VK_SUCCESS(err); |
| 3703 | err = vkEndCommandBuffer(cmd_buffers[obj]); |
| 3704 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3705 | |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 3706 | VkSubmitInfo submit_info = {}; |
| 3707 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3708 | submit_info.commandBufferCount = 1; |
| 3709 | submit_info.pCommandBuffers = &cmd_buffers[obj]; |
| 3710 | // Submit cmd buffer and wait for fence |
| 3711 | err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]); |
| 3712 | ASSERT_VK_SUCCESS(err); |
| 3713 | err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, |
| 3714 | UINT64_MAX); |
| 3715 | ASSERT_VK_SUCCESS(err); |
| 3716 | err = vkResetFences(m_device->device(), 1, &fences[obj]); |
| 3717 | ASSERT_VK_SUCCESS(err); |
| 3718 | } |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3719 | } |
| 3720 | m_errorMonitor->VerifyNotFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 3721 | vkDestroyCommandPool(m_device->device(), cmd_pool, NULL); |
| 3722 | for (uint32_t i = 0; i < NUM_OBJECTS; ++i) { |
| 3723 | vkDestroyFence(m_device->device(), fences[i], nullptr); |
| 3724 | } |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3725 | } |
| 3726 | // This is a positive test. No errors should be generated. |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3727 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) { |
| 3728 | |
| 3729 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 3730 | "submitted on separate queues followed by a QueueWaitIdle."); |
| 3731 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 3732 | if ((m_device->queue_props.empty()) || |
| 3733 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 3734 | return; |
| 3735 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3736 | m_errorMonitor->ExpectSuccess(); |
| 3737 | |
| 3738 | VkSemaphore semaphore; |
| 3739 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 3740 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 3741 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 3742 | &semaphore); |
| 3743 | |
| 3744 | VkCommandPool command_pool; |
| 3745 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3746 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3747 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3748 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3749 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3750 | &command_pool); |
| 3751 | |
| 3752 | VkCommandBuffer command_buffer[2]; |
| 3753 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3754 | command_buffer_allocate_info.sType = |
| 3755 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3756 | command_buffer_allocate_info.commandPool = command_pool; |
| 3757 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3758 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3759 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3760 | command_buffer); |
| 3761 | |
| 3762 | VkQueue queue = VK_NULL_HANDLE; |
| 3763 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3764 | 1, &queue); |
| 3765 | |
| 3766 | { |
| 3767 | VkCommandBufferBeginInfo begin_info{}; |
| 3768 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3769 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3770 | |
| 3771 | vkCmdPipelineBarrier(command_buffer[0], |
| 3772 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3773 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 3774 | 0, nullptr, 0, nullptr); |
| 3775 | |
| 3776 | VkViewport viewport{}; |
| 3777 | viewport.maxDepth = 1.0f; |
| 3778 | viewport.minDepth = 0.0f; |
| 3779 | viewport.width = 512; |
| 3780 | viewport.height = 512; |
| 3781 | viewport.x = 0; |
| 3782 | viewport.y = 0; |
| 3783 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 3784 | vkEndCommandBuffer(command_buffer[0]); |
| 3785 | } |
| 3786 | { |
| 3787 | VkCommandBufferBeginInfo begin_info{}; |
| 3788 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3789 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3790 | |
| 3791 | VkViewport viewport{}; |
| 3792 | viewport.maxDepth = 1.0f; |
| 3793 | viewport.minDepth = 0.0f; |
| 3794 | viewport.width = 512; |
| 3795 | viewport.height = 512; |
| 3796 | viewport.x = 0; |
| 3797 | viewport.y = 0; |
| 3798 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 3799 | vkEndCommandBuffer(command_buffer[1]); |
| 3800 | } |
| 3801 | { |
| 3802 | VkSubmitInfo submit_info{}; |
| 3803 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3804 | submit_info.commandBufferCount = 1; |
| 3805 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 3806 | submit_info.signalSemaphoreCount = 1; |
| 3807 | submit_info.pSignalSemaphores = &semaphore; |
| 3808 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3809 | } |
| 3810 | { |
| 3811 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 3812 | VkSubmitInfo submit_info{}; |
| 3813 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3814 | submit_info.commandBufferCount = 1; |
| 3815 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 3816 | submit_info.waitSemaphoreCount = 1; |
| 3817 | submit_info.pWaitSemaphores = &semaphore; |
| 3818 | submit_info.pWaitDstStageMask = flags; |
| 3819 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3820 | } |
| 3821 | |
| 3822 | vkQueueWaitIdle(m_device->m_queue); |
| 3823 | |
| 3824 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 3825 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 3826 | &command_buffer[0]); |
| 3827 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3828 | |
| 3829 | m_errorMonitor->VerifyNotFound(); |
| 3830 | } |
| 3831 | |
| 3832 | // This is a positive test. No errors should be generated. |
| 3833 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) { |
| 3834 | |
| 3835 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 3836 | "submitted on separate queues, the second having a fence" |
| 3837 | "followed by a QueueWaitIdle."); |
| 3838 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 3839 | if ((m_device->queue_props.empty()) || |
| 3840 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 3841 | return; |
| 3842 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3843 | m_errorMonitor->ExpectSuccess(); |
| 3844 | |
| 3845 | VkFence fence; |
| 3846 | VkFenceCreateInfo fence_create_info{}; |
| 3847 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3848 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 3849 | |
| 3850 | VkSemaphore semaphore; |
| 3851 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 3852 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 3853 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 3854 | &semaphore); |
| 3855 | |
| 3856 | VkCommandPool command_pool; |
| 3857 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3858 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3859 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3860 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3861 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3862 | &command_pool); |
| 3863 | |
| 3864 | VkCommandBuffer command_buffer[2]; |
| 3865 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3866 | command_buffer_allocate_info.sType = |
| 3867 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3868 | command_buffer_allocate_info.commandPool = command_pool; |
| 3869 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3870 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3871 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3872 | command_buffer); |
| 3873 | |
| 3874 | VkQueue queue = VK_NULL_HANDLE; |
| 3875 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3876 | 1, &queue); |
| 3877 | |
| 3878 | { |
| 3879 | VkCommandBufferBeginInfo begin_info{}; |
| 3880 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3881 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3882 | |
| 3883 | vkCmdPipelineBarrier(command_buffer[0], |
| 3884 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3885 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 3886 | 0, nullptr, 0, nullptr); |
| 3887 | |
| 3888 | VkViewport viewport{}; |
| 3889 | viewport.maxDepth = 1.0f; |
| 3890 | viewport.minDepth = 0.0f; |
| 3891 | viewport.width = 512; |
| 3892 | viewport.height = 512; |
| 3893 | viewport.x = 0; |
| 3894 | viewport.y = 0; |
| 3895 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 3896 | vkEndCommandBuffer(command_buffer[0]); |
| 3897 | } |
| 3898 | { |
| 3899 | VkCommandBufferBeginInfo begin_info{}; |
| 3900 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3901 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3902 | |
| 3903 | VkViewport viewport{}; |
| 3904 | viewport.maxDepth = 1.0f; |
| 3905 | viewport.minDepth = 0.0f; |
| 3906 | viewport.width = 512; |
| 3907 | viewport.height = 512; |
| 3908 | viewport.x = 0; |
| 3909 | viewport.y = 0; |
| 3910 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 3911 | vkEndCommandBuffer(command_buffer[1]); |
| 3912 | } |
| 3913 | { |
| 3914 | VkSubmitInfo submit_info{}; |
| 3915 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3916 | submit_info.commandBufferCount = 1; |
| 3917 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 3918 | submit_info.signalSemaphoreCount = 1; |
| 3919 | submit_info.pSignalSemaphores = &semaphore; |
| 3920 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3921 | } |
| 3922 | { |
| 3923 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 3924 | VkSubmitInfo submit_info{}; |
| 3925 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3926 | submit_info.commandBufferCount = 1; |
| 3927 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 3928 | submit_info.waitSemaphoreCount = 1; |
| 3929 | submit_info.pWaitSemaphores = &semaphore; |
| 3930 | submit_info.pWaitDstStageMask = flags; |
| 3931 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 3932 | } |
| 3933 | |
| 3934 | vkQueueWaitIdle(m_device->m_queue); |
| 3935 | |
| 3936 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 3937 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 3938 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 3939 | &command_buffer[0]); |
| 3940 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3941 | |
| 3942 | m_errorMonitor->VerifyNotFound(); |
| 3943 | } |
| 3944 | |
| 3945 | // This is a positive test. No errors should be generated. |
| 3946 | TEST_F(VkLayerTest, |
| 3947 | TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) { |
| 3948 | |
| 3949 | TEST_DESCRIPTION( |
| 3950 | "Two command buffers, each in a separate QueueSubmit call " |
| 3951 | "submitted on separate queues, the second having a fence" |
| 3952 | "followed by two consecutive WaitForFences calls on the same fence."); |
| 3953 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 3954 | if ((m_device->queue_props.empty()) || |
| 3955 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 3956 | return; |
| 3957 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3958 | m_errorMonitor->ExpectSuccess(); |
| 3959 | |
| 3960 | VkFence fence; |
| 3961 | VkFenceCreateInfo fence_create_info{}; |
| 3962 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3963 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 3964 | |
| 3965 | VkSemaphore semaphore; |
| 3966 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 3967 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 3968 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 3969 | &semaphore); |
| 3970 | |
| 3971 | VkCommandPool command_pool; |
| 3972 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3973 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3974 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3975 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3976 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3977 | &command_pool); |
| 3978 | |
| 3979 | VkCommandBuffer command_buffer[2]; |
| 3980 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3981 | command_buffer_allocate_info.sType = |
| 3982 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3983 | command_buffer_allocate_info.commandPool = command_pool; |
| 3984 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3985 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3986 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3987 | command_buffer); |
| 3988 | |
| 3989 | VkQueue queue = VK_NULL_HANDLE; |
| 3990 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3991 | 1, &queue); |
| 3992 | |
| 3993 | { |
| 3994 | VkCommandBufferBeginInfo begin_info{}; |
| 3995 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3996 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3997 | |
| 3998 | vkCmdPipelineBarrier(command_buffer[0], |
| 3999 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4000 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4001 | 0, nullptr, 0, nullptr); |
| 4002 | |
| 4003 | VkViewport viewport{}; |
| 4004 | viewport.maxDepth = 1.0f; |
| 4005 | viewport.minDepth = 0.0f; |
| 4006 | viewport.width = 512; |
| 4007 | viewport.height = 512; |
| 4008 | viewport.x = 0; |
| 4009 | viewport.y = 0; |
| 4010 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4011 | vkEndCommandBuffer(command_buffer[0]); |
| 4012 | } |
| 4013 | { |
| 4014 | VkCommandBufferBeginInfo begin_info{}; |
| 4015 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4016 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4017 | |
| 4018 | VkViewport viewport{}; |
| 4019 | viewport.maxDepth = 1.0f; |
| 4020 | viewport.minDepth = 0.0f; |
| 4021 | viewport.width = 512; |
| 4022 | viewport.height = 512; |
| 4023 | viewport.x = 0; |
| 4024 | viewport.y = 0; |
| 4025 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4026 | vkEndCommandBuffer(command_buffer[1]); |
| 4027 | } |
| 4028 | { |
| 4029 | VkSubmitInfo submit_info{}; |
| 4030 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4031 | submit_info.commandBufferCount = 1; |
| 4032 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4033 | submit_info.signalSemaphoreCount = 1; |
| 4034 | submit_info.pSignalSemaphores = &semaphore; |
| 4035 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4036 | } |
| 4037 | { |
| 4038 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4039 | VkSubmitInfo submit_info{}; |
| 4040 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4041 | submit_info.commandBufferCount = 1; |
| 4042 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4043 | submit_info.waitSemaphoreCount = 1; |
| 4044 | submit_info.pWaitSemaphores = &semaphore; |
| 4045 | submit_info.pWaitDstStageMask = flags; |
| 4046 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4047 | } |
| 4048 | |
| 4049 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4050 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4051 | |
| 4052 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4053 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4054 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4055 | &command_buffer[0]); |
| 4056 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4057 | |
| 4058 | m_errorMonitor->VerifyNotFound(); |
| 4059 | } |
| 4060 | |
| 4061 | // This is a positive test. No errors should be generated. |
| 4062 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) { |
| 4063 | |
| 4064 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4065 | "submitted on separate queues, the second having a fence, " |
| 4066 | "followed by a WaitForFences call."); |
| 4067 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 4068 | if ((m_device->queue_props.empty()) || |
| 4069 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 4070 | return; |
| 4071 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4072 | m_errorMonitor->ExpectSuccess(); |
| 4073 | |
| 4074 | VkFence fence; |
| 4075 | VkFenceCreateInfo fence_create_info{}; |
| 4076 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4077 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4078 | |
| 4079 | VkSemaphore semaphore; |
| 4080 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4081 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4082 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4083 | &semaphore); |
| 4084 | |
| 4085 | VkCommandPool command_pool; |
| 4086 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4087 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4088 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4089 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4090 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4091 | &command_pool); |
| 4092 | |
| 4093 | VkCommandBuffer command_buffer[2]; |
| 4094 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4095 | command_buffer_allocate_info.sType = |
| 4096 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4097 | command_buffer_allocate_info.commandPool = command_pool; |
| 4098 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4099 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4100 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4101 | command_buffer); |
| 4102 | |
| 4103 | VkQueue queue = VK_NULL_HANDLE; |
| 4104 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4105 | 1, &queue); |
| 4106 | |
| 4107 | |
| 4108 | { |
| 4109 | VkCommandBufferBeginInfo begin_info{}; |
| 4110 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4111 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4112 | |
| 4113 | vkCmdPipelineBarrier(command_buffer[0], |
| 4114 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4115 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4116 | 0, nullptr, 0, nullptr); |
| 4117 | |
| 4118 | VkViewport viewport{}; |
| 4119 | viewport.maxDepth = 1.0f; |
| 4120 | viewport.minDepth = 0.0f; |
| 4121 | viewport.width = 512; |
| 4122 | viewport.height = 512; |
| 4123 | viewport.x = 0; |
| 4124 | viewport.y = 0; |
| 4125 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4126 | vkEndCommandBuffer(command_buffer[0]); |
| 4127 | } |
| 4128 | { |
| 4129 | VkCommandBufferBeginInfo begin_info{}; |
| 4130 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4131 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4132 | |
| 4133 | VkViewport viewport{}; |
| 4134 | viewport.maxDepth = 1.0f; |
| 4135 | viewport.minDepth = 0.0f; |
| 4136 | viewport.width = 512; |
| 4137 | viewport.height = 512; |
| 4138 | viewport.x = 0; |
| 4139 | viewport.y = 0; |
| 4140 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4141 | vkEndCommandBuffer(command_buffer[1]); |
| 4142 | } |
| 4143 | { |
| 4144 | VkSubmitInfo submit_info{}; |
| 4145 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4146 | submit_info.commandBufferCount = 1; |
| 4147 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4148 | submit_info.signalSemaphoreCount = 1; |
| 4149 | submit_info.pSignalSemaphores = &semaphore; |
| 4150 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4151 | } |
| 4152 | { |
| 4153 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4154 | VkSubmitInfo submit_info{}; |
| 4155 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4156 | submit_info.commandBufferCount = 1; |
| 4157 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4158 | submit_info.waitSemaphoreCount = 1; |
| 4159 | submit_info.pWaitSemaphores = &semaphore; |
| 4160 | submit_info.pWaitDstStageMask = flags; |
| 4161 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4162 | } |
| 4163 | |
| 4164 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4165 | |
| 4166 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4167 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4168 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4169 | &command_buffer[0]); |
| 4170 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4171 | |
| 4172 | m_errorMonitor->VerifyNotFound(); |
| 4173 | } |
| 4174 | |
| 4175 | // This is a positive test. No errors should be generated. |
| 4176 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) { |
| 4177 | |
| 4178 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4179 | "on the same queue, sharing a signal/wait semaphore, the " |
| 4180 | "second having a fence, " |
| 4181 | "followed by a WaitForFences call."); |
| 4182 | |
| 4183 | m_errorMonitor->ExpectSuccess(); |
| 4184 | |
| 4185 | VkFence fence; |
| 4186 | VkFenceCreateInfo fence_create_info{}; |
| 4187 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4188 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4189 | |
| 4190 | VkSemaphore semaphore; |
| 4191 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4192 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4193 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4194 | &semaphore); |
| 4195 | |
| 4196 | VkCommandPool command_pool; |
| 4197 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4198 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4199 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4200 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4201 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4202 | &command_pool); |
| 4203 | |
| 4204 | VkCommandBuffer command_buffer[2]; |
| 4205 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4206 | command_buffer_allocate_info.sType = |
| 4207 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4208 | command_buffer_allocate_info.commandPool = command_pool; |
| 4209 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4210 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4211 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4212 | command_buffer); |
| 4213 | |
| 4214 | { |
| 4215 | VkCommandBufferBeginInfo begin_info{}; |
| 4216 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4217 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4218 | |
| 4219 | vkCmdPipelineBarrier(command_buffer[0], |
| 4220 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4221 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4222 | 0, nullptr, 0, nullptr); |
| 4223 | |
| 4224 | VkViewport viewport{}; |
| 4225 | viewport.maxDepth = 1.0f; |
| 4226 | viewport.minDepth = 0.0f; |
| 4227 | viewport.width = 512; |
| 4228 | viewport.height = 512; |
| 4229 | viewport.x = 0; |
| 4230 | viewport.y = 0; |
| 4231 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4232 | vkEndCommandBuffer(command_buffer[0]); |
| 4233 | } |
| 4234 | { |
| 4235 | VkCommandBufferBeginInfo begin_info{}; |
| 4236 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4237 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4238 | |
| 4239 | VkViewport viewport{}; |
| 4240 | viewport.maxDepth = 1.0f; |
| 4241 | viewport.minDepth = 0.0f; |
| 4242 | viewport.width = 512; |
| 4243 | viewport.height = 512; |
| 4244 | viewport.x = 0; |
| 4245 | viewport.y = 0; |
| 4246 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4247 | vkEndCommandBuffer(command_buffer[1]); |
| 4248 | } |
| 4249 | { |
| 4250 | VkSubmitInfo submit_info{}; |
| 4251 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4252 | submit_info.commandBufferCount = 1; |
| 4253 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4254 | submit_info.signalSemaphoreCount = 1; |
| 4255 | submit_info.pSignalSemaphores = &semaphore; |
| 4256 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4257 | } |
| 4258 | { |
| 4259 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4260 | VkSubmitInfo submit_info{}; |
| 4261 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4262 | submit_info.commandBufferCount = 1; |
| 4263 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4264 | submit_info.waitSemaphoreCount = 1; |
| 4265 | submit_info.pWaitSemaphores = &semaphore; |
| 4266 | submit_info.pWaitDstStageMask = flags; |
| 4267 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4268 | } |
| 4269 | |
| 4270 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4271 | |
| 4272 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4273 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4274 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4275 | &command_buffer[0]); |
| 4276 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4277 | |
| 4278 | m_errorMonitor->VerifyNotFound(); |
| 4279 | } |
| 4280 | |
| 4281 | // This is a positive test. No errors should be generated. |
| 4282 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) { |
| 4283 | |
| 4284 | TEST_DESCRIPTION( |
| 4285 | "Two command buffers, each in a separate QueueSubmit call " |
| 4286 | "on the same queue, no fences, followed by a third QueueSubmit with NO " |
| 4287 | "SubmitInfos but with a fence, followed by a WaitForFences call."); |
| 4288 | |
| 4289 | m_errorMonitor->ExpectSuccess(); |
| 4290 | |
| 4291 | VkFence fence; |
| 4292 | VkFenceCreateInfo fence_create_info{}; |
| 4293 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4294 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4295 | |
| 4296 | VkCommandPool command_pool; |
| 4297 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4298 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4299 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4300 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4301 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4302 | &command_pool); |
| 4303 | |
| 4304 | VkCommandBuffer command_buffer[2]; |
| 4305 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4306 | command_buffer_allocate_info.sType = |
| 4307 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4308 | command_buffer_allocate_info.commandPool = command_pool; |
| 4309 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4310 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4311 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4312 | command_buffer); |
| 4313 | |
| 4314 | { |
| 4315 | VkCommandBufferBeginInfo begin_info{}; |
| 4316 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4317 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4318 | |
| 4319 | vkCmdPipelineBarrier(command_buffer[0], |
| 4320 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4321 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4322 | 0, nullptr, 0, nullptr); |
| 4323 | |
| 4324 | VkViewport viewport{}; |
| 4325 | viewport.maxDepth = 1.0f; |
| 4326 | viewport.minDepth = 0.0f; |
| 4327 | viewport.width = 512; |
| 4328 | viewport.height = 512; |
| 4329 | viewport.x = 0; |
| 4330 | viewport.y = 0; |
| 4331 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4332 | vkEndCommandBuffer(command_buffer[0]); |
| 4333 | } |
| 4334 | { |
| 4335 | VkCommandBufferBeginInfo begin_info{}; |
| 4336 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4337 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4338 | |
| 4339 | VkViewport viewport{}; |
| 4340 | viewport.maxDepth = 1.0f; |
| 4341 | viewport.minDepth = 0.0f; |
| 4342 | viewport.width = 512; |
| 4343 | viewport.height = 512; |
| 4344 | viewport.x = 0; |
| 4345 | viewport.y = 0; |
| 4346 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4347 | vkEndCommandBuffer(command_buffer[1]); |
| 4348 | } |
| 4349 | { |
| 4350 | VkSubmitInfo submit_info{}; |
| 4351 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4352 | submit_info.commandBufferCount = 1; |
| 4353 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4354 | submit_info.signalSemaphoreCount = 0; |
| 4355 | submit_info.pSignalSemaphores = VK_NULL_HANDLE; |
| 4356 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4357 | } |
| 4358 | { |
| 4359 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4360 | VkSubmitInfo submit_info{}; |
| 4361 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4362 | submit_info.commandBufferCount = 1; |
| 4363 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4364 | submit_info.waitSemaphoreCount = 0; |
| 4365 | submit_info.pWaitSemaphores = VK_NULL_HANDLE; |
| 4366 | submit_info.pWaitDstStageMask = flags; |
| 4367 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4368 | } |
| 4369 | |
| 4370 | vkQueueSubmit(m_device->m_queue, 0, NULL, fence); |
| 4371 | |
| 4372 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4373 | |
| 4374 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4375 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4376 | &command_buffer[0]); |
| 4377 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4378 | |
| 4379 | m_errorMonitor->VerifyNotFound(); |
| 4380 | } |
| 4381 | |
| 4382 | // This is a positive test. No errors should be generated. |
| 4383 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) { |
| 4384 | |
| 4385 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4386 | "on the same queue, the second having a fence, followed " |
| 4387 | "by a WaitForFences call."); |
| 4388 | |
| 4389 | m_errorMonitor->ExpectSuccess(); |
| 4390 | |
| 4391 | VkFence fence; |
| 4392 | VkFenceCreateInfo fence_create_info{}; |
| 4393 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4394 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4395 | |
| 4396 | VkCommandPool command_pool; |
| 4397 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4398 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4399 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4400 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4401 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4402 | &command_pool); |
| 4403 | |
| 4404 | VkCommandBuffer command_buffer[2]; |
| 4405 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4406 | command_buffer_allocate_info.sType = |
| 4407 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4408 | command_buffer_allocate_info.commandPool = command_pool; |
| 4409 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4410 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4411 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4412 | command_buffer); |
| 4413 | |
| 4414 | { |
| 4415 | VkCommandBufferBeginInfo begin_info{}; |
| 4416 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4417 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4418 | |
| 4419 | vkCmdPipelineBarrier(command_buffer[0], |
| 4420 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4421 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4422 | 0, nullptr, 0, nullptr); |
| 4423 | |
| 4424 | VkViewport viewport{}; |
| 4425 | viewport.maxDepth = 1.0f; |
| 4426 | viewport.minDepth = 0.0f; |
| 4427 | viewport.width = 512; |
| 4428 | viewport.height = 512; |
| 4429 | viewport.x = 0; |
| 4430 | viewport.y = 0; |
| 4431 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4432 | vkEndCommandBuffer(command_buffer[0]); |
| 4433 | } |
| 4434 | { |
| 4435 | VkCommandBufferBeginInfo begin_info{}; |
| 4436 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4437 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4438 | |
| 4439 | VkViewport viewport{}; |
| 4440 | viewport.maxDepth = 1.0f; |
| 4441 | viewport.minDepth = 0.0f; |
| 4442 | viewport.width = 512; |
| 4443 | viewport.height = 512; |
| 4444 | viewport.x = 0; |
| 4445 | viewport.y = 0; |
| 4446 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4447 | vkEndCommandBuffer(command_buffer[1]); |
| 4448 | } |
| 4449 | { |
| 4450 | VkSubmitInfo submit_info{}; |
| 4451 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4452 | submit_info.commandBufferCount = 1; |
| 4453 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4454 | submit_info.signalSemaphoreCount = 0; |
| 4455 | submit_info.pSignalSemaphores = VK_NULL_HANDLE; |
| 4456 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4457 | } |
| 4458 | { |
| 4459 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4460 | VkSubmitInfo submit_info{}; |
| 4461 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4462 | submit_info.commandBufferCount = 1; |
| 4463 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4464 | submit_info.waitSemaphoreCount = 0; |
| 4465 | submit_info.pWaitSemaphores = VK_NULL_HANDLE; |
| 4466 | submit_info.pWaitDstStageMask = flags; |
| 4467 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4468 | } |
| 4469 | |
| 4470 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4471 | |
| 4472 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4473 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4474 | &command_buffer[0]); |
| 4475 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4476 | |
| 4477 | m_errorMonitor->VerifyNotFound(); |
| 4478 | } |
| 4479 | |
| 4480 | // This is a positive test. No errors should be generated. |
| 4481 | TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) { |
| 4482 | |
| 4483 | TEST_DESCRIPTION( |
| 4484 | "Two command buffers each in a separate SubmitInfo sent in a single " |
| 4485 | "QueueSubmit call followed by a WaitForFences call."); |
| 4486 | |
| 4487 | m_errorMonitor->ExpectSuccess(); |
| 4488 | |
| 4489 | VkFence fence; |
| 4490 | VkFenceCreateInfo fence_create_info{}; |
| 4491 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4492 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4493 | |
| 4494 | VkSemaphore semaphore; |
| 4495 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4496 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4497 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4498 | &semaphore); |
| 4499 | |
| 4500 | VkCommandPool command_pool; |
| 4501 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4502 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4503 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4504 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4505 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4506 | &command_pool); |
| 4507 | |
| 4508 | VkCommandBuffer command_buffer[2]; |
| 4509 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4510 | command_buffer_allocate_info.sType = |
| 4511 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4512 | command_buffer_allocate_info.commandPool = command_pool; |
| 4513 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4514 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4515 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4516 | command_buffer); |
| 4517 | |
| 4518 | { |
| 4519 | VkCommandBufferBeginInfo begin_info{}; |
| 4520 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4521 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4522 | |
| 4523 | vkCmdPipelineBarrier(command_buffer[0], |
| 4524 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4525 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4526 | 0, nullptr, 0, nullptr); |
| 4527 | |
| 4528 | VkViewport viewport{}; |
| 4529 | viewport.maxDepth = 1.0f; |
| 4530 | viewport.minDepth = 0.0f; |
| 4531 | viewport.width = 512; |
| 4532 | viewport.height = 512; |
| 4533 | viewport.x = 0; |
| 4534 | viewport.y = 0; |
| 4535 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4536 | vkEndCommandBuffer(command_buffer[0]); |
| 4537 | } |
| 4538 | { |
| 4539 | VkCommandBufferBeginInfo begin_info{}; |
| 4540 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4541 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4542 | |
| 4543 | VkViewport viewport{}; |
| 4544 | viewport.maxDepth = 1.0f; |
| 4545 | viewport.minDepth = 0.0f; |
| 4546 | viewport.width = 512; |
| 4547 | viewport.height = 512; |
| 4548 | viewport.x = 0; |
| 4549 | viewport.y = 0; |
| 4550 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4551 | vkEndCommandBuffer(command_buffer[1]); |
| 4552 | } |
| 4553 | { |
| 4554 | VkSubmitInfo submit_info[2]; |
| 4555 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4556 | |
| 4557 | submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4558 | submit_info[0].pNext = NULL; |
| 4559 | submit_info[0].commandBufferCount = 1; |
| 4560 | submit_info[0].pCommandBuffers = &command_buffer[0]; |
| 4561 | submit_info[0].signalSemaphoreCount = 1; |
| 4562 | submit_info[0].pSignalSemaphores = &semaphore; |
| 4563 | submit_info[0].waitSemaphoreCount = 0; |
| 4564 | submit_info[0].pWaitSemaphores = NULL; |
| 4565 | submit_info[0].pWaitDstStageMask = 0; |
| 4566 | |
| 4567 | submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4568 | submit_info[1].pNext = NULL; |
| 4569 | submit_info[1].commandBufferCount = 1; |
| 4570 | submit_info[1].pCommandBuffers = &command_buffer[1]; |
| 4571 | submit_info[1].waitSemaphoreCount = 1; |
| 4572 | submit_info[1].pWaitSemaphores = &semaphore; |
| 4573 | submit_info[1].pWaitDstStageMask = flags; |
| 4574 | submit_info[1].signalSemaphoreCount = 0; |
| 4575 | submit_info[1].pSignalSemaphores = NULL; |
| 4576 | vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence); |
| 4577 | } |
| 4578 | |
| 4579 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4580 | |
| 4581 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4582 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4583 | &command_buffer[0]); |
| 4584 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 4585 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4586 | |
| 4587 | m_errorMonitor->VerifyNotFound(); |
| 4588 | } |
| 4589 | |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4590 | TEST_F(VkLayerTest, DynamicDepthBiasNotBound) { |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4591 | TEST_DESCRIPTION( |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4592 | "Run a simple draw calls to validate failure when Depth Bias dynamic " |
| 4593 | "state is required but not correctly bound."); |
| 4594 | |
| 4595 | // Dynamic depth bias |
| 4596 | m_errorMonitor->SetDesiredFailureMsg( |
| 4597 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4598 | "Dynamic depth bias state not set for this command buffer"); |
| 4599 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4600 | BsoFailDepthBias); |
| 4601 | m_errorMonitor->VerifyFound(); |
| 4602 | } |
| 4603 | |
| 4604 | TEST_F(VkLayerTest, DynamicLineWidthNotBound) { |
| 4605 | TEST_DESCRIPTION( |
| 4606 | "Run a simple draw calls to validate failure when Line Width dynamic " |
| 4607 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4608 | |
| 4609 | // Dynamic line width |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4610 | m_errorMonitor->SetDesiredFailureMsg( |
| 4611 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4612 | "Dynamic line width state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4613 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4614 | BsoFailLineWidth); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4615 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4616 | } |
| 4617 | |
| 4618 | TEST_F(VkLayerTest, DynamicViewportNotBound) { |
| 4619 | TEST_DESCRIPTION( |
| 4620 | "Run a simple draw calls to validate failure when Viewport dynamic " |
| 4621 | "state is required but not correctly bound."); |
| 4622 | |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4623 | // Dynamic viewport state |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4624 | m_errorMonitor->SetDesiredFailureMsg( |
| 4625 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4626 | "Dynamic viewport state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4627 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4628 | BsoFailViewport); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4629 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4630 | } |
| 4631 | |
| 4632 | TEST_F(VkLayerTest, DynamicScissorNotBound) { |
| 4633 | TEST_DESCRIPTION( |
| 4634 | "Run a simple draw calls to validate failure when Scissor dynamic " |
| 4635 | "state is required but not correctly bound."); |
| 4636 | |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4637 | // Dynamic scissor state |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4638 | m_errorMonitor->SetDesiredFailureMsg( |
| 4639 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4640 | "Dynamic scissor state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4641 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4642 | BsoFailScissor); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4643 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4644 | } |
| 4645 | |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 4646 | TEST_F(VkLayerTest, DynamiBlendConstantsNotBound) { |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4647 | TEST_DESCRIPTION( |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 4648 | "Run a simple draw calls to validate failure when Blend Constants " |
| 4649 | "dynamic state is required but not correctly bound."); |
| 4650 | // Dynamic blend constant state |
| 4651 | m_errorMonitor->SetDesiredFailureMsg( |
| 4652 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4653 | "Dynamic blend constants state not set for this command buffer"); |
| 4654 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4655 | BsoFailBlend); |
| 4656 | m_errorMonitor->VerifyFound(); |
| 4657 | } |
| 4658 | |
| 4659 | TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) { |
| 4660 | TEST_DESCRIPTION( |
| 4661 | "Run a simple draw calls to validate failure when Depth Bounds dynamic " |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4662 | "state is required but not correctly bound."); |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 4663 | if (!m_device->phy().features().depthBounds) { |
| 4664 | printf("Device does not support depthBounds test; skipped.\n"); |
| 4665 | return; |
| 4666 | } |
| 4667 | // Dynamic depth bounds |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4668 | m_errorMonitor->SetDesiredFailureMsg( |
| 4669 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4670 | "Dynamic depth bounds state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4671 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4672 | BsoFailDepthBounds); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4673 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4674 | } |
| 4675 | |
| 4676 | TEST_F(VkLayerTest, DynamicStencilReadNotBound) { |
| 4677 | TEST_DESCRIPTION( |
| 4678 | "Run a simple draw calls to validate failure when Stencil Read dynamic " |
| 4679 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4680 | // Dynamic stencil read mask |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4681 | m_errorMonitor->SetDesiredFailureMsg( |
| 4682 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4683 | "Dynamic stencil read mask state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4684 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4685 | BsoFailStencilReadMask); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4686 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4687 | } |
| 4688 | |
| 4689 | TEST_F(VkLayerTest, DynamicStencilWriteNotBound) { |
| 4690 | TEST_DESCRIPTION( |
| 4691 | "Run a simple draw calls to validate failure when Stencil Write dynamic" |
| 4692 | " state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4693 | // Dynamic stencil write mask |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4694 | m_errorMonitor->SetDesiredFailureMsg( |
| 4695 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4696 | "Dynamic stencil write mask state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4697 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4698 | BsoFailStencilWriteMask); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4699 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4700 | } |
| 4701 | |
| 4702 | TEST_F(VkLayerTest, DynamicStencilRefNotBound) { |
| 4703 | TEST_DESCRIPTION( |
| 4704 | "Run a simple draw calls to validate failure when Stencil Ref dynamic " |
| 4705 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4706 | // Dynamic stencil reference |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4707 | m_errorMonitor->SetDesiredFailureMsg( |
| 4708 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4709 | "Dynamic stencil reference state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4710 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4711 | BsoFailStencilReference); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4712 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 963a404 | 2015-09-29 08:18:34 -0600 | [diff] [blame] | 4713 | } |
| 4714 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4715 | TEST_F(VkLayerTest, CommandBufferTwoSubmits) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4716 | m_errorMonitor->SetDesiredFailureMsg( |
| 4717 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4718 | "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has " |
| 4719 | "been submitted"); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4720 | |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4721 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4722 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 4723 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 4724 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4725 | // We luck out b/c by default the framework creates CB w/ the |
| 4726 | // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4727 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4728 | m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 4729 | m_stencil_clear_color, NULL); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4730 | EndCommandBuffer(); |
| 4731 | |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4732 | // Bypass framework since it does the waits automatically |
| 4733 | VkResult err = VK_SUCCESS; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 4734 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 4735 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4736 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 4737 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 4738 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 4739 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 4740 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 4741 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 4742 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 4743 | submit_info.pSignalSemaphores = NULL; |
| 4744 | |
Chris Forbes | 40028e2 | 2016-06-13 09:59:34 +1200 | [diff] [blame] | 4745 | err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4746 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4747 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4748 | // Cause validation error by re-submitting cmd buffer that should only be |
| 4749 | // submitted once |
Chris Forbes | 40028e2 | 2016-06-13 09:59:34 +1200 | [diff] [blame] | 4750 | err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4751 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4752 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4753 | } |
| 4754 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4755 | TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) { |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4756 | // Initiate Draw w/o a PSO bound |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4757 | VkResult err; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4758 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 4759 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4760 | "Unable to allocate 1 descriptors of " |
| 4761 | "type " |
| 4762 | "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4763 | |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4764 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4765 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4766 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4767 | // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer |
| 4768 | // descriptor from it |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 4769 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4770 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 4771 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4772 | |
| 4773 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4774 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 4775 | ds_pool_ci.pNext = NULL; |
| 4776 | ds_pool_ci.flags = 0; |
| 4777 | ds_pool_ci.maxSets = 1; |
| 4778 | ds_pool_ci.poolSizeCount = 1; |
| 4779 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4780 | |
| 4781 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4782 | err = |
| 4783 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4784 | ASSERT_VK_SUCCESS(err); |
| 4785 | |
| 4786 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4787 | dsl_binding.binding = 0; |
| 4788 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4789 | dsl_binding.descriptorCount = 1; |
| 4790 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 4791 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4792 | |
| 4793 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4794 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4795 | ds_layout_ci.pNext = NULL; |
| 4796 | ds_layout_ci.bindingCount = 1; |
| 4797 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4798 | |
| 4799 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4800 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 4801 | &ds_layout); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4802 | ASSERT_VK_SUCCESS(err); |
| 4803 | |
| 4804 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 4805 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 4806 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4807 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 4808 | alloc_info.descriptorPool = ds_pool; |
| 4809 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4810 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 4811 | &descriptorSet); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4812 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4813 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4814 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 4815 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 4816 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4817 | } |
| 4818 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4819 | TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) { |
| 4820 | VkResult err; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4821 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4822 | m_errorMonitor->SetDesiredFailureMsg( |
| 4823 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4824 | "It is invalid to call vkFreeDescriptorSets() with a pool created " |
| 4825 | "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4826 | |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4827 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4828 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4829 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 4830 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4831 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4832 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4833 | |
| 4834 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4835 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 4836 | ds_pool_ci.pNext = NULL; |
| 4837 | ds_pool_ci.maxSets = 1; |
| 4838 | ds_pool_ci.poolSizeCount = 1; |
| 4839 | ds_pool_ci.flags = 0; |
| 4840 | // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means |
| 4841 | // app can only call vkResetDescriptorPool on this pool.; |
| 4842 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4843 | |
| 4844 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4845 | err = |
| 4846 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4847 | ASSERT_VK_SUCCESS(err); |
| 4848 | |
| 4849 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4850 | dsl_binding.binding = 0; |
| 4851 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4852 | dsl_binding.descriptorCount = 1; |
| 4853 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 4854 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4855 | |
| 4856 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4857 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4858 | ds_layout_ci.pNext = NULL; |
| 4859 | ds_layout_ci.bindingCount = 1; |
| 4860 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4861 | |
| 4862 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4863 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 4864 | &ds_layout); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4865 | ASSERT_VK_SUCCESS(err); |
| 4866 | |
| 4867 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 4868 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 4869 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4870 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 4871 | alloc_info.descriptorPool = ds_pool; |
| 4872 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4873 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 4874 | &descriptorSet); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4875 | ASSERT_VK_SUCCESS(err); |
| 4876 | |
| 4877 | err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4878 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4879 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 4880 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 4881 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4882 | } |
| 4883 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4884 | TEST_F(VkLayerTest, InvalidDescriptorPool) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4885 | // Attempt to clear Descriptor Pool with bad object. |
| 4886 | // ObjectTracker should catch this. |
| 4887 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4888 | "Invalid VkDescriptorPool Object 0xbaad6001"); |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4889 | uint64_t fake_pool_handle = 0xbaad6001; |
| 4890 | VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle); |
| 4891 | vkResetDescriptorPool(device(), bad_pool, 0); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4892 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4893 | } |
| 4894 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4895 | TEST_F(VkLayerTest, InvalidDescriptorSet) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4896 | // Attempt to bind an invalid Descriptor Set to a valid Command Buffer |
| 4897 | // ObjectTracker should catch this. |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4898 | // Create a valid cmd buffer |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4899 | // call vkCmdBindDescriptorSets w/ false Descriptor Set |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4900 | |
| 4901 | uint64_t fake_set_handle = 0xbaad6001; |
| 4902 | VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4903 | VkResult err; |
| 4904 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4905 | "Invalid VkDescriptorSet Object 0xbaad6001"); |
| 4906 | |
| 4907 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4908 | |
| 4909 | VkDescriptorSetLayoutBinding layout_bindings[1] = {}; |
| 4910 | layout_bindings[0].binding = 0; |
| 4911 | layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4912 | layout_bindings[0].descriptorCount = 1; |
| 4913 | layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; |
| 4914 | layout_bindings[0].pImmutableSamplers = NULL; |
| 4915 | |
| 4916 | VkDescriptorSetLayout descriptor_set_layout; |
| 4917 | VkDescriptorSetLayoutCreateInfo dslci = {}; |
| 4918 | dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4919 | dslci.pNext = NULL; |
| 4920 | dslci.bindingCount = 1; |
| 4921 | dslci.pBindings = layout_bindings; |
| 4922 | err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout); |
Karl Schultz | 5cb2111 | 2016-04-21 17:17:40 -0600 | [diff] [blame] | 4923 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4924 | |
| 4925 | VkPipelineLayout pipeline_layout; |
| 4926 | VkPipelineLayoutCreateInfo plci = {}; |
| 4927 | plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 4928 | plci.pNext = NULL; |
| 4929 | plci.setLayoutCount = 1; |
| 4930 | plci.pSetLayouts = &descriptor_set_layout; |
| 4931 | err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout); |
Karl Schultz | 5cb2111 | 2016-04-21 17:17:40 -0600 | [diff] [blame] | 4932 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4933 | |
| 4934 | BeginCommandBuffer(); |
| 4935 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4936 | pipeline_layout, 0, 1, &bad_set, 0, NULL); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4937 | m_errorMonitor->VerifyFound(); |
| 4938 | EndCommandBuffer(); |
| 4939 | vkDestroyPipelineLayout(device(), pipeline_layout, NULL); |
| 4940 | vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4941 | } |
| 4942 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4943 | TEST_F(VkLayerTest, InvalidDescriptorSetLayout) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4944 | // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout. |
| 4945 | // ObjectTracker should catch this. |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4946 | uint64_t fake_layout_handle = 0xbaad6001; |
| 4947 | VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4948 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4949 | "Invalid VkDescriptorSetLayout Object 0xbaad6001"); |
| 4950 | |
| 4951 | VkPipelineLayout pipeline_layout; |
| 4952 | VkPipelineLayoutCreateInfo plci = {}; |
| 4953 | plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 4954 | plci.pNext = NULL; |
| 4955 | plci.setLayoutCount = 1; |
| 4956 | plci.pSetLayouts = &bad_layout; |
| 4957 | vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout); |
| 4958 | |
| 4959 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4960 | } |
| 4961 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4962 | TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) { |
| 4963 | TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec " |
| 4964 | "1) A uniform buffer update must have a valid buffer index." |
| 4965 | "2) When using an array of descriptors in a single WriteDescriptor," |
| 4966 | " the descriptor types and stageflags must all be the same." |
| 4967 | "3) Immutable Sampler state must match across descriptors"); |
| 4968 | |
| 4969 | const char *invalid_BufferInfo_ErrorMessage = |
| 4970 | "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, " |
| 4971 | "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or " |
| 4972 | "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL"; |
| 4973 | const char *stateFlag_ErrorMessage = |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 4974 | "Attempting write update to descriptor set "; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4975 | const char *immutable_ErrorMessage = |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 4976 | "Attempting write update to descriptor set "; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4977 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4978 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage); |
| 4979 | |
| 4980 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4981 | VkDescriptorPoolSize ds_type_count[4] = {}; |
| 4982 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4983 | ds_type_count[0].descriptorCount = 1; |
| 4984 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 4985 | ds_type_count[1].descriptorCount = 1; |
| 4986 | ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 4987 | ds_type_count[2].descriptorCount = 1; |
| 4988 | ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 4989 | ds_type_count[3].descriptorCount = 1; |
| 4990 | |
| 4991 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 4992 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 4993 | ds_pool_ci.maxSets = 1; |
| 4994 | ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize); |
| 4995 | ds_pool_ci.pPoolSizes = ds_type_count; |
| 4996 | |
| 4997 | VkDescriptorPool ds_pool; |
| 4998 | VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 4999 | ASSERT_VK_SUCCESS(err); |
| 5000 | |
Mark Mueller | b989672 | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5001 | VkDescriptorSetLayoutBinding layout_binding[3] = {}; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5002 | layout_binding[0].binding = 0; |
| 5003 | layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5004 | layout_binding[0].descriptorCount = 1; |
| 5005 | layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 5006 | layout_binding[0].pImmutableSamplers = NULL; |
| 5007 | |
| 5008 | layout_binding[1].binding = 1; |
| 5009 | layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 5010 | layout_binding[1].descriptorCount = 1; |
| 5011 | layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; |
| 5012 | layout_binding[1].pImmutableSamplers = NULL; |
| 5013 | |
| 5014 | VkSamplerCreateInfo sampler_ci = {}; |
| 5015 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 5016 | sampler_ci.pNext = NULL; |
| 5017 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 5018 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 5019 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 5020 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 5021 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 5022 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 5023 | sampler_ci.mipLodBias = 1.0; |
| 5024 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 5025 | sampler_ci.maxAnisotropy = 1; |
| 5026 | sampler_ci.compareEnable = VK_FALSE; |
| 5027 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 5028 | sampler_ci.minLod = 1.0; |
| 5029 | sampler_ci.maxLod = 1.0; |
| 5030 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 5031 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
| 5032 | VkSampler sampler; |
| 5033 | |
| 5034 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
| 5035 | ASSERT_VK_SUCCESS(err); |
| 5036 | |
| 5037 | layout_binding[2].binding = 2; |
| 5038 | layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 5039 | layout_binding[2].descriptorCount = 1; |
| 5040 | layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; |
| 5041 | layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler); |
| 5042 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5043 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 5044 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5045 | ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding); |
| 5046 | ds_layout_ci.pBindings = layout_binding; |
| 5047 | VkDescriptorSetLayout ds_layout; |
| 5048 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout); |
| 5049 | ASSERT_VK_SUCCESS(err); |
| 5050 | |
| 5051 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 5052 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 5053 | alloc_info.descriptorSetCount = 1; |
| 5054 | alloc_info.descriptorPool = ds_pool; |
| 5055 | alloc_info.pSetLayouts = &ds_layout; |
| 5056 | VkDescriptorSet descriptorSet; |
| 5057 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet); |
| 5058 | ASSERT_VK_SUCCESS(err); |
| 5059 | |
| 5060 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 5061 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5062 | pipeline_layout_ci.pNext = NULL; |
| 5063 | pipeline_layout_ci.setLayoutCount = 1; |
| 5064 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 5065 | |
| 5066 | VkPipelineLayout pipeline_layout; |
| 5067 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout); |
| 5068 | ASSERT_VK_SUCCESS(err); |
| 5069 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5070 | VkWriteDescriptorSet descriptor_write = {}; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5071 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5072 | descriptor_write.dstSet = descriptorSet; |
| 5073 | descriptor_write.dstBinding = 0; |
| 5074 | descriptor_write.descriptorCount = 1; |
| 5075 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5076 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5077 | // 1) The uniform buffer is intentionally invalid here |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5078 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5079 | m_errorMonitor->VerifyFound(); |
| 5080 | |
| 5081 | // Create a buffer to update the descriptor with |
| 5082 | uint32_t qfi = 0; |
| 5083 | VkBufferCreateInfo buffCI = {}; |
| 5084 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 5085 | buffCI.size = 1024; |
| 5086 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 5087 | buffCI.queueFamilyIndexCount = 1; |
| 5088 | buffCI.pQueueFamilyIndices = &qfi; |
| 5089 | |
| 5090 | VkBuffer dyub; |
| 5091 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 5092 | ASSERT_VK_SUCCESS(err); |
| 5093 | VkDescriptorBufferInfo buffInfo = {}; |
| 5094 | buffInfo.buffer = dyub; |
| 5095 | buffInfo.offset = 0; |
| 5096 | buffInfo.range = 1024; |
| 5097 | |
| 5098 | descriptor_write.pBufferInfo = &buffInfo; |
| 5099 | descriptor_write.descriptorCount = 2; |
| 5100 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5101 | // 2) The stateFlags don't match between the first and second descriptor |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5102 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage); |
| 5103 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5104 | m_errorMonitor->VerifyFound(); |
| 5105 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5106 | // 3) The second descriptor has a null_ptr pImmutableSamplers and |
| 5107 | // the third descriptor contains an immutable sampler |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5108 | descriptor_write.dstBinding = 1; |
| 5109 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5110 | |
| 5111 | |
| 5112 | // Make pImageInfo index non-null to avoid complaints of it missing |
| 5113 | VkDescriptorImageInfo imageInfo = {}; |
| 5114 | imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 5115 | descriptor_write.pImageInfo = &imageInfo; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5116 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage); |
| 5117 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5118 | m_errorMonitor->VerifyFound(); |
| 5119 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5120 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
| 5121 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 5122 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5123 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5124 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 5125 | } |
| 5126 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5127 | TEST_F(VkLayerTest, InvalidPipeline) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5128 | // Attempt to bind an invalid Pipeline to a valid Command Buffer |
| 5129 | // ObjectTracker should catch this. |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5130 | // Create a valid cmd buffer |
| 5131 | // call vkCmdBindPipeline w/ false Pipeline |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5132 | uint64_t fake_pipeline_handle = 0xbaad6001; |
| 5133 | VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5134 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5135 | "Invalid VkPipeline Object 0xbaad6001"); |
| 5136 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5137 | BeginCommandBuffer(); |
| 5138 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 5139 | VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline); |
| 5140 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 5141 | // Now issue a draw call with no pipeline bound |
| 5142 | m_errorMonitor->SetDesiredFailureMsg( |
| 5143 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5144 | "At Draw/Dispatch time no valid VkPipeline is bound!"); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 5145 | |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 5146 | BeginCommandBuffer(); |
| 5147 | Draw(1, 0, 0, 0); |
| 5148 | m_errorMonitor->VerifyFound(); |
| 5149 | // Finally same check once more but with Dispatch/Compute |
| 5150 | m_errorMonitor->SetDesiredFailureMsg( |
| 5151 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5152 | "At Draw/Dispatch time no valid VkPipeline is bound!"); |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 5153 | BeginCommandBuffer(); |
| 5154 | vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0); |
| 5155 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5156 | } |
| 5157 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5158 | TEST_F(VkLayerTest, DescriptorSetNotUpdated) { |
| 5159 | // Create and update CommandBuffer then call QueueSubmit w/o calling End on |
| 5160 | // CommandBuffer |
| 5161 | VkResult err; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5162 | |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 5163 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5164 | " bound but it was never updated. "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5165 | |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5166 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 5167 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5168 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 5169 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5170 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5171 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5172 | |
| 5173 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5174 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5175 | ds_pool_ci.pNext = NULL; |
| 5176 | ds_pool_ci.maxSets = 1; |
| 5177 | ds_pool_ci.poolSizeCount = 1; |
| 5178 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 5179 | |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5180 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5181 | err = |
| 5182 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5183 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5184 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5185 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5186 | dsl_binding.binding = 0; |
| 5187 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5188 | dsl_binding.descriptorCount = 1; |
| 5189 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5190 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5191 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5192 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5193 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5194 | ds_layout_ci.pNext = NULL; |
| 5195 | ds_layout_ci.bindingCount = 1; |
| 5196 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5197 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5198 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5199 | &ds_layout); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5200 | ASSERT_VK_SUCCESS(err); |
| 5201 | |
| 5202 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5203 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5204 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5205 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 5206 | alloc_info.descriptorPool = ds_pool; |
| 5207 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5208 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5209 | &descriptorSet); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5210 | ASSERT_VK_SUCCESS(err); |
| 5211 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5212 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5213 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5214 | pipeline_layout_ci.pNext = NULL; |
| 5215 | pipeline_layout_ci.setLayoutCount = 1; |
| 5216 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5217 | |
| 5218 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5219 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5220 | &pipeline_layout); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5221 | ASSERT_VK_SUCCESS(err); |
| 5222 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5223 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 5224 | VK_SHADER_STAGE_VERTEX_BIT, this); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5225 | // 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] | 5226 | // on more devices |
| 5227 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 5228 | VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5229 | |
Tony Barbour | c95e4ac | 2015-08-04 17:05:26 -0600 | [diff] [blame] | 5230 | VkPipelineObj pipe(m_device); |
| 5231 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 5232 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 5233 | pipe.AddColorAttachment(); |
Tony Barbour | c95e4ac | 2015-08-04 17:05:26 -0600 | [diff] [blame] | 5234 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 5235 | |
| 5236 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5237 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 5238 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 5239 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5240 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5241 | 1, &descriptorSet, 0, NULL); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5242 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5243 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 5244 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 5245 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5246 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5247 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 5248 | } |
| 5249 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5250 | TEST_F(VkLayerTest, InvalidBufferViewObject) { |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5251 | // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5252 | VkResult err; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5253 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5254 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5255 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer " |
| 5256 | "descriptor with invalid buffer view"); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5257 | |
| 5258 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5259 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5260 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5261 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5262 | |
| 5263 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5264 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5265 | ds_pool_ci.pNext = NULL; |
| 5266 | ds_pool_ci.maxSets = 1; |
| 5267 | ds_pool_ci.poolSizeCount = 1; |
| 5268 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5269 | |
| 5270 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5271 | err = |
| 5272 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5273 | ASSERT_VK_SUCCESS(err); |
| 5274 | |
| 5275 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5276 | dsl_binding.binding = 0; |
| 5277 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5278 | dsl_binding.descriptorCount = 1; |
| 5279 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5280 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5281 | |
| 5282 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5283 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5284 | ds_layout_ci.pNext = NULL; |
| 5285 | ds_layout_ci.bindingCount = 1; |
| 5286 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5287 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5288 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5289 | &ds_layout); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5290 | ASSERT_VK_SUCCESS(err); |
| 5291 | |
| 5292 | VkDescriptorSet descriptorSet; |
| 5293 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5294 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5295 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5296 | alloc_info.descriptorPool = ds_pool; |
| 5297 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5298 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5299 | &descriptorSet); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5300 | ASSERT_VK_SUCCESS(err); |
| 5301 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5302 | VkBufferView view = |
| 5303 | (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5304 | VkWriteDescriptorSet descriptor_write; |
| 5305 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 5306 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5307 | descriptor_write.dstSet = descriptorSet; |
| 5308 | descriptor_write.dstBinding = 0; |
| 5309 | descriptor_write.descriptorCount = 1; |
| 5310 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5311 | descriptor_write.pTexelBufferView = &view; |
| 5312 | |
| 5313 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5314 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5315 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5316 | |
| 5317 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5318 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 5319 | } |
| 5320 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5321 | TEST_F(VkLayerTest, InvalidDynamicOffsetCases) { |
| 5322 | // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error |
| 5323 | // cases: |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5324 | // 1. No dynamicOffset supplied |
| 5325 | // 2. Too many dynamicOffsets supplied |
| 5326 | // 3. Dynamic offset oversteps buffer being updated |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5327 | VkResult err; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 5328 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5329 | " requires 1 dynamicOffsets, but only " |
| 5330 | "0 dynamicOffsets are left in " |
| 5331 | "pDynamicOffsets "); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5332 | |
| 5333 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5334 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5335 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5336 | |
| 5337 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5338 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 5339 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5340 | |
| 5341 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5342 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5343 | ds_pool_ci.pNext = NULL; |
| 5344 | ds_pool_ci.maxSets = 1; |
| 5345 | ds_pool_ci.poolSizeCount = 1; |
| 5346 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5347 | |
| 5348 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5349 | err = |
| 5350 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5351 | ASSERT_VK_SUCCESS(err); |
| 5352 | |
| 5353 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5354 | dsl_binding.binding = 0; |
| 5355 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 5356 | dsl_binding.descriptorCount = 1; |
| 5357 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5358 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5359 | |
| 5360 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5361 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5362 | ds_layout_ci.pNext = NULL; |
| 5363 | ds_layout_ci.bindingCount = 1; |
| 5364 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5365 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5366 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5367 | &ds_layout); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5368 | ASSERT_VK_SUCCESS(err); |
| 5369 | |
| 5370 | VkDescriptorSet descriptorSet; |
| 5371 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5372 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5373 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5374 | alloc_info.descriptorPool = ds_pool; |
| 5375 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5376 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5377 | &descriptorSet); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5378 | ASSERT_VK_SUCCESS(err); |
| 5379 | |
| 5380 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5381 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5382 | pipeline_layout_ci.pNext = NULL; |
| 5383 | pipeline_layout_ci.setLayoutCount = 1; |
| 5384 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5385 | |
| 5386 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5387 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5388 | &pipeline_layout); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5389 | ASSERT_VK_SUCCESS(err); |
| 5390 | |
| 5391 | // Create a buffer to update the descriptor with |
| 5392 | uint32_t qfi = 0; |
| 5393 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5394 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 5395 | buffCI.size = 1024; |
| 5396 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 5397 | buffCI.queueFamilyIndexCount = 1; |
| 5398 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5399 | |
| 5400 | VkBuffer dyub; |
| 5401 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 5402 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5403 | // Allocate memory and bind to buffer so we can make it to the appropriate |
| 5404 | // error |
| 5405 | VkMemoryAllocateInfo mem_alloc = {}; |
| 5406 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 5407 | mem_alloc.pNext = NULL; |
| 5408 | mem_alloc.allocationSize = 1024; |
Chris Forbes | b6116cc | 2016-05-08 11:39:59 +1200 | [diff] [blame] | 5409 | mem_alloc.memoryTypeIndex = 0; |
| 5410 | |
| 5411 | VkMemoryRequirements memReqs; |
| 5412 | vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs); |
| 5413 | bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, |
| 5414 | 0); |
| 5415 | if (!pass) { |
| 5416 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
| 5417 | return; |
| 5418 | } |
| 5419 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5420 | VkDeviceMemory mem; |
| 5421 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 5422 | ASSERT_VK_SUCCESS(err); |
| 5423 | err = vkBindBufferMemory(m_device->device(), dyub, mem, 0); |
| 5424 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5425 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 5426 | VkDescriptorBufferInfo buffInfo = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5427 | buffInfo.buffer = dyub; |
| 5428 | buffInfo.offset = 0; |
| 5429 | buffInfo.range = 1024; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5430 | |
| 5431 | VkWriteDescriptorSet descriptor_write; |
| 5432 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 5433 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5434 | descriptor_write.dstSet = descriptorSet; |
| 5435 | descriptor_write.dstBinding = 0; |
| 5436 | descriptor_write.descriptorCount = 1; |
| 5437 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 5438 | descriptor_write.pBufferInfo = &buffInfo; |
| 5439 | |
| 5440 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5441 | |
| 5442 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5443 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5444 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5445 | 1, &descriptorSet, 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5446 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5447 | uint32_t pDynOff[2] = {512, 756}; |
| 5448 | // 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] | 5449 | m_errorMonitor->SetDesiredFailureMsg( |
| 5450 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5451 | "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5452 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5453 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5454 | 1, &descriptorSet, 2, pDynOff); |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5455 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5456 | // Finally cause error due to dynamicOffset being too big |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5457 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5458 | " dynamic offset 512 combined with " |
| 5459 | "offset 0 and range 1024 that " |
| 5460 | "oversteps the buffer size of 1024"); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5461 | // Create PSO to be used for draw-time errors below |
| 5462 | char const *vsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5463 | "#version 450\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5464 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 5465 | "out gl_PerVertex { \n" |
| 5466 | " vec4 gl_Position;\n" |
| 5467 | "};\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5468 | "void main(){\n" |
| 5469 | " gl_Position = vec4(1);\n" |
| 5470 | "}\n"; |
| 5471 | char const *fsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5472 | "#version 450\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5473 | "\n" |
| 5474 | "layout(location=0) out vec4 x;\n" |
| 5475 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 5476 | "void main(){\n" |
| 5477 | " x = vec4(bar.y);\n" |
| 5478 | "}\n"; |
| 5479 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 5480 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 5481 | VkPipelineObj pipe(m_device); |
| 5482 | pipe.AddShader(&vs); |
| 5483 | pipe.AddShader(&fs); |
| 5484 | pipe.AddColorAttachment(); |
| 5485 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 5486 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5487 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 5488 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 5489 | // This update should succeed, but offset size of 512 will overstep buffer |
| 5490 | // /w range 1024 & size 1024 |
| 5491 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5492 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5493 | 1, &descriptorSet, 1, pDynOff); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5494 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5495 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5496 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5497 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
Tobin Ehlis | 512098e | 2016-05-05 09:06:12 -0600 | [diff] [blame] | 5498 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5499 | |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5500 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 5501 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5502 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 5503 | } |
| 5504 | |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5505 | TEST_F(VkLayerTest, InvalidPushConstants) { |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5506 | VkResult err; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5507 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5508 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5509 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5510 | |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5511 | VkPipelineLayout pipeline_layout; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5512 | VkPushConstantRange pc_range = {}; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5513 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 5514 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5515 | pipeline_layout_ci.pushConstantRangeCount = 1; |
| 5516 | pipeline_layout_ci.pPushConstantRanges = &pc_range; |
| 5517 | |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5518 | // |
| 5519 | // Check for invalid push constant ranges in pipeline layouts. |
| 5520 | // |
| 5521 | struct PipelineLayoutTestCase { |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5522 | VkPushConstantRange const range; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5523 | char const *msg; |
| 5524 | }; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5525 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5526 | const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4; |
| 5527 | const std::array<PipelineLayoutTestCase, 10> range_tests = {{ |
| 5528 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, |
| 5529 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5530 | "size 0."}, |
| 5531 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1}, |
| 5532 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5533 | "size 1."}, |
| 5534 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1}, |
| 5535 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5536 | "size 1."}, |
| 5537 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0}, |
| 5538 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5539 | "size 0."}, |
| 5540 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4}, |
| 5541 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5542 | "offset 1. Offset must"}, |
| 5543 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big}, |
| 5544 | "vkCreatePipelineLayout() call has push constants index 0 " |
| 5545 | "with offset "}, |
| 5546 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big}, |
| 5547 | "vkCreatePipelineLayout() call has push constants " |
| 5548 | "index 0 with offset "}, |
| 5549 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0}, |
| 5550 | "vkCreatePipelineLayout() call has push constants index 0 " |
| 5551 | "with offset "}, |
| 5552 | {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020}, |
| 5553 | "vkCreatePipelineLayout() call has push " |
| 5554 | "constants index 0 with offset "}, |
| 5555 | {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0}, |
| 5556 | "vkCreatePipelineLayout() call has push " |
| 5557 | "constants index 0 with offset "}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5558 | }}; |
| 5559 | |
| 5560 | // Check for invalid offset and size |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5561 | for (const auto &iter : range_tests) { |
| 5562 | pc_range = iter.range; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5563 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5564 | iter.msg); |
| 5565 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 5566 | NULL, &pipeline_layout); |
| 5567 | m_errorMonitor->VerifyFound(); |
| 5568 | if (VK_SUCCESS == err) { |
| 5569 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5570 | } |
| 5571 | } |
| 5572 | |
| 5573 | // Check for invalid stage flag |
| 5574 | pc_range.offset = 0; |
| 5575 | pc_range.size = 16; |
| 5576 | pc_range.stageFlags = 0; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5577 | m_errorMonitor->SetDesiredFailureMsg( |
| 5578 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5579 | "vkCreatePipelineLayout() call has no stageFlags set."); |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5580 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5581 | &pipeline_layout); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5582 | m_errorMonitor->VerifyFound(); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5583 | if (VK_SUCCESS == err) { |
| 5584 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5585 | } |
| 5586 | |
| 5587 | // Check for overlapping ranges |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5588 | const uint32_t ranges_per_test = 5; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5589 | struct OverlappingRangeTestCase { |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5590 | VkPushConstantRange const ranges[ranges_per_test]; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5591 | char const *msg; |
| 5592 | }; |
| 5593 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5594 | const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5595 | {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5596 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5597 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5598 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5599 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5600 | "vkCreatePipelineLayout() call has push constants with overlapping " |
| 5601 | "ranges: 0:[0, 4), 1:[0, 4)"}, |
| 5602 | { |
| 5603 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5604 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5605 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5606 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 5607 | {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}}, |
| 5608 | "vkCreatePipelineLayout() call has push constants with " |
| 5609 | "overlapping " |
| 5610 | "ranges: 3:[12, 20), 4:[16, 20)", |
| 5611 | }, |
| 5612 | { |
| 5613 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5614 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 5615 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5616 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5617 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5618 | "vkCreatePipelineLayout() call has push constants with " |
| 5619 | "overlapping " |
| 5620 | "ranges: 0:[16, 20), 1:[12, 20)", |
| 5621 | }, |
| 5622 | { |
| 5623 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5624 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5625 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5626 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 5627 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5628 | "vkCreatePipelineLayout() call has push constants with " |
| 5629 | "overlapping " |
| 5630 | "ranges: 0:[16, 20), 3:[12, 20)", |
| 5631 | }, |
| 5632 | { |
| 5633 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5634 | {VK_SHADER_STAGE_VERTEX_BIT, 32, 4}, |
| 5635 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 96}, |
| 5636 | {VK_SHADER_STAGE_VERTEX_BIT, 40, 8}, |
| 5637 | {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}}, |
| 5638 | "vkCreatePipelineLayout() call has push constants with " |
| 5639 | "overlapping " |
| 5640 | "ranges: 0:[16, 20), 2:[4, 100)", |
| 5641 | }}}; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5642 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5643 | for (const auto &iter : overlapping_range_tests) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5644 | pipeline_layout_ci.pPushConstantRanges = iter.ranges; |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5645 | pipeline_layout_ci.pushConstantRangeCount = ranges_per_test; |
| 5646 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5647 | iter.msg); |
| 5648 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 5649 | NULL, &pipeline_layout); |
| 5650 | m_errorMonitor->VerifyFound(); |
| 5651 | if (VK_SUCCESS == err) { |
| 5652 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5653 | } |
| 5654 | } |
| 5655 | |
| 5656 | // 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] | 5657 | const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = |
| 5658 | {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5659 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5660 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5661 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 4}, |
| 5662 | {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}}, |
| 5663 | ""}, |
| 5664 | {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24}, |
| 5665 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 4}, |
| 5666 | {VK_SHADER_STAGE_VERTEX_BIT, 64, 8}, |
| 5667 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 16}, |
| 5668 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5669 | ""}}}; |
| 5670 | for (const auto &iter : overlapping_range_tests_pos) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5671 | pipeline_layout_ci.pPushConstantRanges = iter.ranges; |
| 5672 | m_errorMonitor->ExpectSuccess(); |
| 5673 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 5674 | NULL, &pipeline_layout); |
| 5675 | m_errorMonitor->VerifyNotFound(); |
| 5676 | if (VK_SUCCESS == err) { |
| 5677 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5678 | } |
| 5679 | } |
| 5680 | |
| 5681 | // |
| 5682 | // CmdPushConstants tests |
| 5683 | // |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5684 | const uint8_t dummy_values[100] = {}; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5685 | |
| 5686 | // 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] | 5687 | const std::array<PipelineLayoutTestCase, 16> cmd_range_tests = {{ |
| 5688 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, |
| 5689 | "vkCmdPushConstants() call has push constants with size 0. Size " |
| 5690 | "must be greater than zero and a multiple of 4."}, |
| 5691 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1}, |
| 5692 | "vkCmdPushConstants() call has push constants with size 1. Size " |
| 5693 | "must be greater than zero and a multiple of 4."}, |
| 5694 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1}, |
| 5695 | "vkCmdPushConstants() call has push constants with size 1. Size " |
| 5696 | "must be greater than zero and a multiple of 4."}, |
| 5697 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0}, |
| 5698 | "vkCmdPushConstants() call has push constants with offset 1. " |
| 5699 | "Offset must be a multiple of 4."}, |
| 5700 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4}, |
| 5701 | "vkCmdPushConstants() call has push constants with offset 1. " |
| 5702 | "Offset must be a multiple of 4."}, |
| 5703 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20}, |
| 5704 | "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = " |
| 5705 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5706 | {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8}, |
| 5707 | "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = " |
| 5708 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5709 | {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8}, |
| 5710 | "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = " |
| 5711 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5712 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80}, |
| 5713 | "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = " |
| 5714 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5715 | {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4}, |
| 5716 | "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in " |
| 5717 | "any of the ranges in pipeline layout"}, |
| 5718 | {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, |
| 5719 | 0, 16}, |
| 5720 | "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in " |
| 5721 | "any of the ranges in pipeline layout"}, |
| 5722 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5723 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5724 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5725 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5726 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5727 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5728 | {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5729 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5730 | {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5731 | "vkCmdPushConstants() call has push constants with offset "}, |
| 5732 | }}; |
| 5733 | |
| 5734 | // Two ranges for testing robustness |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5735 | const VkPushConstantRange pc_range2[] = { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5736 | {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5737 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5738 | }; |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5739 | pipeline_layout_ci.pushConstantRangeCount = |
| 5740 | sizeof(pc_range2) / sizeof(VkPushConstantRange); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5741 | pipeline_layout_ci.pPushConstantRanges = pc_range2; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5742 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5743 | &pipeline_layout); |
| 5744 | ASSERT_VK_SUCCESS(err); |
| 5745 | BeginCommandBuffer(); |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5746 | for (const auto &iter : cmd_range_tests) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5747 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5748 | iter.msg); |
| 5749 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5750 | iter.range.stageFlags, iter.range.offset, |
| 5751 | iter.range.size, dummy_values); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5752 | m_errorMonitor->VerifyFound(); |
| 5753 | } |
| 5754 | |
| 5755 | // Check for invalid stage flag |
| 5756 | m_errorMonitor->SetDesiredFailureMsg( |
| 5757 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5758 | "vkCmdPushConstants() call has no stageFlags set."); |
| 5759 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5760 | 0, 16, dummy_values); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5761 | m_errorMonitor->VerifyFound(); |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5762 | EndCommandBuffer(); |
| 5763 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
| 5764 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5765 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5766 | // overlapping range tests with cmd |
| 5767 | const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{ |
| 5768 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20}, |
| 5769 | "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = " |
| 5770 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5771 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5772 | "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = " |
| 5773 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5774 | {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16}, |
| 5775 | "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = " |
| 5776 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5777 | }}; |
| 5778 | const VkPushConstantRange pc_range3[] = { |
| 5779 | {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, |
| 5780 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
| 5781 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5782 | {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, |
| 5783 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, |
| 5784 | {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, |
| 5785 | {VK_SHADER_STAGE_VERTEX_BIT, 56, 28}, |
| 5786 | }; |
| 5787 | pipeline_layout_ci.pushConstantRangeCount = |
| 5788 | sizeof(pc_range3) / sizeof(VkPushConstantRange); |
| 5789 | pipeline_layout_ci.pPushConstantRanges = pc_range3; |
| 5790 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5791 | &pipeline_layout); |
| 5792 | ASSERT_VK_SUCCESS(err); |
| 5793 | BeginCommandBuffer(); |
| 5794 | for (const auto &iter : cmd_overlap_tests) { |
| 5795 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5796 | iter.msg); |
| 5797 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
| 5798 | iter.range.stageFlags, iter.range.offset, |
| 5799 | iter.range.size, dummy_values); |
| 5800 | m_errorMonitor->VerifyFound(); |
| 5801 | } |
| 5802 | EndCommandBuffer(); |
| 5803 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
| 5804 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5805 | |
| 5806 | // positive overlapping range tests with cmd |
| 5807 | const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{ |
| 5808 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""}, |
| 5809 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""}, |
| 5810 | {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""}, |
| 5811 | {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""}, |
| 5812 | }}; |
| 5813 | const VkPushConstantRange pc_range4[] = { |
| 5814 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 64}, |
| 5815 | {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, |
| 5816 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
| 5817 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5818 | {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, |
| 5819 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, |
| 5820 | {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, |
| 5821 | {VK_SHADER_STAGE_VERTEX_BIT, 56, 28}, |
| 5822 | }; |
| 5823 | pipeline_layout_ci.pushConstantRangeCount = |
| 5824 | sizeof(pc_range4) / sizeof(VkPushConstantRange); |
| 5825 | pipeline_layout_ci.pPushConstantRanges = pc_range4; |
| 5826 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5827 | &pipeline_layout); |
| 5828 | ASSERT_VK_SUCCESS(err); |
| 5829 | BeginCommandBuffer(); |
| 5830 | for (const auto &iter : cmd_overlap_tests_pos) { |
| 5831 | m_errorMonitor->ExpectSuccess(); |
| 5832 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
| 5833 | iter.range.stageFlags, iter.range.offset, |
| 5834 | iter.range.size, dummy_values); |
| 5835 | m_errorMonitor->VerifyNotFound(); |
| 5836 | } |
| 5837 | EndCommandBuffer(); |
| 5838 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5839 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5840 | } |
| 5841 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5842 | TEST_F(VkLayerTest, DescriptorSetCompatibility) { |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5843 | // Test various desriptorSet errors with bad binding combinations |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5844 | VkResult err; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5845 | |
| 5846 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5847 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5848 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5849 | |
| 5850 | static const uint32_t NUM_DESCRIPTOR_TYPES = 5; |
| 5851 | VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5852 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5853 | ds_type_count[0].descriptorCount = 10; |
| 5854 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 5855 | ds_type_count[1].descriptorCount = 2; |
| 5856 | ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
| 5857 | ds_type_count[2].descriptorCount = 2; |
| 5858 | ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 5859 | ds_type_count[3].descriptorCount = 5; |
| 5860 | // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT |
| 5861 | // type |
| 5862 | // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 5863 | ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
| 5864 | ds_type_count[4].descriptorCount = 2; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5865 | |
| 5866 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5867 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5868 | ds_pool_ci.pNext = NULL; |
| 5869 | ds_pool_ci.maxSets = 5; |
| 5870 | ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES; |
| 5871 | ds_pool_ci.pPoolSizes = ds_type_count; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5872 | |
| 5873 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5874 | err = |
| 5875 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5876 | ASSERT_VK_SUCCESS(err); |
| 5877 | |
| 5878 | static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2; |
| 5879 | VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5880 | dsl_binding[0].binding = 0; |
| 5881 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5882 | dsl_binding[0].descriptorCount = 5; |
| 5883 | dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 5884 | dsl_binding[0].pImmutableSamplers = NULL; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5885 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5886 | // Create layout identical to set0 layout but w/ different stageFlags |
| 5887 | VkDescriptorSetLayoutBinding dsl_fs_stage_only = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5888 | dsl_fs_stage_only.binding = 0; |
| 5889 | dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5890 | dsl_fs_stage_only.descriptorCount = 5; |
| 5891 | dsl_fs_stage_only.stageFlags = |
| 5892 | VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at |
| 5893 | // bind time |
| 5894 | dsl_fs_stage_only.pImmutableSamplers = NULL; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5895 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5896 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5897 | ds_layout_ci.pNext = NULL; |
| 5898 | ds_layout_ci.bindingCount = 1; |
| 5899 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5900 | static const uint32_t NUM_LAYOUTS = 4; |
| 5901 | VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5902 | VkDescriptorSetLayout ds_layout_fs_only = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5903 | // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only |
| 5904 | // layout for error case |
| 5905 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5906 | &ds_layout[0]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5907 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 5908 | ds_layout_ci.pBindings = &dsl_fs_stage_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5909 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5910 | &ds_layout_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5911 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5912 | dsl_binding[0].binding = 0; |
| 5913 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5914 | dsl_binding[0].descriptorCount = 2; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 5915 | dsl_binding[1].binding = 1; |
| 5916 | dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
| 5917 | dsl_binding[1].descriptorCount = 2; |
| 5918 | dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL; |
| 5919 | dsl_binding[1].pImmutableSamplers = NULL; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 5920 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5921 | ds_layout_ci.bindingCount = 2; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5922 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5923 | &ds_layout[1]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5924 | ASSERT_VK_SUCCESS(err); |
| 5925 | dsl_binding[0].binding = 0; |
| 5926 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5927 | dsl_binding[0].descriptorCount = 5; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5928 | ds_layout_ci.bindingCount = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5929 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5930 | &ds_layout[2]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5931 | ASSERT_VK_SUCCESS(err); |
| 5932 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5933 | dsl_binding[0].descriptorCount = 2; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5934 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5935 | &ds_layout[3]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5936 | ASSERT_VK_SUCCESS(err); |
| 5937 | |
| 5938 | static const uint32_t NUM_SETS = 4; |
| 5939 | VkDescriptorSet descriptorSet[NUM_SETS] = {}; |
| 5940 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5941 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5942 | alloc_info.descriptorSetCount = NUM_LAYOUTS; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5943 | alloc_info.descriptorPool = ds_pool; |
| 5944 | alloc_info.pSetLayouts = ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5945 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5946 | descriptorSet); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5947 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5948 | VkDescriptorSet ds0_fs_only = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5949 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5950 | alloc_info.pSetLayouts = &ds_layout_fs_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5951 | err = |
| 5952 | vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5953 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5954 | |
| 5955 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5956 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5957 | pipeline_layout_ci.pNext = NULL; |
| 5958 | pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS; |
| 5959 | pipeline_layout_ci.pSetLayouts = ds_layout; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5960 | |
| 5961 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5962 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5963 | &pipeline_layout); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5964 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5965 | // Create pipelineLayout with only one setLayout |
| 5966 | pipeline_layout_ci.setLayoutCount = 1; |
| 5967 | VkPipelineLayout single_pipe_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5968 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5969 | &single_pipe_layout); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5970 | ASSERT_VK_SUCCESS(err); |
| 5971 | // Create pipelineLayout with 2 descriptor setLayout at index 0 |
| 5972 | pipeline_layout_ci.pSetLayouts = &ds_layout[3]; |
| 5973 | VkPipelineLayout pipe_layout_one_desc; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5974 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5975 | &pipe_layout_one_desc); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5976 | ASSERT_VK_SUCCESS(err); |
| 5977 | // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0 |
| 5978 | pipeline_layout_ci.pSetLayouts = &ds_layout[2]; |
| 5979 | VkPipelineLayout pipe_layout_five_samp; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5980 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5981 | &pipe_layout_five_samp); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5982 | ASSERT_VK_SUCCESS(err); |
| 5983 | // Create pipelineLayout with UB type, but stageFlags for FS only |
| 5984 | pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only; |
| 5985 | VkPipelineLayout pipe_layout_fs_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5986 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5987 | &pipe_layout_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5988 | ASSERT_VK_SUCCESS(err); |
| 5989 | // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine |
| 5990 | VkDescriptorSetLayout pl_bad_s0[2] = {}; |
| 5991 | pl_bad_s0[0] = ds_layout_fs_only; |
| 5992 | pl_bad_s0[1] = ds_layout[1]; |
| 5993 | pipeline_layout_ci.setLayoutCount = 2; |
| 5994 | pipeline_layout_ci.pSetLayouts = pl_bad_s0; |
| 5995 | VkPipelineLayout pipe_layout_bad_set0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5996 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5997 | &pipe_layout_bad_set0); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5998 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5999 | |
| 6000 | // Create a buffer to update the descriptor with |
| 6001 | uint32_t qfi = 0; |
| 6002 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6003 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 6004 | buffCI.size = 1024; |
| 6005 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 6006 | buffCI.queueFamilyIndexCount = 1; |
| 6007 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6008 | |
| 6009 | VkBuffer dyub; |
| 6010 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 6011 | ASSERT_VK_SUCCESS(err); |
| 6012 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 6013 | static const uint32_t NUM_BUFFS = 5; |
| 6014 | VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6015 | for (uint32_t i = 0; i < NUM_BUFFS; ++i) { |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6016 | buffInfo[i].buffer = dyub; |
| 6017 | buffInfo[i].offset = 0; |
| 6018 | buffInfo[i].range = 1024; |
| 6019 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6020 | VkImage image; |
| 6021 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 6022 | const int32_t tex_width = 32; |
| 6023 | const int32_t tex_height = 32; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6024 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6025 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 6026 | image_create_info.pNext = NULL; |
| 6027 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 6028 | image_create_info.format = tex_format; |
| 6029 | image_create_info.extent.width = tex_width; |
| 6030 | image_create_info.extent.height = tex_height; |
| 6031 | image_create_info.extent.depth = 1; |
| 6032 | image_create_info.mipLevels = 1; |
| 6033 | image_create_info.arrayLayers = 1; |
| 6034 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 6035 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 6036 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 6037 | image_create_info.flags = 0; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6038 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 6039 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6040 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6041 | VkMemoryRequirements memReqs; |
| 6042 | VkDeviceMemory imageMem; |
| 6043 | bool pass; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 6044 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6045 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 6046 | memAlloc.pNext = NULL; |
| 6047 | memAlloc.allocationSize = 0; |
| 6048 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 6049 | vkGetImageMemoryRequirements(m_device->device(), image, &memReqs); |
| 6050 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6051 | pass = |
| 6052 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 6053 | ASSERT_TRUE(pass); |
| 6054 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem); |
| 6055 | ASSERT_VK_SUCCESS(err); |
| 6056 | err = vkBindImageMemory(m_device->device(), image, imageMem, 0); |
| 6057 | ASSERT_VK_SUCCESS(err); |
| 6058 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6059 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6060 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 6061 | image_view_create_info.image = image; |
| 6062 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 6063 | image_view_create_info.format = tex_format; |
| 6064 | image_view_create_info.subresourceRange.layerCount = 1; |
| 6065 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 6066 | image_view_create_info.subresourceRange.levelCount = 1; |
| 6067 | image_view_create_info.subresourceRange.aspectMask = |
| 6068 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6069 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6070 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6071 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 6072 | &view); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6073 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6074 | VkDescriptorImageInfo imageInfo[4] = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6075 | imageInfo[0].imageView = view; |
| 6076 | imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 6077 | imageInfo[1].imageView = view; |
| 6078 | imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6079 | imageInfo[2].imageView = view; |
| 6080 | imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 6081 | imageInfo[3].imageView = view; |
| 6082 | imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6083 | |
| 6084 | static const uint32_t NUM_SET_UPDATES = 3; |
| 6085 | VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {}; |
| 6086 | descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 6087 | descriptor_write[0].dstSet = descriptorSet[0]; |
| 6088 | descriptor_write[0].dstBinding = 0; |
| 6089 | descriptor_write[0].descriptorCount = 5; |
| 6090 | descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6091 | descriptor_write[0].pBufferInfo = buffInfo; |
| 6092 | descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 6093 | descriptor_write[1].dstSet = descriptorSet[1]; |
| 6094 | descriptor_write[1].dstBinding = 0; |
| 6095 | descriptor_write[1].descriptorCount = 2; |
| 6096 | descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 6097 | descriptor_write[1].pImageInfo = imageInfo; |
| 6098 | descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 6099 | descriptor_write[2].dstSet = descriptorSet[1]; |
| 6100 | descriptor_write[2].dstBinding = 1; |
| 6101 | descriptor_write[2].descriptorCount = 2; |
| 6102 | descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6103 | descriptor_write[2].pImageInfo = &imageInfo[2]; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6104 | |
| 6105 | vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6106 | |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6107 | // Create PSO to be used for draw-time errors below |
| 6108 | char const *vsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 6109 | "#version 450\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6110 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 6111 | "out gl_PerVertex {\n" |
| 6112 | " vec4 gl_Position;\n" |
| 6113 | "};\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6114 | "void main(){\n" |
| 6115 | " gl_Position = vec4(1);\n" |
| 6116 | "}\n"; |
| 6117 | char const *fsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 6118 | "#version 450\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6119 | "\n" |
| 6120 | "layout(location=0) out vec4 x;\n" |
| 6121 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 6122 | "void main(){\n" |
| 6123 | " x = vec4(bar.y);\n" |
| 6124 | "}\n"; |
| 6125 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6126 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6127 | VkPipelineObj pipe(m_device); |
| 6128 | pipe.AddShader(&vs); |
| 6129 | pipe.AddShader(&fs); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6130 | pipe.AddColorAttachment(); |
| 6131 | pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass()); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6132 | |
| 6133 | BeginCommandBuffer(); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6134 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6135 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 6136 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 6137 | // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding |
| 6138 | // of PSO |
| 6139 | // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of |
| 6140 | // cmd_pipeline.c |
| 6141 | // due to the fact that cmd_alloc_dset_data() has not been called in |
| 6142 | // cmd_bind_graphics_pipeline() |
| 6143 | // TODO : Want to cause various binding incompatibility issues here to test |
| 6144 | // DrawState |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6145 | // First cause various verify_layout_compatibility() fails |
| 6146 | // Second disturb early and late sets and verify INFO msgs |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6147 | // verify_set_layout_compatibility fail cases: |
| 6148 | // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6149 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6150 | " due to: invalid VkPipelineLayout "); |
| 6151 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6152 | VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6153 | (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, |
| 6154 | &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6155 | m_errorMonitor->VerifyFound(); |
| 6156 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6157 | // 2. layoutIndex exceeds # of layouts in layout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6158 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6159 | " attempting to bind set to index 1"); |
| 6160 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6161 | VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, |
| 6162 | 0, 2, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6163 | m_errorMonitor->VerifyFound(); |
| 6164 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6165 | vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6166 | // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5 |
| 6167 | // descriptors |
| 6168 | m_errorMonitor->SetDesiredFailureMsg( |
| 6169 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 6170 | " has 2 descriptors, but DescriptorSetLayout "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6171 | vkCmdBindDescriptorSets( |
| 6172 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6173 | pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6174 | m_errorMonitor->VerifyFound(); |
| 6175 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6176 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL); |
| 6177 | // 4. same # of descriptors but mismatch in type |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6178 | m_errorMonitor->SetDesiredFailureMsg( |
| 6179 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 6180 | " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6181 | vkCmdBindDescriptorSets( |
| 6182 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6183 | pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6184 | m_errorMonitor->VerifyFound(); |
| 6185 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6186 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL); |
| 6187 | // 5. same # of descriptors but mismatch in stageFlags |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6188 | m_errorMonitor->SetDesiredFailureMsg( |
| 6189 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 6190 | " has stageFlags 16 but binding 0 for DescriptorSetLayout "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6191 | vkCmdBindDescriptorSets( |
| 6192 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6193 | pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6194 | m_errorMonitor->VerifyFound(); |
| 6195 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6196 | // Cause INFO messages due to disturbing previously bound Sets |
| 6197 | // First bind sets 0 & 1 |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6198 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6199 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6200 | 2, &descriptorSet[0], 0, NULL); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6201 | // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6202 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 6203 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6204 | " previously bound as set #0 was disturbed "); |
| 6205 | vkCmdBindDescriptorSets( |
| 6206 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6207 | pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6208 | m_errorMonitor->VerifyFound(); |
| 6209 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6210 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6211 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6212 | 2, &descriptorSet[0], 0, NULL); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6213 | // 2. Disturb set after last bound set |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 6214 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6215 | " newly bound as set #0 so set #1 and " |
| 6216 | "any subsequent sets were disturbed "); |
| 6217 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6218 | VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6219 | pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6220 | m_errorMonitor->VerifyFound(); |
| 6221 | |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6222 | // Cause draw-time errors due to PSO incompatibilities |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6223 | // 1. Error due to not binding required set (we actually use same code as |
| 6224 | // above to disturb set0) |
| 6225 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6226 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6227 | 2, &descriptorSet[0], 0, NULL); |
| 6228 | vkCmdBindDescriptorSets( |
| 6229 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6230 | pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL); |
| 6231 | m_errorMonitor->SetDesiredFailureMsg( |
| 6232 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6233 | " uses set #0 but that set is not bound."); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6234 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6235 | m_errorMonitor->VerifyFound(); |
| 6236 | |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6237 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6238 | // 2. Error due to bound set not being compatible with PSO's |
| 6239 | // VkPipelineLayout (diff stageFlags in this case) |
| 6240 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6241 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6242 | 2, &descriptorSet[0], 0, NULL); |
| 6243 | m_errorMonitor->SetDesiredFailureMsg( |
| 6244 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6245 | " bound as set #0 is not compatible with "); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6246 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6247 | m_errorMonitor->VerifyFound(); |
| 6248 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6249 | // Remaining clean-up |
| 6250 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6251 | for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) { |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6252 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL); |
| 6253 | } |
| 6254 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL); |
Tobin Ehlis | 9bfd449 | 2016-05-05 15:09:11 -0600 | [diff] [blame] | 6255 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only); |
| 6256 | vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6257 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6258 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6259 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 6260 | vkFreeMemory(m_device->device(), imageMem, NULL); |
| 6261 | vkDestroyImage(m_device->device(), image, NULL); |
| 6262 | vkDestroyImageView(m_device->device(), view, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6263 | } |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6264 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6265 | TEST_F(VkLayerTest, NoBeginCommandBuffer) { |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6266 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6267 | m_errorMonitor->SetDesiredFailureMsg( |
| 6268 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6269 | "You must call vkBeginCommandBuffer() before this call to "); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6270 | |
| 6271 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6272 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6273 | // Call EndCommandBuffer() w/o calling BeginCommandBuffer() |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6274 | vkEndCommandBuffer(commandBuffer.GetBufferHandle()); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6275 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6276 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6277 | } |
| 6278 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6279 | TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) { |
| 6280 | VkResult err; |
| 6281 | VkCommandBuffer draw_cmd; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6282 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6283 | m_errorMonitor->SetDesiredFailureMsg( |
| 6284 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 61b36f3 | 2015-12-16 08:19:42 -0700 | [diff] [blame] | 6285 | " must specify a valid renderpass parameter."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6286 | |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6287 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6288 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6289 | VkCommandBufferAllocateInfo cmd = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6290 | cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6291 | cmd.pNext = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6292 | cmd.commandPool = m_commandPool; |
| 6293 | cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6294 | cmd.commandBufferCount = 1; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6295 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6296 | err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 6297 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6298 | |
| 6299 | // Force the failure by not setting the Renderpass and Framebuffer fields |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6300 | VkCommandBufferBeginInfo cmd_buf_info = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6301 | VkCommandBufferInheritanceInfo cmd_buf_hinfo = {}; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6302 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6303 | cmd_buf_info.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6304 | cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | |
| 6305 | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6306 | cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo; |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6307 | |
| 6308 | // The error should be caught by validation of the BeginCommandBuffer call |
| 6309 | vkBeginCommandBuffer(draw_cmd, &cmd_buf_info); |
| 6310 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6311 | m_errorMonitor->VerifyFound(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6312 | vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6313 | } |
| 6314 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6315 | TEST_F(VkLayerTest, CommandBufferResetErrors) { |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6316 | // Cause error due to Begin while recording CB |
| 6317 | // Then cause 2 errors for attempting to reset CB w/o having |
| 6318 | // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from |
| 6319 | // which CBs were allocated. Note that this bit is off by default. |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 6320 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6321 | "Cannot call Begin on CB"); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6322 | |
| 6323 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6324 | |
| 6325 | // Calls AllocateCommandBuffers |
| 6326 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
| 6327 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6328 | // Force the failure by setting the Renderpass and Framebuffer fields with |
| 6329 | // (fake) data |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6330 | VkCommandBufferBeginInfo cmd_buf_info = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6331 | VkCommandBufferInheritanceInfo cmd_buf_hinfo = {}; |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6332 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 6333 | cmd_buf_info.pNext = NULL; |
| 6334 | cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6335 | cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo; |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6336 | |
| 6337 | // Begin CB to transition to recording state |
| 6338 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
| 6339 | // Can't re-begin. This should trigger error |
| 6340 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6341 | m_errorMonitor->VerifyFound(); |
| 6342 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6343 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6344 | "Attempt to reset command buffer "); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6345 | VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test |
| 6346 | // Reset attempt will trigger error due to incorrect CommandPool state |
| 6347 | vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6348 | m_errorMonitor->VerifyFound(); |
| 6349 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6350 | m_errorMonitor->SetDesiredFailureMsg( |
| 6351 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6352 | " attempts to implicitly reset cmdBuffer created from "); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6353 | // Transition CB to RECORDED state |
| 6354 | vkEndCommandBuffer(commandBuffer.GetBufferHandle()); |
| 6355 | // Now attempting to Begin will implicitly reset, which triggers error |
| 6356 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6357 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6358 | } |
| 6359 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6360 | TEST_F(VkLayerTest, InvalidPipelineCreateState) { |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6361 | // Attempt to Create Gfx Pipeline w/o a VS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6362 | VkResult err; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6363 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6364 | m_errorMonitor->SetDesiredFailureMsg( |
| 6365 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6366 | "Invalid Pipeline CreateInfo State: Vtx Shader required"); |
| 6367 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6368 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 6369 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 6370 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6371 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6372 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6373 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6374 | |
| 6375 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6376 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6377 | ds_pool_ci.pNext = NULL; |
| 6378 | ds_pool_ci.maxSets = 1; |
| 6379 | ds_pool_ci.poolSizeCount = 1; |
| 6380 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 6381 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6382 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6383 | err = |
| 6384 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6385 | ASSERT_VK_SUCCESS(err); |
| 6386 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6387 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6388 | dsl_binding.binding = 0; |
| 6389 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6390 | dsl_binding.descriptorCount = 1; |
| 6391 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 6392 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6393 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6394 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6395 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6396 | ds_layout_ci.pNext = NULL; |
| 6397 | ds_layout_ci.bindingCount = 1; |
| 6398 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6399 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6400 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6401 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6402 | &ds_layout); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6403 | ASSERT_VK_SUCCESS(err); |
| 6404 | |
| 6405 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6406 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6407 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6408 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6409 | alloc_info.descriptorPool = ds_pool; |
| 6410 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6411 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6412 | &descriptorSet); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6413 | ASSERT_VK_SUCCESS(err); |
| 6414 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6415 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6416 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6417 | pipeline_layout_ci.setLayoutCount = 1; |
| 6418 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6419 | |
| 6420 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6421 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6422 | &pipeline_layout); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6423 | ASSERT_VK_SUCCESS(err); |
| 6424 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6425 | VkViewport vp = {}; // Just need dummy vp to point to |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6426 | VkRect2D sc = {}; // dummy scissor to point to |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6427 | |
| 6428 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6429 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 6430 | vp_state_ci.scissorCount = 1; |
| 6431 | vp_state_ci.pScissors = ≻ |
| 6432 | vp_state_ci.viewportCount = 1; |
| 6433 | vp_state_ci.pViewports = &vp; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6434 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6435 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 6436 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 6437 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 6438 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 6439 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 6440 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 6441 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 6442 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 6443 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6444 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6445 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6446 | gp_ci.pViewportState = &vp_state_ci; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6447 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6448 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6449 | gp_ci.layout = pipeline_layout; |
| 6450 | gp_ci.renderPass = renderPass(); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6451 | |
| 6452 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6453 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 6454 | pc_ci.initialDataSize = 0; |
| 6455 | pc_ci.pInitialData = 0; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6456 | |
| 6457 | VkPipeline pipeline; |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 6458 | VkPipelineCache pipelineCache; |
| 6459 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6460 | err = |
| 6461 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 6462 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6463 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6464 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6465 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6466 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 6467 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6468 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6469 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6470 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6471 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6472 | } |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6473 | /*// TODO : This test should be good, but needs Tess support in compiler to run |
| 6474 | TEST_F(VkLayerTest, InvalidPatchControlPoints) |
| 6475 | { |
| 6476 | // Attempt to Create Gfx Pipeline w/o a VS |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6477 | VkResult err; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6478 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 6479 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6480 | "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH |
| 6481 | primitive "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6482 | |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6483 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6484 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6485 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6486 | VkDescriptorPoolSize ds_type_count = {}; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6487 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6488 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6489 | |
| 6490 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 6491 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6492 | ds_pool_ci.pNext = NULL; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6493 | ds_pool_ci.poolSizeCount = 1; |
| 6494 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6495 | |
| 6496 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6497 | err = vkCreateDescriptorPool(m_device->device(), |
| 6498 | 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] | 6499 | ASSERT_VK_SUCCESS(err); |
| 6500 | |
| 6501 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6502 | dsl_binding.binding = 0; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6503 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | 0212448 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 6504 | dsl_binding.descriptorCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6505 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 6506 | dsl_binding.pImmutableSamplers = NULL; |
| 6507 | |
| 6508 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6509 | ds_layout_ci.sType = |
| 6510 | VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6511 | ds_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6512 | ds_layout_ci.bindingCount = 1; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 6513 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6514 | |
| 6515 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6516 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6517 | &ds_layout); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6518 | ASSERT_VK_SUCCESS(err); |
| 6519 | |
| 6520 | VkDescriptorSet descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6521 | err = vkAllocateDescriptorSets(m_device->device(), ds_pool, |
| 6522 | VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6523 | ASSERT_VK_SUCCESS(err); |
| 6524 | |
| 6525 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6526 | pipeline_layout_ci.sType = |
| 6527 | VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6528 | pipeline_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6529 | pipeline_layout_ci.setLayoutCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6530 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 6531 | |
| 6532 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6533 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6534 | &pipeline_layout); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6535 | ASSERT_VK_SUCCESS(err); |
| 6536 | |
| 6537 | VkPipelineShaderStageCreateInfo shaderStages[3]; |
| 6538 | memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 6539 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6540 | VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, |
| 6541 | this); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6542 | // 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] | 6543 | VkShaderObj |
| 6544 | tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, |
| 6545 | this); |
| 6546 | VkShaderObj |
| 6547 | te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, |
| 6548 | this); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6549 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6550 | shaderStages[0].sType = |
| 6551 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 6552 | shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6553 | shaderStages[0].shader = vs.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6554 | shaderStages[1].sType = |
| 6555 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 6556 | shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6557 | shaderStages[1].shader = tc.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6558 | shaderStages[2].sType = |
| 6559 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 6560 | shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6561 | shaderStages[2].shader = te.handle(); |
| 6562 | |
| 6563 | VkPipelineInputAssemblyStateCreateInfo iaCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6564 | iaCI.sType = |
| 6565 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
Chia-I Wu | 515eb8f | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6566 | iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6567 | |
| 6568 | VkPipelineTessellationStateCreateInfo tsCI = {}; |
| 6569 | tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO; |
| 6570 | tsCI.patchControlPoints = 0; // This will cause an error |
| 6571 | |
| 6572 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 6573 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6574 | gp_ci.pNext = NULL; |
| 6575 | gp_ci.stageCount = 3; |
| 6576 | gp_ci.pStages = shaderStages; |
| 6577 | gp_ci.pVertexInputState = NULL; |
| 6578 | gp_ci.pInputAssemblyState = &iaCI; |
| 6579 | gp_ci.pTessellationState = &tsCI; |
| 6580 | gp_ci.pViewportState = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6581 | gp_ci.pRasterizationState = NULL; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6582 | gp_ci.pMultisampleState = NULL; |
| 6583 | gp_ci.pDepthStencilState = NULL; |
| 6584 | gp_ci.pColorBlendState = NULL; |
| 6585 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6586 | gp_ci.layout = pipeline_layout; |
| 6587 | gp_ci.renderPass = renderPass(); |
| 6588 | |
| 6589 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 6590 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 6591 | pc_ci.pNext = NULL; |
| 6592 | pc_ci.initialSize = 0; |
| 6593 | pc_ci.initialData = 0; |
| 6594 | pc_ci.maxSize = 0; |
| 6595 | |
| 6596 | VkPipeline pipeline; |
| 6597 | VkPipelineCache pipelineCache; |
| 6598 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6599 | err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, |
| 6600 | &pipelineCache); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6601 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6602 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6603 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6604 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6605 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 6606 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6607 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6608 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6609 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6610 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6611 | } |
| 6612 | */ |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6613 | // Set scissor and viewport counts to different numbers |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6614 | TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6615 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6616 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6617 | m_errorMonitor->SetDesiredFailureMsg( |
| 6618 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6619 | "Gfx Pipeline viewport count (1) must match scissor count (0)."); |
| 6620 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6621 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6622 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6623 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6624 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6625 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6626 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6627 | |
| 6628 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6629 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6630 | ds_pool_ci.maxSets = 1; |
| 6631 | ds_pool_ci.poolSizeCount = 1; |
| 6632 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6633 | |
| 6634 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6635 | err = |
| 6636 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6637 | ASSERT_VK_SUCCESS(err); |
| 6638 | |
| 6639 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6640 | dsl_binding.binding = 0; |
| 6641 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6642 | dsl_binding.descriptorCount = 1; |
| 6643 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6644 | |
| 6645 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6646 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6647 | ds_layout_ci.bindingCount = 1; |
| 6648 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6649 | |
| 6650 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6651 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6652 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6653 | ASSERT_VK_SUCCESS(err); |
| 6654 | |
| 6655 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6656 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6657 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6658 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6659 | alloc_info.descriptorPool = ds_pool; |
| 6660 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6661 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6662 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6663 | ASSERT_VK_SUCCESS(err); |
| 6664 | |
| 6665 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6666 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6667 | pipeline_layout_ci.setLayoutCount = 1; |
| 6668 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6669 | |
| 6670 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6671 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6672 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6673 | ASSERT_VK_SUCCESS(err); |
| 6674 | |
| 6675 | VkViewport vp = {}; // Just need dummy vp to point to |
| 6676 | |
| 6677 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6678 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 6679 | vp_state_ci.scissorCount = 0; |
| 6680 | vp_state_ci.viewportCount = 1; // Count mismatch should cause error |
| 6681 | vp_state_ci.pViewports = &vp; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6682 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6683 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 6684 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 6685 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 6686 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 6687 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 6688 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 6689 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 6690 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 6691 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 6692 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6693 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6694 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6695 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 6696 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6697 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 6698 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6699 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6700 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6701 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 6702 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6703 | |
| 6704 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6705 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6706 | gp_ci.stageCount = 2; |
| 6707 | gp_ci.pStages = shaderStages; |
| 6708 | gp_ci.pViewportState = &vp_state_ci; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6709 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6710 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6711 | gp_ci.layout = pipeline_layout; |
| 6712 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6713 | |
| 6714 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6715 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6716 | |
| 6717 | VkPipeline pipeline; |
| 6718 | VkPipelineCache pipelineCache; |
| 6719 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6720 | err = |
| 6721 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6722 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6723 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6724 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6725 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6726 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6727 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6728 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6729 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6730 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6731 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6732 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6733 | // Don't set viewport state in PSO. This is an error b/c we always need this |
| 6734 | // state |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 6735 | // 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] | 6736 | TEST_F(VkLayerTest, PSOViewportStateNotSet) { |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6737 | // Attempt to Create Gfx Pipeline w/o a VS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6738 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6739 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6740 | m_errorMonitor->SetDesiredFailureMsg( |
| 6741 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6742 | "Gfx Pipeline pViewportState is null. Even if "); |
| 6743 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6744 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6745 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6746 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6747 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6748 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6749 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6750 | |
| 6751 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6752 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6753 | ds_pool_ci.maxSets = 1; |
| 6754 | ds_pool_ci.poolSizeCount = 1; |
| 6755 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6756 | |
| 6757 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6758 | err = |
| 6759 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6760 | ASSERT_VK_SUCCESS(err); |
| 6761 | |
| 6762 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6763 | dsl_binding.binding = 0; |
| 6764 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6765 | dsl_binding.descriptorCount = 1; |
| 6766 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6767 | |
| 6768 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6769 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6770 | ds_layout_ci.bindingCount = 1; |
| 6771 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6772 | |
| 6773 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6774 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6775 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6776 | ASSERT_VK_SUCCESS(err); |
| 6777 | |
| 6778 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6779 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6780 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6781 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6782 | alloc_info.descriptorPool = ds_pool; |
| 6783 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6784 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6785 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6786 | ASSERT_VK_SUCCESS(err); |
| 6787 | |
| 6788 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6789 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6790 | pipeline_layout_ci.setLayoutCount = 1; |
| 6791 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6792 | |
| 6793 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6794 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6795 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6796 | ASSERT_VK_SUCCESS(err); |
| 6797 | |
| 6798 | VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR; |
| 6799 | // Set scissor as dynamic to avoid second error |
| 6800 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6801 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 6802 | dyn_state_ci.dynamicStateCount = 1; |
| 6803 | dyn_state_ci.pDynamicStates = &sc_state; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6804 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 6805 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6806 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6807 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6808 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 6809 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6810 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 6811 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6812 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6813 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6814 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 6815 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6816 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6817 | |
| 6818 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 6819 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 6820 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 6821 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 6822 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 6823 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 6824 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 6825 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 6826 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6827 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6828 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6829 | gp_ci.stageCount = 2; |
| 6830 | gp_ci.pStages = shaderStages; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6831 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6832 | gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state |
| 6833 | // should cause validation error |
| 6834 | gp_ci.pDynamicState = &dyn_state_ci; |
| 6835 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6836 | gp_ci.layout = pipeline_layout; |
| 6837 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6838 | |
| 6839 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6840 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6841 | |
| 6842 | VkPipeline pipeline; |
| 6843 | VkPipelineCache pipelineCache; |
| 6844 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6845 | err = |
| 6846 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6847 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6848 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6849 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6850 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6851 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6852 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6853 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6854 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6855 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6856 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6857 | } |
| 6858 | // Create PSO w/o non-zero viewportCount but no viewport data |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6859 | // Then run second test where dynamic scissor count doesn't match PSO scissor |
| 6860 | // count |
| 6861 | TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) { |
| 6862 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6863 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6864 | m_errorMonitor->SetDesiredFailureMsg( |
| 6865 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6866 | "Gfx Pipeline viewportCount is 1, but pViewports is NULL. "); |
| 6867 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6868 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6869 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6870 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6871 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6872 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6873 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6874 | |
| 6875 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6876 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6877 | ds_pool_ci.maxSets = 1; |
| 6878 | ds_pool_ci.poolSizeCount = 1; |
| 6879 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6880 | |
| 6881 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6882 | err = |
| 6883 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6884 | ASSERT_VK_SUCCESS(err); |
| 6885 | |
| 6886 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6887 | dsl_binding.binding = 0; |
| 6888 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6889 | dsl_binding.descriptorCount = 1; |
| 6890 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6891 | |
| 6892 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6893 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6894 | ds_layout_ci.bindingCount = 1; |
| 6895 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6896 | |
| 6897 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6898 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6899 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6900 | ASSERT_VK_SUCCESS(err); |
| 6901 | |
| 6902 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6903 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6904 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6905 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6906 | alloc_info.descriptorPool = ds_pool; |
| 6907 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6908 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6909 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6910 | ASSERT_VK_SUCCESS(err); |
| 6911 | |
| 6912 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6913 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6914 | pipeline_layout_ci.setLayoutCount = 1; |
| 6915 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6916 | |
| 6917 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6918 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6919 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6920 | ASSERT_VK_SUCCESS(err); |
| 6921 | |
| 6922 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6923 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 6924 | vp_state_ci.viewportCount = 1; |
| 6925 | vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error |
| 6926 | vp_state_ci.scissorCount = 1; |
| 6927 | vp_state_ci.pScissors = |
| 6928 | NULL; // Scissor is dynamic (below) so this won't cause error |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6929 | |
| 6930 | VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR; |
| 6931 | // Set scissor as dynamic to avoid that error |
| 6932 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6933 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 6934 | dyn_state_ci.dynamicStateCount = 1; |
| 6935 | dyn_state_ci.pDynamicStates = &sc_state; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6936 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 6937 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6938 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6939 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6940 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 6941 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6942 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 6943 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6944 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6945 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6946 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 6947 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6948 | |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6949 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 6950 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 6951 | vi_ci.pNext = nullptr; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6952 | vi_ci.vertexBindingDescriptionCount = 0; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6953 | vi_ci.pVertexBindingDescriptions = nullptr; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6954 | vi_ci.vertexAttributeDescriptionCount = 0; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6955 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 6956 | |
| 6957 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 6958 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 6959 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 6960 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6961 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6962 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6963 | rs_ci.pNext = nullptr; |
| 6964 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 6965 | VkPipelineColorBlendAttachmentState att = {}; |
| 6966 | att.blendEnable = VK_FALSE; |
| 6967 | att.colorWriteMask = 0xf; |
| 6968 | |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6969 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 6970 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 6971 | cb_ci.pNext = nullptr; |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 6972 | cb_ci.attachmentCount = 1; |
| 6973 | cb_ci.pAttachments = &att; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6974 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6975 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6976 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6977 | gp_ci.stageCount = 2; |
| 6978 | gp_ci.pStages = shaderStages; |
| 6979 | gp_ci.pVertexInputState = &vi_ci; |
| 6980 | gp_ci.pInputAssemblyState = &ia_ci; |
| 6981 | gp_ci.pViewportState = &vp_state_ci; |
| 6982 | gp_ci.pRasterizationState = &rs_ci; |
| 6983 | gp_ci.pColorBlendState = &cb_ci; |
| 6984 | gp_ci.pDynamicState = &dyn_state_ci; |
| 6985 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6986 | gp_ci.layout = pipeline_layout; |
| 6987 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6988 | |
| 6989 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6990 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6991 | |
| 6992 | VkPipeline pipeline; |
| 6993 | VkPipelineCache pipelineCache; |
| 6994 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6995 | err = |
| 6996 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6997 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6998 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6999 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7000 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7001 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7002 | |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7003 | // 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] | 7004 | // First need to successfully create the PSO from above by setting |
| 7005 | // pViewports |
| 7006 | m_errorMonitor->SetDesiredFailureMsg( |
| 7007 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7008 | "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO " |
| 7009 | "scissorCount is 1. These counts must match."); |
| 7010 | |
| 7011 | VkViewport vp = {}; // Just need dummy vp to point to |
| 7012 | vp_state_ci.pViewports = &vp; |
| 7013 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7014 | &gp_ci, NULL, &pipeline); |
| 7015 | ASSERT_VK_SUCCESS(err); |
| 7016 | BeginCommandBuffer(); |
| 7017 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7018 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 7019 | VkRect2D scissors[2] = {}; // don't care about data |
| 7020 | // Count of 2 doesn't match PSO count of 1 |
| 7021 | vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors); |
| 7022 | Draw(1, 0, 0, 0); |
| 7023 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7024 | m_errorMonitor->VerifyFound(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7025 | |
| 7026 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7027 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7028 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7029 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7030 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7031 | } |
| 7032 | // Create PSO w/o non-zero scissorCount but no scissor data |
| 7033 | // Then run second test where dynamic viewportCount doesn't match PSO |
| 7034 | // viewportCount |
| 7035 | TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) { |
| 7036 | VkResult err; |
| 7037 | |
| 7038 | m_errorMonitor->SetDesiredFailureMsg( |
| 7039 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7040 | "Gfx Pipeline scissorCount is 1, but pScissors is NULL. "); |
| 7041 | |
| 7042 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7043 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7044 | |
| 7045 | VkDescriptorPoolSize ds_type_count = {}; |
| 7046 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7047 | ds_type_count.descriptorCount = 1; |
| 7048 | |
| 7049 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 7050 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7051 | ds_pool_ci.maxSets = 1; |
| 7052 | ds_pool_ci.poolSizeCount = 1; |
| 7053 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 7054 | |
| 7055 | VkDescriptorPool ds_pool; |
| 7056 | err = |
| 7057 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 7058 | ASSERT_VK_SUCCESS(err); |
| 7059 | |
| 7060 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 7061 | dsl_binding.binding = 0; |
| 7062 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7063 | dsl_binding.descriptorCount = 1; |
| 7064 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7065 | |
| 7066 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 7067 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7068 | ds_layout_ci.bindingCount = 1; |
| 7069 | ds_layout_ci.pBindings = &dsl_binding; |
| 7070 | |
| 7071 | VkDescriptorSetLayout ds_layout; |
| 7072 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7073 | &ds_layout); |
| 7074 | ASSERT_VK_SUCCESS(err); |
| 7075 | |
| 7076 | VkDescriptorSet descriptorSet; |
| 7077 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 7078 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 7079 | alloc_info.descriptorSetCount = 1; |
| 7080 | alloc_info.descriptorPool = ds_pool; |
| 7081 | alloc_info.pSetLayouts = &ds_layout; |
| 7082 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7083 | &descriptorSet); |
| 7084 | ASSERT_VK_SUCCESS(err); |
| 7085 | |
| 7086 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 7087 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7088 | pipeline_layout_ci.setLayoutCount = 1; |
| 7089 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 7090 | |
| 7091 | VkPipelineLayout pipeline_layout; |
| 7092 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7093 | &pipeline_layout); |
| 7094 | ASSERT_VK_SUCCESS(err); |
| 7095 | |
| 7096 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 7097 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7098 | vp_state_ci.scissorCount = 1; |
| 7099 | vp_state_ci.pScissors = |
| 7100 | NULL; // Null scissor w/ count of 1 should cause error |
| 7101 | vp_state_ci.viewportCount = 1; |
| 7102 | vp_state_ci.pViewports = |
| 7103 | NULL; // vp is dynamic (below) so this won't cause error |
| 7104 | |
| 7105 | VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT; |
| 7106 | // Set scissor as dynamic to avoid that error |
| 7107 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
| 7108 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 7109 | dyn_state_ci.dynamicStateCount = 1; |
| 7110 | dyn_state_ci.pDynamicStates = &vp_state; |
| 7111 | |
| 7112 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
| 7113 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 7114 | |
| 7115 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7116 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7117 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7118 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 7119 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7120 | // but add it to be able to run on more devices |
| 7121 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 7122 | shaderStages[1] = fs.GetStageCreateInfo(); |
| 7123 | |
| 7124 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 7125 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 7126 | vi_ci.pNext = nullptr; |
| 7127 | vi_ci.vertexBindingDescriptionCount = 0; |
| 7128 | vi_ci.pVertexBindingDescriptions = nullptr; |
| 7129 | vi_ci.vertexAttributeDescriptionCount = 0; |
| 7130 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 7131 | |
| 7132 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 7133 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 7134 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 7135 | |
| 7136 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
| 7137 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7138 | rs_ci.pNext = nullptr; |
| 7139 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 7140 | VkPipelineColorBlendAttachmentState att = {}; |
| 7141 | att.blendEnable = VK_FALSE; |
| 7142 | att.colorWriteMask = 0xf; |
| 7143 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7144 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 7145 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 7146 | cb_ci.pNext = nullptr; |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 7147 | cb_ci.attachmentCount = 1; |
| 7148 | cb_ci.pAttachments = &att; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7149 | |
| 7150 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 7151 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7152 | gp_ci.stageCount = 2; |
| 7153 | gp_ci.pStages = shaderStages; |
| 7154 | gp_ci.pVertexInputState = &vi_ci; |
| 7155 | gp_ci.pInputAssemblyState = &ia_ci; |
| 7156 | gp_ci.pViewportState = &vp_state_ci; |
| 7157 | gp_ci.pRasterizationState = &rs_ci; |
| 7158 | gp_ci.pColorBlendState = &cb_ci; |
| 7159 | gp_ci.pDynamicState = &dyn_state_ci; |
| 7160 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7161 | gp_ci.layout = pipeline_layout; |
| 7162 | gp_ci.renderPass = renderPass(); |
| 7163 | |
| 7164 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 7165 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 7166 | |
| 7167 | VkPipeline pipeline; |
| 7168 | VkPipelineCache pipelineCache; |
| 7169 | |
| 7170 | err = |
| 7171 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7172 | ASSERT_VK_SUCCESS(err); |
| 7173 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7174 | &gp_ci, NULL, &pipeline); |
| 7175 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7176 | m_errorMonitor->VerifyFound(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7177 | |
| 7178 | // Now hit second fail case where we set scissor w/ different count than PSO |
| 7179 | // First need to successfully create the PSO from above by setting |
| 7180 | // pViewports |
| 7181 | m_errorMonitor->SetDesiredFailureMsg( |
| 7182 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7183 | "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO " |
| 7184 | "viewportCount is 1. These counts must match."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7185 | |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7186 | VkRect2D sc = {}; // Just need dummy vp to point to |
| 7187 | vp_state_ci.pScissors = ≻ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7188 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7189 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7190 | ASSERT_VK_SUCCESS(err); |
| 7191 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7192 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7193 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7194 | VkViewport viewports[2] = {}; // don't care about data |
| 7195 | // Count of 2 doesn't match PSO count of 1 |
Jon Ashburn | 19d3bf1 | 2015-12-30 14:06:55 -0700 | [diff] [blame] | 7196 | vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7197 | Draw(1, 0, 0, 0); |
| 7198 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7199 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7200 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7201 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7202 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7203 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7204 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7205 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7206 | } |
| 7207 | |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7208 | TEST_F(VkLayerTest, PSOLineWidthInvalid) { |
| 7209 | VkResult err; |
| 7210 | |
| 7211 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7212 | "Attempt to set lineWidth to -1"); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7213 | |
| 7214 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7215 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7216 | |
| 7217 | VkDescriptorPoolSize ds_type_count = {}; |
| 7218 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7219 | ds_type_count.descriptorCount = 1; |
| 7220 | |
| 7221 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 7222 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7223 | ds_pool_ci.maxSets = 1; |
| 7224 | ds_pool_ci.poolSizeCount = 1; |
| 7225 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 7226 | |
| 7227 | VkDescriptorPool ds_pool; |
| 7228 | err = |
| 7229 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 7230 | ASSERT_VK_SUCCESS(err); |
| 7231 | |
| 7232 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 7233 | dsl_binding.binding = 0; |
| 7234 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7235 | dsl_binding.descriptorCount = 1; |
| 7236 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7237 | |
| 7238 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 7239 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7240 | ds_layout_ci.bindingCount = 1; |
| 7241 | ds_layout_ci.pBindings = &dsl_binding; |
| 7242 | |
| 7243 | VkDescriptorSetLayout ds_layout; |
| 7244 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7245 | &ds_layout); |
| 7246 | ASSERT_VK_SUCCESS(err); |
| 7247 | |
| 7248 | VkDescriptorSet descriptorSet; |
| 7249 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 7250 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 7251 | alloc_info.descriptorSetCount = 1; |
| 7252 | alloc_info.descriptorPool = ds_pool; |
| 7253 | alloc_info.pSetLayouts = &ds_layout; |
| 7254 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7255 | &descriptorSet); |
| 7256 | ASSERT_VK_SUCCESS(err); |
| 7257 | |
| 7258 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 7259 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7260 | pipeline_layout_ci.setLayoutCount = 1; |
| 7261 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 7262 | |
| 7263 | VkPipelineLayout pipeline_layout; |
| 7264 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7265 | &pipeline_layout); |
| 7266 | ASSERT_VK_SUCCESS(err); |
| 7267 | |
| 7268 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 7269 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7270 | vp_state_ci.scissorCount = 1; |
| 7271 | vp_state_ci.pScissors = NULL; |
| 7272 | vp_state_ci.viewportCount = 1; |
| 7273 | vp_state_ci.pViewports = NULL; |
| 7274 | |
| 7275 | VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, |
| 7276 | VK_DYNAMIC_STATE_SCISSOR, |
| 7277 | VK_DYNAMIC_STATE_LINE_WIDTH}; |
| 7278 | // Set scissor as dynamic to avoid that error |
| 7279 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
| 7280 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 7281 | dyn_state_ci.dynamicStateCount = 2; |
| 7282 | dyn_state_ci.pDynamicStates = dynamic_states; |
| 7283 | |
| 7284 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
| 7285 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 7286 | |
| 7287 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7288 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7289 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7290 | VK_SHADER_STAGE_FRAGMENT_BIT, |
| 7291 | this); // TODO - We shouldn't need a fragment shader |
| 7292 | // but add it to be able to run on more devices |
| 7293 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 7294 | shaderStages[1] = fs.GetStageCreateInfo(); |
| 7295 | |
| 7296 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 7297 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 7298 | vi_ci.pNext = nullptr; |
| 7299 | vi_ci.vertexBindingDescriptionCount = 0; |
| 7300 | vi_ci.pVertexBindingDescriptions = nullptr; |
| 7301 | vi_ci.vertexAttributeDescriptionCount = 0; |
| 7302 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 7303 | |
| 7304 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 7305 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 7306 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 7307 | |
| 7308 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
| 7309 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7310 | rs_ci.pNext = nullptr; |
| 7311 | |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7312 | // Check too low (line width of -1.0f). |
| 7313 | rs_ci.lineWidth = -1.0f; |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7314 | |
| 7315 | VkPipelineColorBlendAttachmentState att = {}; |
| 7316 | att.blendEnable = VK_FALSE; |
| 7317 | att.colorWriteMask = 0xf; |
| 7318 | |
| 7319 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 7320 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 7321 | cb_ci.pNext = nullptr; |
| 7322 | cb_ci.attachmentCount = 1; |
| 7323 | cb_ci.pAttachments = &att; |
| 7324 | |
| 7325 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 7326 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7327 | gp_ci.stageCount = 2; |
| 7328 | gp_ci.pStages = shaderStages; |
| 7329 | gp_ci.pVertexInputState = &vi_ci; |
| 7330 | gp_ci.pInputAssemblyState = &ia_ci; |
| 7331 | gp_ci.pViewportState = &vp_state_ci; |
| 7332 | gp_ci.pRasterizationState = &rs_ci; |
| 7333 | gp_ci.pColorBlendState = &cb_ci; |
| 7334 | gp_ci.pDynamicState = &dyn_state_ci; |
| 7335 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7336 | gp_ci.layout = pipeline_layout; |
| 7337 | gp_ci.renderPass = renderPass(); |
| 7338 | |
| 7339 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 7340 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 7341 | |
| 7342 | VkPipeline pipeline; |
| 7343 | VkPipelineCache pipelineCache; |
| 7344 | |
| 7345 | err = |
| 7346 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7347 | ASSERT_VK_SUCCESS(err); |
| 7348 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7349 | &gp_ci, NULL, &pipeline); |
| 7350 | |
| 7351 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7352 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7353 | |
| 7354 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7355 | "Attempt to set lineWidth to 65536"); |
| 7356 | |
| 7357 | // Check too high (line width of 65536.0f). |
| 7358 | rs_ci.lineWidth = 65536.0f; |
| 7359 | |
| 7360 | err = |
| 7361 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7362 | ASSERT_VK_SUCCESS(err); |
| 7363 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7364 | &gp_ci, NULL, &pipeline); |
| 7365 | |
| 7366 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7367 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7368 | |
| 7369 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7370 | "Attempt to set lineWidth to -1"); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7371 | |
| 7372 | dyn_state_ci.dynamicStateCount = 3; |
| 7373 | |
| 7374 | rs_ci.lineWidth = 1.0f; |
| 7375 | |
| 7376 | err = |
| 7377 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7378 | ASSERT_VK_SUCCESS(err); |
| 7379 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7380 | &gp_ci, NULL, &pipeline); |
| 7381 | BeginCommandBuffer(); |
| 7382 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7383 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 7384 | |
| 7385 | // Check too low with dynamic setting. |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7386 | vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7387 | m_errorMonitor->VerifyFound(); |
| 7388 | |
| 7389 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7390 | "Attempt to set lineWidth to 65536"); |
| 7391 | |
| 7392 | // Check too high with dynamic setting. |
| 7393 | vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f); |
| 7394 | m_errorMonitor->VerifyFound(); |
| 7395 | EndCommandBuffer(); |
| 7396 | |
| 7397 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7398 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7399 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7400 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7401 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7402 | } |
| 7403 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7404 | TEST_F(VkLayerTest, NullRenderPass) { |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7405 | // Bind a NULL RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7406 | m_errorMonitor->SetDesiredFailureMsg( |
| 7407 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7408 | "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()"); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7409 | |
| 7410 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7411 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7412 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 7413 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7414 | // Don't care about RenderPass handle b/c error should be flagged before |
| 7415 | // that |
| 7416 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, |
| 7417 | VK_SUBPASS_CONTENTS_INLINE); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7418 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7419 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7420 | } |
| 7421 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7422 | TEST_F(VkLayerTest, RenderPassWithinRenderPass) { |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7423 | // Bind a BeginRenderPass within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7424 | m_errorMonitor->SetDesiredFailureMsg( |
| 7425 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7426 | "It is invalid to issue this call inside an active render pass"); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7427 | |
| 7428 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7429 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7430 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 7431 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7432 | // Just create a dummy Renderpass that's non-NULL so we can get to the |
| 7433 | // proper error |
Chris Forbes | 38ae7c4 | 2016-06-21 20:51:44 +1200 | [diff] [blame] | 7434 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7435 | VK_SUBPASS_CONTENTS_INLINE); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7436 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7437 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 7438 | } |
| 7439 | |
Chris Forbes | 2eeabe3 | 2016-06-21 20:52:34 +1200 | [diff] [blame] | 7440 | TEST_F(VkLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) { |
| 7441 | m_errorMonitor->ExpectSuccess(); |
| 7442 | |
| 7443 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7444 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7445 | |
| 7446 | BeginCommandBuffer(); // framework implicitly begins the renderpass. |
| 7447 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // end implicit. |
| 7448 | |
| 7449 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, |
| 7450 | VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS); |
| 7451 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 7452 | m_errorMonitor->VerifyNotFound(); |
| 7453 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, |
| 7454 | VK_SUBPASS_CONTENTS_INLINE); |
| 7455 | m_errorMonitor->VerifyNotFound(); |
| 7456 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 7457 | m_errorMonitor->VerifyNotFound(); |
| 7458 | |
| 7459 | m_commandBuffer->EndCommandBuffer(); |
| 7460 | m_errorMonitor->VerifyNotFound(); |
| 7461 | } |
| 7462 | |
Tobin Ehlis | 5a1c033 | 2016-05-31 13:59:26 -0600 | [diff] [blame] | 7463 | TEST_F(VkLayerTest, RenderPassClearOpMismatch) { |
| 7464 | TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than" |
| 7465 | "the number of renderPass attachments that use loadOp" |
| 7466 | "VK_ATTACHMENT_LOAD_OP_CLEAR."); |
| 7467 | |
| 7468 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7469 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7470 | |
| 7471 | // Create a renderPass with a single attachment that uses loadOp CLEAR |
| 7472 | VkAttachmentReference attach = {}; |
| 7473 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 7474 | VkSubpassDescription subpass = {}; |
| 7475 | subpass.inputAttachmentCount = 1; |
| 7476 | subpass.pInputAttachments = &attach; |
| 7477 | VkRenderPassCreateInfo rpci = {}; |
| 7478 | rpci.subpassCount = 1; |
| 7479 | rpci.pSubpasses = &subpass; |
| 7480 | rpci.attachmentCount = 1; |
| 7481 | VkAttachmentDescription attach_desc = {}; |
| 7482 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 7483 | // Set loadOp to CLEAR |
| 7484 | attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 7485 | rpci.pAttachments = &attach_desc; |
| 7486 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 7487 | VkRenderPass rp; |
| 7488 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 7489 | |
| 7490 | VkCommandBufferInheritanceInfo hinfo = {}; |
| 7491 | hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; |
| 7492 | hinfo.renderPass = VK_NULL_HANDLE; |
| 7493 | hinfo.subpass = 0; |
| 7494 | hinfo.framebuffer = VK_NULL_HANDLE; |
| 7495 | hinfo.occlusionQueryEnable = VK_FALSE; |
| 7496 | hinfo.queryFlags = 0; |
| 7497 | hinfo.pipelineStatistics = 0; |
| 7498 | VkCommandBufferBeginInfo info = {}; |
| 7499 | info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
| 7500 | info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 7501 | info.pInheritanceInfo = &hinfo; |
| 7502 | |
| 7503 | vkBeginCommandBuffer(m_commandBuffer->handle(), &info); |
| 7504 | VkRenderPassBeginInfo rp_begin = {}; |
| 7505 | rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 7506 | rp_begin.pNext = NULL; |
| 7507 | rp_begin.renderPass = renderPass(); |
| 7508 | rp_begin.framebuffer = framebuffer(); |
| 7509 | rp_begin.clearValueCount = 0; // Should be 1 |
| 7510 | |
| 7511 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7512 | " has a clearValueCount of 0 but the " |
| 7513 | "actual number of attachments in " |
| 7514 | "renderPass "); |
| 7515 | |
| 7516 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, |
| 7517 | VK_SUBPASS_CONTENTS_INLINE); |
| 7518 | |
| 7519 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 5c70ebd | 2016-06-09 13:45:00 -0600 | [diff] [blame] | 7520 | |
| 7521 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 5a1c033 | 2016-05-31 13:59:26 -0600 | [diff] [blame] | 7522 | } |
| 7523 | |
Cody Northrop | 3bb4d96 | 2016-05-09 16:15:57 -0600 | [diff] [blame] | 7524 | TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) { |
| 7525 | |
| 7526 | TEST_DESCRIPTION("End a command buffer with an active render pass"); |
| 7527 | |
| 7528 | m_errorMonitor->SetDesiredFailureMsg( |
| 7529 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7530 | "It is invalid to issue this call inside an active render pass"); |
| 7531 | |
| 7532 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7533 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7534 | |
| 7535 | // The framework's BeginCommandBuffer calls CreateRenderPass |
| 7536 | BeginCommandBuffer(); |
| 7537 | |
| 7538 | // Call directly into vkEndCommandBuffer instead of the |
| 7539 | // the framework's EndCommandBuffer, which inserts a |
| 7540 | // vkEndRenderPass |
| 7541 | vkEndCommandBuffer(m_commandBuffer->GetBufferHandle()); |
| 7542 | |
| 7543 | m_errorMonitor->VerifyFound(); |
| 7544 | |
| 7545 | // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY |
| 7546 | // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT |
| 7547 | } |
| 7548 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7549 | TEST_F(VkLayerTest, FillBufferWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7550 | // Call CmdFillBuffer within an active renderpass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7551 | m_errorMonitor->SetDesiredFailureMsg( |
| 7552 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7553 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7554 | |
| 7555 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7556 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7557 | |
| 7558 | // Renderpass is started here |
| 7559 | BeginCommandBuffer(); |
| 7560 | |
| 7561 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7562 | vk_testing::Buffer dstBuffer; |
| 7563 | dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7564 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7565 | m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7566 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7567 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7568 | } |
| 7569 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7570 | TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7571 | // Call CmdUpdateBuffer within an active renderpass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7572 | m_errorMonitor->SetDesiredFailureMsg( |
| 7573 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7574 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7575 | |
| 7576 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7577 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7578 | |
| 7579 | // Renderpass is started here |
| 7580 | BeginCommandBuffer(); |
| 7581 | |
| 7582 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7583 | vk_testing::Buffer dstBuffer; |
| 7584 | dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7585 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7586 | VkDeviceSize dstOffset = 0; |
| 7587 | VkDeviceSize dataSize = 1024; |
| 7588 | const uint32_t *pData = NULL; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7589 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7590 | vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), |
| 7591 | dstOffset, dataSize, pData); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7592 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7593 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7594 | } |
| 7595 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7596 | TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7597 | // Call CmdClearColorImage within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7598 | m_errorMonitor->SetDesiredFailureMsg( |
| 7599 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7600 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7601 | |
| 7602 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7603 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7604 | |
| 7605 | // Renderpass is started here |
| 7606 | BeginCommandBuffer(); |
| 7607 | |
Michael Lentine | 0a369f6 | 2016-02-03 16:51:46 -0600 | [diff] [blame] | 7608 | VkClearColorValue clear_color; |
| 7609 | memset(clear_color.uint32, 0, sizeof(uint32_t) * 4); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7610 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 7611 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 7612 | const int32_t tex_width = 32; |
| 7613 | const int32_t tex_height = 32; |
| 7614 | VkImageCreateInfo image_create_info = {}; |
| 7615 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 7616 | image_create_info.pNext = NULL; |
| 7617 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 7618 | image_create_info.format = tex_format; |
| 7619 | image_create_info.extent.width = tex_width; |
| 7620 | image_create_info.extent.height = tex_height; |
| 7621 | image_create_info.extent.depth = 1; |
| 7622 | image_create_info.mipLevels = 1; |
| 7623 | image_create_info.arrayLayers = 1; |
| 7624 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 7625 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 7626 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7627 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7628 | vk_testing::Image dstImage; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7629 | dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 7630 | reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7631 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7632 | const VkImageSubresourceRange range = vk_testing::Image::subresource_range( |
| 7633 | image_create_info, VK_IMAGE_ASPECT_COLOR_BIT); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7634 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7635 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), |
| 7636 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7637 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7638 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7639 | } |
| 7640 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7641 | TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7642 | // Call CmdClearDepthStencilImage within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7643 | m_errorMonitor->SetDesiredFailureMsg( |
| 7644 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7645 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7646 | |
| 7647 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7648 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7649 | |
| 7650 | // Renderpass is started here |
| 7651 | BeginCommandBuffer(); |
| 7652 | |
| 7653 | VkClearDepthStencilValue clear_value = {0}; |
Dustin Graves | a2e5c94 | 2016-02-11 18:28:06 -0700 | [diff] [blame] | 7654 | VkMemoryPropertyFlags reqs = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7655 | VkImageCreateInfo image_create_info = vk_testing::Image::create_info(); |
| 7656 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 7657 | image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 7658 | image_create_info.extent.width = 64; |
| 7659 | image_create_info.extent.height = 64; |
| 7660 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 7661 | image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7662 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7663 | vk_testing::Image dstImage; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7664 | dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 7665 | reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7666 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7667 | const VkImageSubresourceRange range = vk_testing::Image::subresource_range( |
| 7668 | image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7669 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7670 | vkCmdClearDepthStencilImage( |
| 7671 | m_commandBuffer->GetBufferHandle(), dstImage.handle(), |
| 7672 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, |
| 7673 | &range); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7674 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7675 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7676 | } |
| 7677 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7678 | TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) { |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 7679 | // Call CmdClearAttachmentss outside of an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7680 | VkResult err; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7681 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 7682 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7683 | "vkCmdClearAttachments: This call " |
| 7684 | "must be issued inside an active " |
| 7685 | "render pass"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7686 | |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7687 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7688 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7689 | |
| 7690 | // Start no RenderPass |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7691 | err = m_commandBuffer->BeginCommandBuffer(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7692 | ASSERT_VK_SUCCESS(err); |
| 7693 | |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 7694 | VkClearAttachment color_attachment; |
| 7695 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 7696 | color_attachment.clearValue.color.float32[0] = 0; |
| 7697 | color_attachment.clearValue.color.float32[1] = 0; |
| 7698 | color_attachment.clearValue.color.float32[2] = 0; |
| 7699 | color_attachment.clearValue.color.float32[3] = 0; |
| 7700 | color_attachment.colorAttachment = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7701 | VkClearRect clear_rect = {{{0, 0}, {32, 32}}}; |
| 7702 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 7703 | &color_attachment, 1, &clear_rect); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7704 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7705 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7706 | } |
| 7707 | |
Karl Schultz | 9e66a29 | 2016-04-21 15:57:51 -0600 | [diff] [blame] | 7708 | TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) { |
| 7709 | // Try to add a buffer memory barrier with no buffer. |
| 7710 | m_errorMonitor->SetDesiredFailureMsg( |
| 7711 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7712 | "required parameter pBufferMemoryBarriers[i].buffer specified as VK_NULL_HANDLE"); |
| 7713 | |
| 7714 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7715 | BeginCommandBuffer(); |
| 7716 | |
| 7717 | VkBufferMemoryBarrier buf_barrier = {}; |
| 7718 | buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; |
| 7719 | buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 7720 | buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 7721 | buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7722 | buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7723 | buf_barrier.buffer = VK_NULL_HANDLE; |
| 7724 | buf_barrier.offset = 0; |
| 7725 | buf_barrier.size = VK_WHOLE_SIZE; |
| 7726 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7727 | VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, |
| 7728 | 0, 0, nullptr, 1, &buf_barrier, 0, nullptr); |
| 7729 | |
| 7730 | m_errorMonitor->VerifyFound(); |
| 7731 | } |
| 7732 | |
Tony Barbour | 7fd5c0f | 2016-05-03 16:11:53 -0600 | [diff] [blame] | 7733 | TEST_F(VkLayerTest, InvalidBarriers) { |
| 7734 | TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER "); |
| 7735 | |
| 7736 | m_errorMonitor->SetDesiredFailureMsg( |
| 7737 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass"); |
| 7738 | |
| 7739 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7740 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7741 | |
| 7742 | VkMemoryBarrier mem_barrier = {}; |
| 7743 | mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER; |
| 7744 | mem_barrier.pNext = NULL; |
| 7745 | mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 7746 | mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 7747 | BeginCommandBuffer(); |
| 7748 | // BeginCommandBuffer() starts a render pass |
| 7749 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7750 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7751 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1, |
| 7752 | &mem_barrier, 0, nullptr, 0, nullptr); |
| 7753 | m_errorMonitor->VerifyFound(); |
| 7754 | |
| 7755 | m_errorMonitor->SetDesiredFailureMsg( |
| 7756 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7757 | "Image Layout cannot be transitioned to UNDEFINED"); |
| 7758 | VkImageObj image(m_device); |
| 7759 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 7760 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 7761 | ASSERT_TRUE(image.initialized()); |
| 7762 | VkImageMemoryBarrier img_barrier = {}; |
| 7763 | img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 7764 | img_barrier.pNext = NULL; |
| 7765 | img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 7766 | img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 7767 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 7768 | // New layout can't be UNDEFINED |
| 7769 | img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 7770 | img_barrier.image = image.handle(); |
| 7771 | img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7772 | img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7773 | img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 7774 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 7775 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 7776 | img_barrier.subresourceRange.layerCount = 1; |
| 7777 | img_barrier.subresourceRange.levelCount = 1; |
| 7778 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7779 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7780 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 7781 | nullptr, 1, &img_barrier); |
| 7782 | m_errorMonitor->VerifyFound(); |
| 7783 | img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 7784 | |
| 7785 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7786 | "Subresource must have the sum of the " |
| 7787 | "baseArrayLayer"); |
| 7788 | // baseArrayLayer + layerCount must be <= image's arrayLayers |
| 7789 | img_barrier.subresourceRange.baseArrayLayer = 1; |
| 7790 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7791 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7792 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 7793 | nullptr, 1, &img_barrier); |
| 7794 | m_errorMonitor->VerifyFound(); |
| 7795 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 7796 | |
| 7797 | m_errorMonitor->SetDesiredFailureMsg( |
| 7798 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7799 | "Subresource must have the sum of the baseMipLevel"); |
| 7800 | // baseMipLevel + levelCount must be <= image's mipLevels |
| 7801 | img_barrier.subresourceRange.baseMipLevel = 1; |
| 7802 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7803 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7804 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 7805 | nullptr, 1, &img_barrier); |
| 7806 | m_errorMonitor->VerifyFound(); |
| 7807 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 7808 | |
| 7809 | m_errorMonitor->SetDesiredFailureMsg( |
| 7810 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7811 | "Buffer Barriers cannot be used during a render pass"); |
| 7812 | vk_testing::Buffer buffer; |
| 7813 | buffer.init(*m_device, 256); |
| 7814 | VkBufferMemoryBarrier buf_barrier = {}; |
| 7815 | buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; |
| 7816 | buf_barrier.pNext = NULL; |
| 7817 | buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 7818 | buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 7819 | buf_barrier.buffer = buffer.handle(); |
| 7820 | buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7821 | buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7822 | buf_barrier.offset = 0; |
| 7823 | buf_barrier.size = VK_WHOLE_SIZE; |
| 7824 | // Can't send buffer barrier during a render pass |
| 7825 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7826 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7827 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 7828 | &buf_barrier, 0, nullptr); |
| 7829 | m_errorMonitor->VerifyFound(); |
| 7830 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 7831 | |
| 7832 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7833 | "which is not less than total size"); |
| 7834 | buf_barrier.offset = 257; |
| 7835 | // Offset greater than total size |
| 7836 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7837 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7838 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 7839 | &buf_barrier, 0, nullptr); |
| 7840 | m_errorMonitor->VerifyFound(); |
| 7841 | buf_barrier.offset = 0; |
| 7842 | |
| 7843 | m_errorMonitor->SetDesiredFailureMsg( |
| 7844 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size"); |
| 7845 | buf_barrier.size = 257; |
| 7846 | // Size greater than total size |
| 7847 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7848 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7849 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 7850 | &buf_barrier, 0, nullptr); |
| 7851 | m_errorMonitor->VerifyFound(); |
| 7852 | buf_barrier.size = VK_WHOLE_SIZE; |
| 7853 | |
| 7854 | m_errorMonitor->SetDesiredFailureMsg( |
| 7855 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7856 | "Image is a depth and stencil format and thus must " |
| 7857 | "have both VK_IMAGE_ASPECT_DEPTH_BIT and " |
| 7858 | "VK_IMAGE_ASPECT_STENCIL_BIT set."); |
| 7859 | VkDepthStencilObj ds_image(m_device); |
| 7860 | ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT); |
| 7861 | ASSERT_TRUE(ds_image.initialized()); |
| 7862 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 7863 | img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 7864 | img_barrier.image = ds_image.handle(); |
| 7865 | // Leave aspectMask at COLOR on purpose |
| 7866 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7867 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7868 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 7869 | nullptr, 1, &img_barrier); |
| 7870 | m_errorMonitor->VerifyFound(); |
| 7871 | } |
| 7872 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7873 | TEST_F(VkLayerTest, IdxBufferAlignmentError) { |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7874 | // Bind a BeginRenderPass within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7875 | VkResult err; |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7876 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7877 | m_errorMonitor->SetDesiredFailureMsg( |
| 7878 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7879 | "vkCmdBindIndexBuffer() offset (0x7) does not fall on "); |
| 7880 | |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7881 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7882 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7883 | uint32_t qfi = 0; |
| 7884 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7885 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 7886 | buffCI.size = 1024; |
| 7887 | buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; |
| 7888 | buffCI.queueFamilyIndexCount = 1; |
| 7889 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7890 | |
| 7891 | VkBuffer ib; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7892 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7893 | ASSERT_VK_SUCCESS(err); |
| 7894 | |
| 7895 | BeginCommandBuffer(); |
| 7896 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7897 | // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7898 | // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7899 | // 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] | 7900 | vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, |
| 7901 | VK_INDEX_TYPE_UINT16); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7902 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7903 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 7904 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7905 | vkDestroyBuffer(m_device->device(), ib, NULL); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7906 | } |
| 7907 | |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 7908 | TEST_F(VkLayerTest, InvalidQueueFamilyIndex) { |
| 7909 | // Create an out-of-range queueFamilyIndex |
| 7910 | m_errorMonitor->SetDesiredFailureMsg( |
| 7911 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Dustin Graves | de62853 | 2016-04-21 16:30:17 -0600 | [diff] [blame] | 7912 | "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one " |
| 7913 | "of the indices specified when the device was created, via the " |
| 7914 | "VkDeviceQueueCreateInfo structure."); |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 7915 | |
| 7916 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7917 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7918 | VkBufferCreateInfo buffCI = {}; |
| 7919 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 7920 | buffCI.size = 1024; |
| 7921 | buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; |
| 7922 | buffCI.queueFamilyIndexCount = 1; |
| 7923 | // Introduce failure by specifying invalid queue_family_index |
| 7924 | uint32_t qfi = 777; |
| 7925 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 24aab04 | 2016-03-24 10:54:18 -0600 | [diff] [blame] | 7926 | buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 7927 | |
| 7928 | VkBuffer ib; |
| 7929 | vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib); |
| 7930 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7931 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7932 | vkDestroyBuffer(m_device->device(), ib, NULL); |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 7933 | } |
| 7934 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7935 | TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) { |
| 7936 | // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be |
| 7937 | // secondary) |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7938 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7939 | m_errorMonitor->SetDesiredFailureMsg( |
| 7940 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7941 | "vkCmdExecuteCommands() called w/ Primary Cmd Buffer "); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 7942 | |
| 7943 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7944 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 7945 | |
| 7946 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7947 | // ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7948 | VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle(); |
| 7949 | vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 7950 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7951 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 7952 | } |
| 7953 | |
Tobin Ehlis | 17826bd | 2016-05-25 11:12:50 -0600 | [diff] [blame] | 7954 | TEST_F(VkLayerTest, DSUsageBitsErrors) { |
| 7955 | TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers " |
| 7956 | "that do not have correct usage bits sets."); |
| 7957 | VkResult err; |
| 7958 | |
| 7959 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7960 | VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {}; |
| 7961 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 7962 | ds_type_count[i].type = VkDescriptorType(i); |
| 7963 | ds_type_count[i].descriptorCount = 1; |
| 7964 | } |
| 7965 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 7966 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7967 | ds_pool_ci.pNext = NULL; |
| 7968 | ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 7969 | ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 7970 | ds_pool_ci.pPoolSizes = ds_type_count; |
| 7971 | |
| 7972 | VkDescriptorPool ds_pool; |
| 7973 | err = |
| 7974 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 7975 | ASSERT_VK_SUCCESS(err); |
| 7976 | |
| 7977 | // Create 10 layouts where each has a single descriptor of different type |
| 7978 | VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = |
| 7979 | {}; |
| 7980 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 7981 | dsl_binding[i].binding = 0; |
| 7982 | dsl_binding[i].descriptorType = VkDescriptorType(i); |
| 7983 | dsl_binding[i].descriptorCount = 1; |
| 7984 | dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL; |
| 7985 | dsl_binding[i].pImmutableSamplers = NULL; |
| 7986 | } |
| 7987 | |
| 7988 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 7989 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7990 | ds_layout_ci.pNext = NULL; |
| 7991 | ds_layout_ci.bindingCount = 1; |
| 7992 | VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE]; |
| 7993 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 7994 | ds_layout_ci.pBindings = dsl_binding + i; |
| 7995 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, |
| 7996 | NULL, ds_layouts + i); |
| 7997 | ASSERT_VK_SUCCESS(err); |
| 7998 | } |
| 7999 | VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {}; |
| 8000 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 8001 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 8002 | alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 8003 | alloc_info.descriptorPool = ds_pool; |
| 8004 | alloc_info.pSetLayouts = ds_layouts; |
| 8005 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8006 | descriptor_sets); |
| 8007 | ASSERT_VK_SUCCESS(err); |
| 8008 | |
| 8009 | // Create a buffer & bufferView to be used for invalid updates |
| 8010 | VkBufferCreateInfo buff_ci = {}; |
| 8011 | buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 8012 | // This usage is not valid for any descriptor type |
| 8013 | buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; |
| 8014 | buff_ci.size = 256; |
| 8015 | buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 8016 | VkBuffer buffer; |
| 8017 | err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer); |
| 8018 | ASSERT_VK_SUCCESS(err); |
| 8019 | |
| 8020 | VkBufferViewCreateInfo buff_view_ci = {}; |
| 8021 | buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; |
| 8022 | buff_view_ci.buffer = buffer; |
| 8023 | buff_view_ci.format = VK_FORMAT_R8_UNORM; |
| 8024 | buff_view_ci.range = VK_WHOLE_SIZE; |
| 8025 | VkBufferView buff_view; |
| 8026 | err = |
| 8027 | vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view); |
| 8028 | ASSERT_VK_SUCCESS(err); |
| 8029 | |
| 8030 | // Create an image to be used for invalid updates |
| 8031 | VkImageCreateInfo image_ci = {}; |
| 8032 | image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 8033 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 8034 | image_ci.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 8035 | image_ci.extent.width = 64; |
| 8036 | image_ci.extent.height = 64; |
| 8037 | image_ci.extent.depth = 1; |
| 8038 | image_ci.mipLevels = 1; |
| 8039 | image_ci.arrayLayers = 1; |
| 8040 | image_ci.samples = VK_SAMPLE_COUNT_1_BIT; |
| 8041 | image_ci.tiling = VK_IMAGE_TILING_LINEAR; |
| 8042 | image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 8043 | // This usage is not valid for any descriptor type |
| 8044 | image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 8045 | image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 8046 | VkImage image; |
| 8047 | err = vkCreateImage(m_device->device(), &image_ci, NULL, &image); |
| 8048 | ASSERT_VK_SUCCESS(err); |
| 8049 | // Bind memory to image |
| 8050 | VkMemoryRequirements mem_reqs; |
| 8051 | VkDeviceMemory image_mem; |
| 8052 | bool pass; |
| 8053 | VkMemoryAllocateInfo mem_alloc = {}; |
| 8054 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 8055 | mem_alloc.pNext = NULL; |
| 8056 | mem_alloc.allocationSize = 0; |
| 8057 | mem_alloc.memoryTypeIndex = 0; |
| 8058 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 8059 | mem_alloc.allocationSize = mem_reqs.size; |
| 8060 | pass = |
| 8061 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 8062 | ASSERT_TRUE(pass); |
| 8063 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem); |
| 8064 | ASSERT_VK_SUCCESS(err); |
| 8065 | err = vkBindImageMemory(m_device->device(), image, image_mem, 0); |
| 8066 | ASSERT_VK_SUCCESS(err); |
| 8067 | // Now create view for image |
| 8068 | VkImageViewCreateInfo image_view_ci = {}; |
| 8069 | image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 8070 | image_view_ci.image = image; |
| 8071 | image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 8072 | image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 8073 | image_view_ci.subresourceRange.layerCount = 1; |
| 8074 | image_view_ci.subresourceRange.baseArrayLayer = 0; |
| 8075 | image_view_ci.subresourceRange.levelCount = 1; |
| 8076 | image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 8077 | VkImageView image_view; |
| 8078 | err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, |
| 8079 | &image_view); |
| 8080 | ASSERT_VK_SUCCESS(err); |
| 8081 | |
| 8082 | VkDescriptorBufferInfo buff_info = {}; |
| 8083 | buff_info.buffer = buffer; |
| 8084 | VkDescriptorImageInfo img_info = {}; |
| 8085 | img_info.imageView = image_view; |
| 8086 | VkWriteDescriptorSet descriptor_write = {}; |
| 8087 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 8088 | descriptor_write.dstBinding = 0; |
| 8089 | descriptor_write.descriptorCount = 1; |
| 8090 | descriptor_write.pTexelBufferView = &buff_view; |
| 8091 | descriptor_write.pBufferInfo = &buff_info; |
| 8092 | descriptor_write.pImageInfo = &img_info; |
| 8093 | |
| 8094 | // These error messages align with VkDescriptorType struct |
| 8095 | const char *error_msgs[] = { |
| 8096 | "", // placeholder, no error for SAMPLER descriptor |
| 8097 | " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.", |
| 8098 | " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.", |
| 8099 | " does not have VK_IMAGE_USAGE_STORAGE_BIT set.", |
| 8100 | " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.", |
| 8101 | " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.", |
| 8102 | " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.", |
| 8103 | " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.", |
| 8104 | " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.", |
| 8105 | " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.", |
| 8106 | " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."}; |
| 8107 | // Start loop at 1 as SAMPLER desc type has no usage bit error |
| 8108 | for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 8109 | descriptor_write.descriptorType = VkDescriptorType(i); |
| 8110 | descriptor_write.dstSet = descriptor_sets[i]; |
| 8111 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8112 | error_msgs[i]); |
| 8113 | |
| 8114 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, |
| 8115 | NULL); |
| 8116 | |
| 8117 | m_errorMonitor->VerifyFound(); |
| 8118 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL); |
| 8119 | } |
| 8120 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL); |
| 8121 | vkDestroyImage(m_device->device(), image, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 8122 | vkFreeMemory(m_device->device(), image_mem, NULL); |
Tobin Ehlis | 17826bd | 2016-05-25 11:12:50 -0600 | [diff] [blame] | 8123 | vkDestroyImageView(m_device->device(), image_view, NULL); |
| 8124 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 8125 | vkDestroyBufferView(m_device->device(), buff_view, NULL); |
| 8126 | vkFreeDescriptorSets(m_device->device(), ds_pool, |
| 8127 | VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets); |
| 8128 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 8129 | } |
| 8130 | |
Tobin Ehlis | 2fc296b | 2016-06-15 14:05:27 -0600 | [diff] [blame] | 8131 | TEST_F(VkLayerTest, DSAspectBitsErrors) { |
| 8132 | // TODO : Initially only catching case where DEPTH & STENCIL aspect bits |
| 8133 | // are set, but could expand this test to hit more cases. |
| 8134 | TEST_DESCRIPTION("Attempt to update descriptor sets for images " |
| 8135 | "that do not have correct aspect bits sets."); |
| 8136 | VkResult err; |
| 8137 | |
| 8138 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8139 | VkDescriptorPoolSize ds_type_count = {}; |
| 8140 | ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 8141 | ds_type_count.descriptorCount = 1; |
| 8142 | |
| 8143 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 8144 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8145 | ds_pool_ci.pNext = NULL; |
| 8146 | ds_pool_ci.maxSets = 5; |
| 8147 | ds_pool_ci.poolSizeCount = 1; |
| 8148 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 8149 | |
| 8150 | VkDescriptorPool ds_pool; |
| 8151 | err = |
| 8152 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 8153 | ASSERT_VK_SUCCESS(err); |
| 8154 | |
| 8155 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 8156 | dsl_binding.binding = 0; |
| 8157 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 8158 | dsl_binding.descriptorCount = 1; |
| 8159 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8160 | dsl_binding.pImmutableSamplers = NULL; |
| 8161 | |
| 8162 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 8163 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8164 | ds_layout_ci.pNext = NULL; |
| 8165 | ds_layout_ci.bindingCount = 1; |
| 8166 | ds_layout_ci.pBindings = &dsl_binding; |
| 8167 | VkDescriptorSetLayout ds_layout; |
| 8168 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8169 | &ds_layout); |
| 8170 | ASSERT_VK_SUCCESS(err); |
| 8171 | |
| 8172 | VkDescriptorSet descriptor_set = {}; |
| 8173 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 8174 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 8175 | alloc_info.descriptorSetCount = 1; |
| 8176 | alloc_info.descriptorPool = ds_pool; |
| 8177 | alloc_info.pSetLayouts = &ds_layout; |
| 8178 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8179 | &descriptor_set); |
| 8180 | ASSERT_VK_SUCCESS(err); |
| 8181 | |
| 8182 | // Create an image to be used for invalid updates |
| 8183 | VkImageCreateInfo image_ci = {}; |
| 8184 | image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 8185 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 8186 | image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 8187 | image_ci.extent.width = 64; |
| 8188 | image_ci.extent.height = 64; |
| 8189 | image_ci.extent.depth = 1; |
| 8190 | image_ci.mipLevels = 1; |
| 8191 | image_ci.arrayLayers = 1; |
| 8192 | image_ci.samples = VK_SAMPLE_COUNT_1_BIT; |
| 8193 | image_ci.tiling = VK_IMAGE_TILING_LINEAR; |
| 8194 | image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 8195 | image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 8196 | image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 8197 | VkImage image; |
| 8198 | err = vkCreateImage(m_device->device(), &image_ci, NULL, &image); |
| 8199 | ASSERT_VK_SUCCESS(err); |
| 8200 | // Bind memory to image |
| 8201 | VkMemoryRequirements mem_reqs; |
| 8202 | VkDeviceMemory image_mem; |
| 8203 | bool pass; |
| 8204 | VkMemoryAllocateInfo mem_alloc = {}; |
| 8205 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 8206 | mem_alloc.pNext = NULL; |
| 8207 | mem_alloc.allocationSize = 0; |
| 8208 | mem_alloc.memoryTypeIndex = 0; |
| 8209 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 8210 | mem_alloc.allocationSize = mem_reqs.size; |
| 8211 | pass = |
| 8212 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 8213 | ASSERT_TRUE(pass); |
| 8214 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem); |
| 8215 | ASSERT_VK_SUCCESS(err); |
| 8216 | err = vkBindImageMemory(m_device->device(), image, image_mem, 0); |
| 8217 | ASSERT_VK_SUCCESS(err); |
| 8218 | // Now create view for image |
| 8219 | VkImageViewCreateInfo image_view_ci = {}; |
| 8220 | image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 8221 | image_view_ci.image = image; |
| 8222 | image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 8223 | image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 8224 | image_view_ci.subresourceRange.layerCount = 1; |
| 8225 | image_view_ci.subresourceRange.baseArrayLayer = 0; |
| 8226 | image_view_ci.subresourceRange.levelCount = 1; |
| 8227 | // Setting both depth & stencil aspect bits is illegal for descriptor |
| 8228 | image_view_ci.subresourceRange.aspectMask = |
| 8229 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 8230 | |
| 8231 | VkImageView image_view; |
| 8232 | err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, |
| 8233 | &image_view); |
| 8234 | ASSERT_VK_SUCCESS(err); |
| 8235 | |
| 8236 | VkDescriptorImageInfo img_info = {}; |
| 8237 | img_info.imageView = image_view; |
| 8238 | VkWriteDescriptorSet descriptor_write = {}; |
| 8239 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 8240 | descriptor_write.dstBinding = 0; |
| 8241 | descriptor_write.descriptorCount = 1; |
| 8242 | descriptor_write.pTexelBufferView = NULL; |
| 8243 | descriptor_write.pBufferInfo = NULL; |
| 8244 | descriptor_write.pImageInfo = &img_info; |
| 8245 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 8246 | descriptor_write.dstSet = descriptor_set; |
| 8247 | const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT " |
| 8248 | "or VK_IMAGE_ASPECT_STENCIL_BIT "; |
| 8249 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8250 | error_msg); |
| 8251 | |
| 8252 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8253 | |
| 8254 | m_errorMonitor->VerifyFound(); |
| 8255 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8256 | vkDestroyImage(m_device->device(), image, NULL); |
| 8257 | vkFreeMemory(m_device->device(), image_mem, NULL); |
| 8258 | vkDestroyImageView(m_device->device(), image_view, NULL); |
| 8259 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set); |
| 8260 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 8261 | } |
| 8262 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8263 | TEST_F(VkLayerTest, DSTypeMismatch) { |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8264 | // 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] | 8265 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8266 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8267 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8268 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8269 | " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update " |
| 8270 | "type is VK_DESCRIPTOR_TYPE_SAMPLER"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8271 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8272 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8273 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8274 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8275 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8276 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8277 | |
| 8278 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8279 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8280 | ds_pool_ci.pNext = NULL; |
| 8281 | ds_pool_ci.maxSets = 1; |
| 8282 | ds_pool_ci.poolSizeCount = 1; |
| 8283 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8284 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8285 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8286 | err = |
| 8287 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8288 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8289 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8290 | dsl_binding.binding = 0; |
| 8291 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8292 | dsl_binding.descriptorCount = 1; |
| 8293 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8294 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8295 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8296 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8297 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8298 | ds_layout_ci.pNext = NULL; |
| 8299 | ds_layout_ci.bindingCount = 1; |
| 8300 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8301 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8302 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8303 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8304 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8305 | ASSERT_VK_SUCCESS(err); |
| 8306 | |
| 8307 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8308 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8309 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8310 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8311 | alloc_info.descriptorPool = ds_pool; |
| 8312 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8313 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8314 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8315 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8316 | |
Tobin Ehlis | 30db8f8 | 2016-05-05 08:19:48 -0600 | [diff] [blame] | 8317 | VkSamplerCreateInfo sampler_ci = {}; |
| 8318 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8319 | sampler_ci.pNext = NULL; |
| 8320 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8321 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8322 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8323 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8324 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8325 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8326 | sampler_ci.mipLodBias = 1.0; |
| 8327 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8328 | sampler_ci.maxAnisotropy = 1; |
| 8329 | sampler_ci.compareEnable = VK_FALSE; |
| 8330 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8331 | sampler_ci.minLod = 1.0; |
| 8332 | sampler_ci.maxLod = 1.0; |
| 8333 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8334 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
| 8335 | VkSampler sampler; |
| 8336 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
| 8337 | ASSERT_VK_SUCCESS(err); |
| 8338 | |
| 8339 | VkDescriptorImageInfo info = {}; |
| 8340 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8341 | |
| 8342 | VkWriteDescriptorSet descriptor_write; |
| 8343 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8344 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8345 | descriptor_write.dstSet = descriptorSet; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8346 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8347 | // This is a mismatched type for the layout which expects BUFFER |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8348 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8349 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8350 | |
| 8351 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8352 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8353 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8354 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8355 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8356 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8357 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8358 | } |
| 8359 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8360 | TEST_F(VkLayerTest, DSUpdateOutOfBounds) { |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8361 | // For overlapping Update, have arrayIndex exceed that of layout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8362 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8363 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8364 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8365 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8366 | " binding #0 with 1 total descriptors but update of 1 descriptors " |
| 8367 | "starting at binding offset of 0 combined with update array element " |
| 8368 | "offset of 1 oversteps the size of this descriptor set."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8369 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8370 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8371 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8372 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8373 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8374 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8375 | |
| 8376 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8377 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8378 | ds_pool_ci.pNext = NULL; |
| 8379 | ds_pool_ci.maxSets = 1; |
| 8380 | ds_pool_ci.poolSizeCount = 1; |
| 8381 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8382 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8383 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8384 | err = |
| 8385 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8386 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8387 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8388 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8389 | dsl_binding.binding = 0; |
| 8390 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8391 | dsl_binding.descriptorCount = 1; |
| 8392 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8393 | dsl_binding.pImmutableSamplers = NULL; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8394 | |
| 8395 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8396 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8397 | ds_layout_ci.pNext = NULL; |
| 8398 | ds_layout_ci.bindingCount = 1; |
| 8399 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8400 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8401 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8402 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8403 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8404 | ASSERT_VK_SUCCESS(err); |
| 8405 | |
| 8406 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8407 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8408 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8409 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8410 | alloc_info.descriptorPool = ds_pool; |
| 8411 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8412 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8413 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8414 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8415 | |
Tobin Ehlis | 30db8f8 | 2016-05-05 08:19:48 -0600 | [diff] [blame] | 8416 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 8417 | VkDescriptorBufferInfo buff_info = {}; |
| 8418 | buff_info.buffer = |
| 8419 | VkBuffer(0); // Don't care about buffer handle for this test |
| 8420 | buff_info.offset = 0; |
| 8421 | buff_info.range = 1024; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8422 | |
| 8423 | VkWriteDescriptorSet descriptor_write; |
| 8424 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8425 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8426 | descriptor_write.dstSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8427 | descriptor_write.dstArrayElement = |
| 8428 | 1; /* This index out of bounds for the update */ |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8429 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8430 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8431 | descriptor_write.pBufferInfo = &buff_info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8432 | |
| 8433 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8434 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8435 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8436 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8437 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8438 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8439 | } |
| 8440 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8441 | TEST_F(VkLayerTest, InvalidDSUpdateIndex) { |
| 8442 | // Create layout w/ count of 1 and attempt update to that layout w/ binding |
| 8443 | // index 2 |
| 8444 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8445 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8446 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8447 | " does not have binding 2."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8448 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8449 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8450 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8451 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8452 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8453 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8454 | |
| 8455 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8456 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8457 | ds_pool_ci.pNext = NULL; |
| 8458 | ds_pool_ci.maxSets = 1; |
| 8459 | ds_pool_ci.poolSizeCount = 1; |
| 8460 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 8461 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8462 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8463 | err = |
| 8464 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8465 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8466 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8467 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8468 | dsl_binding.binding = 0; |
| 8469 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8470 | dsl_binding.descriptorCount = 1; |
| 8471 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8472 | dsl_binding.pImmutableSamplers = NULL; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8473 | |
| 8474 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8475 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8476 | ds_layout_ci.pNext = NULL; |
| 8477 | ds_layout_ci.bindingCount = 1; |
| 8478 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8479 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8480 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8481 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8482 | ASSERT_VK_SUCCESS(err); |
| 8483 | |
| 8484 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8485 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8486 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8487 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8488 | alloc_info.descriptorPool = ds_pool; |
| 8489 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8490 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8491 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8492 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8493 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8494 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8495 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8496 | sampler_ci.pNext = NULL; |
| 8497 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8498 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8499 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8500 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8501 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8502 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8503 | sampler_ci.mipLodBias = 1.0; |
| 8504 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8505 | sampler_ci.maxAnisotropy = 1; |
| 8506 | sampler_ci.compareEnable = VK_FALSE; |
| 8507 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8508 | sampler_ci.minLod = 1.0; |
| 8509 | sampler_ci.maxLod = 1.0; |
| 8510 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8511 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8512 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8513 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8514 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8515 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8516 | |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8517 | VkDescriptorImageInfo info = {}; |
| 8518 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8519 | |
| 8520 | VkWriteDescriptorSet descriptor_write; |
| 8521 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8522 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8523 | descriptor_write.dstSet = descriptorSet; |
| 8524 | descriptor_write.dstBinding = 2; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8525 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8526 | // 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] | 8527 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8528 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8529 | |
| 8530 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8531 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8532 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8533 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8534 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8535 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8536 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8537 | } |
| 8538 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8539 | TEST_F(VkLayerTest, InvalidDSUpdateStruct) { |
| 8540 | // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* |
| 8541 | // types |
| 8542 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8543 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 8544 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 660bcdc | 2016-05-17 10:39:46 -0600 | [diff] [blame] | 8545 | ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8546 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8547 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 8548 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8549 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8550 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8551 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8552 | |
| 8553 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8554 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8555 | ds_pool_ci.pNext = NULL; |
| 8556 | ds_pool_ci.maxSets = 1; |
| 8557 | ds_pool_ci.poolSizeCount = 1; |
| 8558 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 8559 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8560 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8561 | err = |
| 8562 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8563 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8564 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8565 | dsl_binding.binding = 0; |
| 8566 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8567 | dsl_binding.descriptorCount = 1; |
| 8568 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8569 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8570 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8571 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8572 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8573 | ds_layout_ci.pNext = NULL; |
| 8574 | ds_layout_ci.bindingCount = 1; |
| 8575 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8576 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8577 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8578 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8579 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8580 | ASSERT_VK_SUCCESS(err); |
| 8581 | |
| 8582 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8583 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8584 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8585 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8586 | alloc_info.descriptorPool = ds_pool; |
| 8587 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8588 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8589 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8590 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8591 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8592 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8593 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8594 | sampler_ci.pNext = NULL; |
| 8595 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8596 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8597 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8598 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8599 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8600 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8601 | sampler_ci.mipLodBias = 1.0; |
| 8602 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8603 | sampler_ci.maxAnisotropy = 1; |
| 8604 | sampler_ci.compareEnable = VK_FALSE; |
| 8605 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8606 | sampler_ci.minLod = 1.0; |
| 8607 | sampler_ci.maxLod = 1.0; |
| 8608 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8609 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8610 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8611 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8612 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8613 | |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8614 | VkDescriptorImageInfo info = {}; |
| 8615 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8616 | |
| 8617 | VkWriteDescriptorSet descriptor_write; |
| 8618 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8619 | descriptor_write.sType = |
| 8620 | (VkStructureType)0x99999999; /* Intentionally broken struct type */ |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8621 | descriptor_write.dstSet = descriptorSet; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8622 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8623 | // 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] | 8624 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8625 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8626 | |
| 8627 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8628 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8629 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8630 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8631 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8632 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8633 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8634 | } |
| 8635 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8636 | TEST_F(VkLayerTest, SampleDescriptorUpdateError) { |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8637 | // Create a single Sampler descriptor and send it an invalid Sampler |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8638 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8639 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8640 | m_errorMonitor->SetDesiredFailureMsg( |
| 8641 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8642 | "Attempted write update to sampler descriptor with invalid sampler"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8643 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8644 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8645 | // TODO : Farm Descriptor setup code to helper function(s) to reduce copied |
| 8646 | // code |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8647 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8648 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8649 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8650 | |
| 8651 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8652 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8653 | ds_pool_ci.pNext = NULL; |
| 8654 | ds_pool_ci.maxSets = 1; |
| 8655 | ds_pool_ci.poolSizeCount = 1; |
| 8656 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8657 | |
| 8658 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8659 | err = |
| 8660 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8661 | ASSERT_VK_SUCCESS(err); |
| 8662 | |
| 8663 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8664 | dsl_binding.binding = 0; |
| 8665 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8666 | dsl_binding.descriptorCount = 1; |
| 8667 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8668 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8669 | |
| 8670 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8671 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8672 | ds_layout_ci.pNext = NULL; |
| 8673 | ds_layout_ci.bindingCount = 1; |
| 8674 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8675 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8676 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8677 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8678 | ASSERT_VK_SUCCESS(err); |
| 8679 | |
| 8680 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8681 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8682 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8683 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8684 | alloc_info.descriptorPool = ds_pool; |
| 8685 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8686 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8687 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8688 | ASSERT_VK_SUCCESS(err); |
| 8689 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8690 | VkSampler sampler = |
| 8691 | (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8692 | |
| 8693 | VkDescriptorImageInfo descriptor_info; |
| 8694 | memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo)); |
| 8695 | descriptor_info.sampler = sampler; |
| 8696 | |
| 8697 | VkWriteDescriptorSet descriptor_write; |
| 8698 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8699 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8700 | descriptor_write.dstSet = descriptorSet; |
| 8701 | descriptor_write.dstBinding = 0; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8702 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8703 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8704 | descriptor_write.pImageInfo = &descriptor_info; |
| 8705 | |
| 8706 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8707 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8708 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8709 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8710 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8711 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8712 | } |
| 8713 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8714 | TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) { |
| 8715 | // Create a single combined Image/Sampler descriptor and send it an invalid |
| 8716 | // imageView |
| 8717 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8718 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8719 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8720 | "Attempted write update to combined " |
| 8721 | "image sampler descriptor failed due " |
Tobin Ehlis | 63c4b8a | 2016-05-09 10:29:34 -0600 | [diff] [blame] | 8722 | "to: Invalid VkImageView:"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8723 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8724 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8725 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8726 | ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 8727 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8728 | |
| 8729 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8730 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8731 | ds_pool_ci.pNext = NULL; |
| 8732 | ds_pool_ci.maxSets = 1; |
| 8733 | ds_pool_ci.poolSizeCount = 1; |
| 8734 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8735 | |
| 8736 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8737 | err = |
| 8738 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8739 | ASSERT_VK_SUCCESS(err); |
| 8740 | |
| 8741 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8742 | dsl_binding.binding = 0; |
| 8743 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 8744 | dsl_binding.descriptorCount = 1; |
| 8745 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8746 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8747 | |
| 8748 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8749 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8750 | ds_layout_ci.pNext = NULL; |
| 8751 | ds_layout_ci.bindingCount = 1; |
| 8752 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8753 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8754 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8755 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8756 | ASSERT_VK_SUCCESS(err); |
| 8757 | |
| 8758 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8759 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8760 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8761 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8762 | alloc_info.descriptorPool = ds_pool; |
| 8763 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8764 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8765 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8766 | ASSERT_VK_SUCCESS(err); |
| 8767 | |
| 8768 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8769 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8770 | sampler_ci.pNext = NULL; |
| 8771 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8772 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8773 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8774 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8775 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8776 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8777 | sampler_ci.mipLodBias = 1.0; |
| 8778 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8779 | sampler_ci.maxAnisotropy = 1; |
| 8780 | sampler_ci.compareEnable = VK_FALSE; |
| 8781 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8782 | sampler_ci.minLod = 1.0; |
| 8783 | sampler_ci.maxLod = 1.0; |
| 8784 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8785 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8786 | |
| 8787 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8788 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8789 | ASSERT_VK_SUCCESS(err); |
| 8790 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8791 | VkImageView view = |
| 8792 | (VkImageView)((size_t)0xbaadbeef); // invalid imageView object |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8793 | |
| 8794 | VkDescriptorImageInfo descriptor_info; |
| 8795 | memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo)); |
| 8796 | descriptor_info.sampler = sampler; |
| 8797 | descriptor_info.imageView = view; |
| 8798 | |
| 8799 | VkWriteDescriptorSet descriptor_write; |
| 8800 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8801 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8802 | descriptor_write.dstSet = descriptorSet; |
| 8803 | descriptor_write.dstBinding = 0; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8804 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8805 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 8806 | descriptor_write.pImageInfo = &descriptor_info; |
| 8807 | |
| 8808 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8809 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8810 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8811 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8812 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8813 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8814 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8815 | } |
| 8816 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8817 | TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) { |
| 8818 | // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update |
| 8819 | // into the other |
| 8820 | VkResult err; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8821 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8822 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8823 | " binding #1 with type " |
| 8824 | "VK_DESCRIPTOR_TYPE_SAMPLER. Types do " |
| 8825 | "not match."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8826 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8827 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8828 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8829 | VkDescriptorPoolSize ds_type_count[2] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8830 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8831 | ds_type_count[0].descriptorCount = 1; |
| 8832 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8833 | ds_type_count[1].descriptorCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8834 | |
| 8835 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8836 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8837 | ds_pool_ci.pNext = NULL; |
| 8838 | ds_pool_ci.maxSets = 1; |
| 8839 | ds_pool_ci.poolSizeCount = 2; |
| 8840 | ds_pool_ci.pPoolSizes = ds_type_count; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8841 | |
| 8842 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8843 | err = |
| 8844 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8845 | ASSERT_VK_SUCCESS(err); |
| 8846 | VkDescriptorSetLayoutBinding dsl_binding[2] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8847 | dsl_binding[0].binding = 0; |
| 8848 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8849 | dsl_binding[0].descriptorCount = 1; |
| 8850 | dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 8851 | dsl_binding[0].pImmutableSamplers = NULL; |
| 8852 | dsl_binding[1].binding = 1; |
| 8853 | dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8854 | dsl_binding[1].descriptorCount = 1; |
| 8855 | dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL; |
| 8856 | dsl_binding[1].pImmutableSamplers = NULL; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8857 | |
| 8858 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8859 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8860 | ds_layout_ci.pNext = NULL; |
| 8861 | ds_layout_ci.bindingCount = 2; |
| 8862 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8863 | |
| 8864 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8865 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8866 | &ds_layout); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8867 | ASSERT_VK_SUCCESS(err); |
| 8868 | |
| 8869 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8870 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8871 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8872 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8873 | alloc_info.descriptorPool = ds_pool; |
| 8874 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8875 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8876 | &descriptorSet); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8877 | ASSERT_VK_SUCCESS(err); |
| 8878 | |
| 8879 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8880 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8881 | sampler_ci.pNext = NULL; |
| 8882 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8883 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8884 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8885 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8886 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8887 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8888 | sampler_ci.mipLodBias = 1.0; |
| 8889 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8890 | sampler_ci.maxAnisotropy = 1; |
| 8891 | sampler_ci.compareEnable = VK_FALSE; |
| 8892 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8893 | sampler_ci.minLod = 1.0; |
| 8894 | sampler_ci.maxLod = 1.0; |
| 8895 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8896 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8897 | |
| 8898 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8899 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8900 | ASSERT_VK_SUCCESS(err); |
| 8901 | |
| 8902 | VkDescriptorImageInfo info = {}; |
| 8903 | info.sampler = sampler; |
| 8904 | |
| 8905 | VkWriteDescriptorSet descriptor_write; |
| 8906 | memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet)); |
| 8907 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8908 | descriptor_write.dstSet = descriptorSet; |
| 8909 | descriptor_write.dstBinding = 1; // SAMPLER binding from layout above |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8910 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8911 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8912 | descriptor_write.pImageInfo = &info; |
| 8913 | // This write update should succeed |
| 8914 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8915 | // Now perform a copy update that fails due to type mismatch |
| 8916 | VkCopyDescriptorSet copy_ds_update; |
| 8917 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 8918 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 8919 | copy_ds_update.srcSet = descriptorSet; |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 8920 | copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8921 | copy_ds_update.dstSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8922 | copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8923 | copy_ds_update.descriptorCount = 1; // copy 1 descriptor |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8924 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 8925 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8926 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8927 | // 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] | 8928 | m_errorMonitor->SetDesiredFailureMsg( |
| 8929 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8930 | " does not have copy update src binding of 3."); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8931 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 8932 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 8933 | copy_ds_update.srcSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8934 | copy_ds_update.srcBinding = |
| 8935 | 3; // ERROR : Invalid binding for matching layout |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8936 | copy_ds_update.dstSet = descriptorSet; |
| 8937 | copy_ds_update.dstBinding = 0; |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 8938 | copy_ds_update.descriptorCount = 1; // Copy 1 descriptor |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8939 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 8940 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8941 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8942 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8943 | // 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] | 8944 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8945 | VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus " |
| 8946 | "update array offset of 0 and update of " |
| 8947 | "5 descriptors oversteps total number " |
| 8948 | "of descriptors in set: 2."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8949 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8950 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 8951 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 8952 | copy_ds_update.srcSet = descriptorSet; |
| 8953 | copy_ds_update.srcBinding = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8954 | copy_ds_update.dstSet = descriptorSet; |
| 8955 | copy_ds_update.dstBinding = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8956 | copy_ds_update.descriptorCount = |
| 8957 | 5; // ERROR copy 5 descriptors (out of bounds for layout) |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8958 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 8959 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8960 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8961 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8962 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8963 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8964 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8965 | } |
| 8966 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8967 | TEST_F(VkLayerTest, NumSamplesMismatch) { |
| 8968 | // Create CommandBuffer where MSAA samples doesn't match RenderPass |
| 8969 | // sampleCount |
| 8970 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8971 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 8972 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8973 | "Num samples mismatch! "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8974 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8975 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8976 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8977 | VkDescriptorPoolSize ds_type_count = {}; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8978 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8979 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8980 | |
| 8981 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8982 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8983 | ds_pool_ci.pNext = NULL; |
| 8984 | ds_pool_ci.maxSets = 1; |
| 8985 | ds_pool_ci.poolSizeCount = 1; |
| 8986 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 8987 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8988 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8989 | err = |
| 8990 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8991 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8992 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8993 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 8994 | dsl_binding.binding = 0; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8995 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | 0212448 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 8996 | dsl_binding.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8997 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8998 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8999 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9000 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9001 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9002 | ds_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9003 | ds_layout_ci.bindingCount = 1; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 9004 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9005 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9006 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9007 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9008 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9009 | ASSERT_VK_SUCCESS(err); |
| 9010 | |
| 9011 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9012 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9013 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9014 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9015 | alloc_info.descriptorPool = ds_pool; |
| 9016 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9017 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9018 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9019 | ASSERT_VK_SUCCESS(err); |
| 9020 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9021 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9022 | pipe_ms_state_ci.sType = |
| 9023 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9024 | pipe_ms_state_ci.pNext = NULL; |
| 9025 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT; |
| 9026 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9027 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9028 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9029 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9030 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9031 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9032 | pipeline_layout_ci.pNext = NULL; |
| 9033 | pipeline_layout_ci.setLayoutCount = 1; |
| 9034 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9035 | |
| 9036 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9037 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9038 | &pipeline_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9039 | ASSERT_VK_SUCCESS(err); |
| 9040 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9041 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9042 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9043 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9044 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9045 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9046 | // but add it to be able to run on more devices |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9047 | VkPipelineObj pipe(m_device); |
| 9048 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 9049 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9050 | pipe.AddColorAttachment(); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9051 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 9052 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9053 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 9054 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9055 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9056 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9057 | |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9058 | // Render triangle (the error should trigger on the attempt to draw). |
| 9059 | Draw(3, 1, 0, 0); |
| 9060 | |
| 9061 | // Finalize recording of the command buffer |
| 9062 | EndCommandBuffer(); |
| 9063 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9064 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9065 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9066 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9067 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9068 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9069 | } |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9070 | |
Tobin Ehlis | 85aa15a | 2016-06-15 10:52:37 -0600 | [diff] [blame] | 9071 | TEST_F(VkLayerTest, RenderPassIncompatible) { |
| 9072 | TEST_DESCRIPTION("Hit RenderPass incompatible cases. " |
| 9073 | "Initial case is drawing with an active renderpass that's " |
| 9074 | "not compatible with the bound PSO's creation renderpass"); |
| 9075 | VkResult err; |
| 9076 | |
| 9077 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9078 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9079 | |
| 9080 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 9081 | dsl_binding.binding = 0; |
| 9082 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9083 | dsl_binding.descriptorCount = 1; |
| 9084 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9085 | dsl_binding.pImmutableSamplers = NULL; |
| 9086 | |
| 9087 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9088 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9089 | ds_layout_ci.pNext = NULL; |
| 9090 | ds_layout_ci.bindingCount = 1; |
| 9091 | ds_layout_ci.pBindings = &dsl_binding; |
| 9092 | |
| 9093 | VkDescriptorSetLayout ds_layout; |
| 9094 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9095 | &ds_layout); |
| 9096 | ASSERT_VK_SUCCESS(err); |
| 9097 | |
| 9098 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 9099 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9100 | pipeline_layout_ci.pNext = NULL; |
| 9101 | pipeline_layout_ci.setLayoutCount = 1; |
| 9102 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 9103 | |
| 9104 | VkPipelineLayout pipeline_layout; |
| 9105 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9106 | &pipeline_layout); |
| 9107 | ASSERT_VK_SUCCESS(err); |
| 9108 | |
| 9109 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9110 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9111 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9112 | VK_SHADER_STAGE_FRAGMENT_BIT, |
| 9113 | this); // We shouldn't need a fragment shader |
| 9114 | // but add it to be able to run on more devices |
| 9115 | // Create a renderpass that will be incompatible with default renderpass |
| 9116 | VkAttachmentReference attach = {}; |
| 9117 | attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 9118 | VkAttachmentReference color_att = {}; |
| 9119 | color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 9120 | VkSubpassDescription subpass = {}; |
| 9121 | subpass.inputAttachmentCount = 1; |
| 9122 | subpass.pInputAttachments = &attach; |
| 9123 | subpass.colorAttachmentCount = 1; |
| 9124 | subpass.pColorAttachments = &color_att; |
| 9125 | VkRenderPassCreateInfo rpci = {}; |
| 9126 | rpci.subpassCount = 1; |
| 9127 | rpci.pSubpasses = &subpass; |
| 9128 | rpci.attachmentCount = 1; |
| 9129 | VkAttachmentDescription attach_desc = {}; |
| 9130 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
Cody Northrop | bd16af1 | 2016-06-21 09:25:48 -0600 | [diff] [blame] | 9131 | // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM |
| 9132 | attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM; |
Tobin Ehlis | 85aa15a | 2016-06-15 10:52:37 -0600 | [diff] [blame] | 9133 | rpci.pAttachments = &attach_desc; |
| 9134 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 9135 | VkRenderPass rp; |
| 9136 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9137 | VkPipelineObj pipe(m_device); |
| 9138 | pipe.AddShader(&vs); |
| 9139 | pipe.AddShader(&fs); |
| 9140 | pipe.AddColorAttachment(); |
| 9141 | VkViewport view_port = {}; |
| 9142 | m_viewports.push_back(view_port); |
| 9143 | pipe.SetViewport(m_viewports); |
| 9144 | VkRect2D rect = {}; |
| 9145 | m_scissors.push_back(rect); |
| 9146 | pipe.SetScissor(m_scissors); |
| 9147 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 9148 | |
| 9149 | VkCommandBufferInheritanceInfo cbii = {}; |
| 9150 | cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; |
| 9151 | cbii.renderPass = rp; |
| 9152 | cbii.subpass = 0; |
| 9153 | VkCommandBufferBeginInfo cbbi = {}; |
| 9154 | cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 9155 | cbbi.pInheritanceInfo = &cbii; |
| 9156 | vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi); |
| 9157 | VkRenderPassBeginInfo rpbi = {}; |
| 9158 | rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 9159 | rpbi.framebuffer = m_framebuffer; |
| 9160 | rpbi.renderPass = rp; |
| 9161 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, |
| 9162 | VK_SUBPASS_CONTENTS_INLINE); |
| 9163 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9164 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 9165 | |
| 9166 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9167 | " is incompatible w/ gfx pipeline "); |
| 9168 | // Render triangle (the error should trigger on the attempt to draw). |
| 9169 | Draw(3, 1, 0, 0); |
| 9170 | |
| 9171 | // Finalize recording of the command buffer |
| 9172 | EndCommandBuffer(); |
| 9173 | |
| 9174 | m_errorMonitor->VerifyFound(); |
| 9175 | |
| 9176 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9177 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9178 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 9179 | } |
| 9180 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9181 | TEST_F(VkLayerTest, NumBlendAttachMismatch) { |
| 9182 | // Create Pipeline where the number of blend attachments doesn't match the |
| 9183 | // number of color attachments. In this case, we don't add any color |
| 9184 | // blend attachments even though we have a color attachment. |
| 9185 | VkResult err; |
| 9186 | |
| 9187 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9188 | "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] | 9189 | |
| 9190 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9191 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9192 | VkDescriptorPoolSize ds_type_count = {}; |
| 9193 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9194 | ds_type_count.descriptorCount = 1; |
| 9195 | |
| 9196 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 9197 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9198 | ds_pool_ci.pNext = NULL; |
| 9199 | ds_pool_ci.maxSets = 1; |
| 9200 | ds_pool_ci.poolSizeCount = 1; |
| 9201 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 9202 | |
| 9203 | VkDescriptorPool ds_pool; |
| 9204 | err = |
| 9205 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 9206 | ASSERT_VK_SUCCESS(err); |
| 9207 | |
| 9208 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 9209 | dsl_binding.binding = 0; |
| 9210 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9211 | dsl_binding.descriptorCount = 1; |
| 9212 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9213 | dsl_binding.pImmutableSamplers = NULL; |
| 9214 | |
| 9215 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9216 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9217 | ds_layout_ci.pNext = NULL; |
| 9218 | ds_layout_ci.bindingCount = 1; |
| 9219 | ds_layout_ci.pBindings = &dsl_binding; |
| 9220 | |
| 9221 | VkDescriptorSetLayout ds_layout; |
| 9222 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9223 | &ds_layout); |
| 9224 | ASSERT_VK_SUCCESS(err); |
| 9225 | |
| 9226 | VkDescriptorSet descriptorSet; |
| 9227 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 9228 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 9229 | alloc_info.descriptorSetCount = 1; |
| 9230 | alloc_info.descriptorPool = ds_pool; |
| 9231 | alloc_info.pSetLayouts = &ds_layout; |
| 9232 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9233 | &descriptorSet); |
| 9234 | ASSERT_VK_SUCCESS(err); |
| 9235 | |
| 9236 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
| 9237 | pipe_ms_state_ci.sType = |
| 9238 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9239 | pipe_ms_state_ci.pNext = NULL; |
| 9240 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; |
| 9241 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9242 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9243 | pipe_ms_state_ci.pSampleMask = NULL; |
| 9244 | |
| 9245 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 9246 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9247 | pipeline_layout_ci.pNext = NULL; |
| 9248 | pipeline_layout_ci.setLayoutCount = 1; |
| 9249 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 9250 | |
| 9251 | VkPipelineLayout pipeline_layout; |
| 9252 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9253 | &pipeline_layout); |
| 9254 | ASSERT_VK_SUCCESS(err); |
| 9255 | |
| 9256 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9257 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9258 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9259 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9260 | this); // We shouldn't need a fragment shader |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9261 | // but add it to be able to run on more devices |
| 9262 | VkPipelineObj pipe(m_device); |
| 9263 | pipe.AddShader(&vs); |
| 9264 | pipe.AddShader(&fs); |
| 9265 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 9266 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 9267 | |
| 9268 | BeginCommandBuffer(); |
| 9269 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9270 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 9271 | |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9272 | // Render triangle (the error should trigger on the attempt to draw). |
| 9273 | Draw(3, 1, 0, 0); |
| 9274 | |
| 9275 | // Finalize recording of the command buffer |
| 9276 | EndCommandBuffer(); |
| 9277 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9278 | m_errorMonitor->VerifyFound(); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9279 | |
| 9280 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9281 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9282 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 9283 | } |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9284 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 9285 | TEST_F(VkLayerTest, MissingClearAttachment) { |
| 9286 | TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment " |
| 9287 | "structure passed to vkCmdClearAttachments"); |
| 9288 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9289 | "vkCmdClearAttachments() attachment index 1 not found in attachment " |
| 9290 | "reference array of active subpass 0"); |
| 9291 | |
| 9292 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments); |
| 9293 | m_errorMonitor->VerifyFound(); |
| 9294 | } |
| 9295 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9296 | TEST_F(VkLayerTest, ClearCmdNoDraw) { |
| 9297 | // Create CommandBuffer where we add ClearCmd for FB Color attachment prior |
| 9298 | // to issuing a Draw |
| 9299 | VkResult err; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9300 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9301 | m_errorMonitor->SetDesiredFailureMsg( |
Tony Barbour | 7e56d30 | 2016-03-02 15:12:01 -0700 | [diff] [blame] | 9302 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9303 | "vkCmdClearAttachments() issued on CB object "); |
| 9304 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9305 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9306 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9307 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9308 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9309 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9310 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9311 | |
| 9312 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9313 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9314 | ds_pool_ci.pNext = NULL; |
| 9315 | ds_pool_ci.maxSets = 1; |
| 9316 | ds_pool_ci.poolSizeCount = 1; |
| 9317 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9318 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9319 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9320 | err = |
| 9321 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9322 | ASSERT_VK_SUCCESS(err); |
| 9323 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9324 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9325 | dsl_binding.binding = 0; |
| 9326 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9327 | dsl_binding.descriptorCount = 1; |
| 9328 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9329 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9330 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9331 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9332 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9333 | ds_layout_ci.pNext = NULL; |
| 9334 | ds_layout_ci.bindingCount = 1; |
| 9335 | ds_layout_ci.pBindings = &dsl_binding; |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9336 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9337 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9338 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9339 | &ds_layout); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9340 | ASSERT_VK_SUCCESS(err); |
| 9341 | |
| 9342 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9343 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9344 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9345 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9346 | alloc_info.descriptorPool = ds_pool; |
| 9347 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9348 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9349 | &descriptorSet); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9350 | ASSERT_VK_SUCCESS(err); |
| 9351 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9352 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9353 | pipe_ms_state_ci.sType = |
| 9354 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9355 | pipe_ms_state_ci.pNext = NULL; |
| 9356 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT; |
| 9357 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9358 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9359 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9360 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9361 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9362 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9363 | pipeline_layout_ci.pNext = NULL; |
| 9364 | pipeline_layout_ci.setLayoutCount = 1; |
| 9365 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9366 | |
| 9367 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9368 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9369 | &pipeline_layout); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9370 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9371 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9372 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9373 | VK_SHADER_STAGE_VERTEX_BIT, this); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9374 | // 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] | 9375 | // on more devices |
| 9376 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9377 | VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9378 | |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9379 | VkPipelineObj pipe(m_device); |
| 9380 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 9381 | pipe.AddShader(&fs); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9382 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 9383 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 9384 | |
| 9385 | BeginCommandBuffer(); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9386 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9387 | // Main thing we care about for this test is that the VkImage obj we're |
| 9388 | // clearing matches Color Attachment of FB |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9389 | // Also pass down other dummy params to keep driver and paramchecker happy |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 9390 | VkClearAttachment color_attachment; |
| 9391 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9392 | color_attachment.clearValue.color.float32[0] = 1.0; |
| 9393 | color_attachment.clearValue.color.float32[1] = 1.0; |
| 9394 | color_attachment.clearValue.color.float32[2] = 1.0; |
| 9395 | color_attachment.clearValue.color.float32[3] = 1.0; |
| 9396 | color_attachment.colorAttachment = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9397 | VkClearRect clear_rect = { |
| 9398 | {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}}; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9399 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9400 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 9401 | &color_attachment, 1, &clear_rect); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9402 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9403 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9404 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9405 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9406 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9407 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9408 | } |
| 9409 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9410 | TEST_F(VkLayerTest, VtxBufferBadIndex) { |
| 9411 | VkResult err; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9412 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9413 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 9414 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | dfcd9b6 | 2015-12-14 15:14:10 -0700 | [diff] [blame] | 9415 | "but no vertex buffers are attached to this Pipeline State Object"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9416 | |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9417 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 9418 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9419 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9420 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9421 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9422 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9423 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9424 | |
| 9425 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9426 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9427 | ds_pool_ci.pNext = NULL; |
| 9428 | ds_pool_ci.maxSets = 1; |
| 9429 | ds_pool_ci.poolSizeCount = 1; |
| 9430 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9431 | |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 9432 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9433 | err = |
| 9434 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9435 | ASSERT_VK_SUCCESS(err); |
| 9436 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9437 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9438 | dsl_binding.binding = 0; |
| 9439 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9440 | dsl_binding.descriptorCount = 1; |
| 9441 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9442 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9443 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9444 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9445 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9446 | ds_layout_ci.pNext = NULL; |
| 9447 | ds_layout_ci.bindingCount = 1; |
| 9448 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9449 | |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9450 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9451 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9452 | &ds_layout); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9453 | ASSERT_VK_SUCCESS(err); |
| 9454 | |
| 9455 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9456 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9457 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9458 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9459 | alloc_info.descriptorPool = ds_pool; |
| 9460 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9461 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9462 | &descriptorSet); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9463 | ASSERT_VK_SUCCESS(err); |
| 9464 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9465 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9466 | pipe_ms_state_ci.sType = |
| 9467 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9468 | pipe_ms_state_ci.pNext = NULL; |
| 9469 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; |
| 9470 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9471 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9472 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9473 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9474 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9475 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9476 | pipeline_layout_ci.pNext = NULL; |
| 9477 | pipeline_layout_ci.setLayoutCount = 1; |
| 9478 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 9479 | VkPipelineLayout pipeline_layout; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9480 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9481 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9482 | &pipeline_layout); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9483 | ASSERT_VK_SUCCESS(err); |
| 9484 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9485 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9486 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9487 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9488 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9489 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9490 | // but add it to be able to run on more devices |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9491 | VkPipelineObj pipe(m_device); |
| 9492 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 9493 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9494 | pipe.AddColorAttachment(); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9495 | pipe.SetMSAA(&pipe_ms_state_ci); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 9496 | pipe.SetViewport(m_viewports); |
| 9497 | pipe.SetScissor(m_scissors); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9498 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 9499 | |
| 9500 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9501 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9502 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | f7bf450 | 2015-09-09 15:12:35 -0600 | [diff] [blame] | 9503 | // Don't care about actual data, just need to get to draw to flag error |
| 9504 | static const float vbo_data[3] = {1.f, 0.f, 1.f}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9505 | VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), |
| 9506 | (const void *)&vbo_data); |
Tobin Ehlis | f7bf450 | 2015-09-09 15:12:35 -0600 | [diff] [blame] | 9507 | 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] | 9508 | Draw(1, 0, 0, 0); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9509 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9510 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9511 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9512 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9513 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9514 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9515 | } |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 9516 | // INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here) |
| 9517 | TEST_F(VkLayerTest, InvalidImageLayout) { |
| 9518 | TEST_DESCRIPTION("Hit all possible validation checks associated with the " |
| 9519 | "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having" |
| 9520 | "images in the wrong layout when they're copied or transitioned."); |
| 9521 | // 3 in ValidateCmdBufImageLayouts |
| 9522 | // * -1 Attempt to submit cmd buf w/ deleted image |
| 9523 | // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource |
| 9524 | // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource |
| 9525 | m_errorMonitor->SetDesiredFailureMsg( |
| 9526 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9527 | "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL."); |
| 9528 | |
| 9529 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9530 | // Create src & dst images to use for copy operations |
| 9531 | VkImage src_image; |
| 9532 | VkImage dst_image; |
| 9533 | |
| 9534 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 9535 | const int32_t tex_width = 32; |
| 9536 | const int32_t tex_height = 32; |
| 9537 | |
| 9538 | VkImageCreateInfo image_create_info = {}; |
| 9539 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 9540 | image_create_info.pNext = NULL; |
| 9541 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 9542 | image_create_info.format = tex_format; |
| 9543 | image_create_info.extent.width = tex_width; |
| 9544 | image_create_info.extent.height = tex_height; |
| 9545 | image_create_info.extent.depth = 1; |
| 9546 | image_create_info.mipLevels = 1; |
| 9547 | image_create_info.arrayLayers = 4; |
| 9548 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 9549 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 9550 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 9551 | image_create_info.flags = 0; |
| 9552 | |
| 9553 | VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image); |
| 9554 | ASSERT_VK_SUCCESS(err); |
| 9555 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image); |
| 9556 | ASSERT_VK_SUCCESS(err); |
| 9557 | |
| 9558 | BeginCommandBuffer(); |
| 9559 | VkImageCopy copyRegion; |
| 9560 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9561 | copyRegion.srcSubresource.mipLevel = 0; |
| 9562 | copyRegion.srcSubresource.baseArrayLayer = 0; |
| 9563 | copyRegion.srcSubresource.layerCount = 1; |
| 9564 | copyRegion.srcOffset.x = 0; |
| 9565 | copyRegion.srcOffset.y = 0; |
| 9566 | copyRegion.srcOffset.z = 0; |
| 9567 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9568 | copyRegion.dstSubresource.mipLevel = 0; |
| 9569 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 9570 | copyRegion.dstSubresource.layerCount = 1; |
| 9571 | copyRegion.dstOffset.x = 0; |
| 9572 | copyRegion.dstOffset.y = 0; |
| 9573 | copyRegion.dstOffset.z = 0; |
| 9574 | copyRegion.extent.width = 1; |
| 9575 | copyRegion.extent.height = 1; |
| 9576 | copyRegion.extent.depth = 1; |
| 9577 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9578 | m_errorMonitor->VerifyFound(); |
| 9579 | // Now cause error due to src image layout changing |
| 9580 | m_errorMonitor->SetDesiredFailureMsg( |
| 9581 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9582 | "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL."); |
| 9583 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9584 | m_errorMonitor->VerifyFound(); |
| 9585 | // Final src error is due to bad layout type |
| 9586 | m_errorMonitor->SetDesiredFailureMsg( |
| 9587 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9588 | "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL."); |
| 9589 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9590 | m_errorMonitor->VerifyFound(); |
| 9591 | // Now verify same checks for dst |
| 9592 | m_errorMonitor->SetDesiredFailureMsg( |
| 9593 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9594 | "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL."); |
| 9595 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9596 | m_errorMonitor->VerifyFound(); |
| 9597 | // Now cause error due to src image layout changing |
| 9598 | m_errorMonitor->SetDesiredFailureMsg( |
| 9599 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9600 | "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL."); |
| 9601 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, ©Region); |
| 9602 | m_errorMonitor->VerifyFound(); |
| 9603 | m_errorMonitor->SetDesiredFailureMsg( |
| 9604 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9605 | "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL."); |
| 9606 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, ©Region); |
| 9607 | m_errorMonitor->VerifyFound(); |
| 9608 | // Now cause error due to bad image layout transition in PipelineBarrier |
| 9609 | VkImageMemoryBarrier image_barrier[1] = {}; |
| 9610 | image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 9611 | image_barrier[0].image = src_image; |
| 9612 | image_barrier[0].subresourceRange.layerCount = 2; |
| 9613 | image_barrier[0].subresourceRange.levelCount = 2; |
| 9614 | image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9615 | m_errorMonitor->SetDesiredFailureMsg( |
| 9616 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9617 | "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL."); |
| 9618 | vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier); |
| 9619 | m_errorMonitor->VerifyFound(); |
| 9620 | |
| 9621 | // Finally some layout errors at RenderPass create time |
| 9622 | // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing. |
| 9623 | VkAttachmentReference attach = {}; |
| 9624 | // perf warning for GENERAL layout w/ non-DS input attachment |
| 9625 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 9626 | VkSubpassDescription subpass = {}; |
| 9627 | subpass.inputAttachmentCount = 1; |
| 9628 | subpass.pInputAttachments = &attach; |
| 9629 | VkRenderPassCreateInfo rpci = {}; |
| 9630 | rpci.subpassCount = 1; |
| 9631 | rpci.pSubpasses = &subpass; |
| 9632 | rpci.attachmentCount = 1; |
| 9633 | VkAttachmentDescription attach_desc = {}; |
| 9634 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 9635 | rpci.pAttachments = &attach_desc; |
Tobin Ehlis | 1efce02 | 2016-05-11 10:40:34 -0600 | [diff] [blame] | 9636 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 9637 | VkRenderPass rp; |
| 9638 | m_errorMonitor->SetDesiredFailureMsg( |
| 9639 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9640 | "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL."); |
| 9641 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9642 | m_errorMonitor->VerifyFound(); |
| 9643 | // error w/ non-general layout |
| 9644 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 9645 | |
| 9646 | m_errorMonitor->SetDesiredFailureMsg( |
| 9647 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9648 | "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL."); |
| 9649 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9650 | m_errorMonitor->VerifyFound(); |
| 9651 | subpass.inputAttachmentCount = 0; |
| 9652 | subpass.colorAttachmentCount = 1; |
| 9653 | subpass.pColorAttachments = &attach; |
| 9654 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 9655 | // perf warning for GENERAL layout on color attachment |
| 9656 | m_errorMonitor->SetDesiredFailureMsg( |
| 9657 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9658 | "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL."); |
| 9659 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9660 | m_errorMonitor->VerifyFound(); |
| 9661 | // error w/ non-color opt or GENERAL layout for color attachment |
| 9662 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 9663 | m_errorMonitor->SetDesiredFailureMsg( |
| 9664 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9665 | "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL."); |
| 9666 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9667 | m_errorMonitor->VerifyFound(); |
| 9668 | subpass.colorAttachmentCount = 0; |
| 9669 | subpass.pDepthStencilAttachment = &attach; |
| 9670 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 9671 | // perf warning for GENERAL layout on DS attachment |
| 9672 | m_errorMonitor->SetDesiredFailureMsg( |
| 9673 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9674 | "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL."); |
| 9675 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9676 | m_errorMonitor->VerifyFound(); |
| 9677 | // error w/ non-ds opt or GENERAL layout for color attachment |
| 9678 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 9679 | m_errorMonitor->SetDesiredFailureMsg( |
| 9680 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9681 | "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL."); |
| 9682 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9683 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 1efce02 | 2016-05-11 10:40:34 -0600 | [diff] [blame] | 9684 | // For this error we need a valid renderpass so create default one |
| 9685 | attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 9686 | attach.attachment = 0; |
| 9687 | attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 9688 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
| 9689 | attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE; |
| 9690 | attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 9691 | attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 9692 | // Can't do a CLEAR load on READ_ONLY initialLayout |
| 9693 | attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 9694 | attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 9695 | attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 9696 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9697 | " with invalid first layout " |
| 9698 | "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_" |
| 9699 | "ONLY_OPTIMAL"); |
| 9700 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9701 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 9702 | |
| 9703 | vkDestroyImage(m_device->device(), src_image, NULL); |
| 9704 | vkDestroyImage(m_device->device(), dst_image, NULL); |
| 9705 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9706 | #endif // DRAW_STATE_TESTS |
| 9707 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 9708 | #if THREADING_TESTS |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9709 | #if GTEST_IS_THREADSAFE |
| 9710 | struct thread_data_struct { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9711 | VkCommandBuffer commandBuffer; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9712 | VkEvent event; |
| 9713 | bool bailout; |
| 9714 | }; |
| 9715 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9716 | extern "C" void *AddToCommandBuffer(void *arg) { |
| 9717 | struct thread_data_struct *data = (struct thread_data_struct *)arg; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9718 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9719 | for (int i = 0; i < 10000; i++) { |
| 9720 | vkCmdSetEvent(data->commandBuffer, data->event, |
| 9721 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9722 | if (data->bailout) { |
| 9723 | break; |
| 9724 | } |
| 9725 | } |
| 9726 | return NULL; |
| 9727 | } |
| 9728 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9729 | TEST_F(VkLayerTest, ThreadCommandBufferCollision) { |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 9730 | test_platform_thread thread; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9731 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9732 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9733 | "THREADING ERROR"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9734 | |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9735 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9736 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 9737 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9738 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9739 | // Calls AllocateCommandBuffers |
| 9740 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
Mark Lobodzinski | 5495d13 | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 9741 | |
| 9742 | // Avoid creating RenderPass |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9743 | commandBuffer.BeginCommandBuffer(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9744 | |
| 9745 | VkEventCreateInfo event_info; |
| 9746 | VkEvent event; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9747 | VkResult err; |
| 9748 | |
| 9749 | memset(&event_info, 0, sizeof(event_info)); |
| 9750 | event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 9751 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9752 | err = vkCreateEvent(device(), &event_info, NULL, &event); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9753 | ASSERT_VK_SUCCESS(err); |
| 9754 | |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9755 | err = vkResetEvent(device(), event); |
| 9756 | ASSERT_VK_SUCCESS(err); |
| 9757 | |
| 9758 | struct thread_data_struct data; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9759 | data.commandBuffer = commandBuffer.GetBufferHandle(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9760 | data.event = event; |
| 9761 | data.bailout = false; |
| 9762 | m_errorMonitor->SetBailout(&data.bailout); |
| 9763 | // Add many entries to command buffer from another thread. |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 9764 | test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9765 | // Add many entries to command buffer from this thread at the same time. |
| 9766 | AddToCommandBuffer(&data); |
Mark Lobodzinski | 5495d13 | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 9767 | |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 9768 | test_platform_thread_join(thread, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9769 | commandBuffer.EndCommandBuffer(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9770 | |
Mike Stroyan | 10b8cb7 | 2016-01-22 15:22:03 -0700 | [diff] [blame] | 9771 | m_errorMonitor->SetBailout(NULL); |
| 9772 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9773 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9774 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9775 | vkDestroyEvent(device(), event, NULL); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9776 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9777 | #endif // GTEST_IS_THREADSAFE |
| 9778 | #endif // THREADING_TESTS |
| 9779 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9780 | #if SHADER_CHECKER_TESTS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9781 | TEST_F(VkLayerTest, InvalidSPIRVCodeSize) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9782 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9783 | "Invalid SPIR-V header"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9784 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9785 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9786 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9787 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9788 | VkShaderModule module; |
| 9789 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 9790 | struct icd_spv_header spv; |
| 9791 | |
| 9792 | spv.magic = ICD_SPV_MAGIC; |
| 9793 | spv.version = ICD_SPV_VERSION; |
| 9794 | spv.gen_magic = 0; |
| 9795 | |
| 9796 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 9797 | moduleCreateInfo.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9798 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9799 | moduleCreateInfo.codeSize = 4; |
| 9800 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9801 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9802 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9803 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9804 | } |
| 9805 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9806 | TEST_F(VkLayerTest, InvalidSPIRVMagic) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9807 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9808 | "Invalid SPIR-V magic number"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9809 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9810 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9811 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9812 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9813 | VkShaderModule module; |
| 9814 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 9815 | struct icd_spv_header spv; |
| 9816 | |
| 9817 | spv.magic = ~ICD_SPV_MAGIC; |
| 9818 | spv.version = ICD_SPV_VERSION; |
| 9819 | spv.gen_magic = 0; |
| 9820 | |
| 9821 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 9822 | moduleCreateInfo.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9823 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9824 | moduleCreateInfo.codeSize = sizeof(spv) + 10; |
| 9825 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9826 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9827 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9828 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9829 | } |
| 9830 | |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9831 | #if 0 |
| 9832 | // Not currently covered by SPIRV-Tools validator |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9833 | TEST_F(VkLayerTest, InvalidSPIRVVersion) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9834 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9835 | "Invalid SPIR-V header"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9836 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9837 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9838 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9839 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9840 | VkShaderModule module; |
| 9841 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 9842 | struct icd_spv_header spv; |
| 9843 | |
| 9844 | spv.magic = ICD_SPV_MAGIC; |
| 9845 | spv.version = ~ICD_SPV_VERSION; |
| 9846 | spv.gen_magic = 0; |
| 9847 | |
| 9848 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 9849 | moduleCreateInfo.pNext = NULL; |
| 9850 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9851 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9852 | moduleCreateInfo.codeSize = sizeof(spv) + 10; |
| 9853 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9854 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9855 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9856 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9857 | } |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9858 | #endif |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9859 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9860 | TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 9861 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9862 | "not consumed by fragment shader"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9863 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9864 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 9865 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9866 | |
| 9867 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9868 | "#version 450\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9869 | "\n" |
| 9870 | "layout(location=0) out float x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 9871 | "out gl_PerVertex {\n" |
| 9872 | " vec4 gl_Position;\n" |
| 9873 | "};\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9874 | "void main(){\n" |
| 9875 | " gl_Position = vec4(1);\n" |
| 9876 | " x = 0;\n" |
| 9877 | "}\n"; |
| 9878 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9879 | "#version 450\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9880 | "\n" |
| 9881 | "layout(location=0) out vec4 color;\n" |
| 9882 | "void main(){\n" |
| 9883 | " color = vec4(1);\n" |
| 9884 | "}\n"; |
| 9885 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 9886 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9887 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9888 | |
| 9889 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 9890 | pipe.AddColorAttachment(); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9891 | pipe.AddShader(&vs); |
| 9892 | pipe.AddShader(&fs); |
| 9893 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9894 | VkDescriptorSetObj descriptorSet(m_device); |
| 9895 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9896 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9897 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 9898 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9899 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9900 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9901 | } |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9902 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9903 | TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9904 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9905 | "not written by vertex shader"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9906 | |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9907 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 9908 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9909 | |
| 9910 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9911 | "#version 450\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9912 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 9913 | "out gl_PerVertex {\n" |
| 9914 | " vec4 gl_Position;\n" |
| 9915 | "};\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9916 | "void main(){\n" |
| 9917 | " gl_Position = vec4(1);\n" |
| 9918 | "}\n"; |
| 9919 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9920 | "#version 450\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9921 | "\n" |
| 9922 | "layout(location=0) in float x;\n" |
| 9923 | "layout(location=0) out vec4 color;\n" |
| 9924 | "void main(){\n" |
| 9925 | " color = vec4(x);\n" |
| 9926 | "}\n"; |
| 9927 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 9928 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9929 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9930 | |
| 9931 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 9932 | pipe.AddColorAttachment(); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9933 | pipe.AddShader(&vs); |
| 9934 | pipe.AddShader(&fs); |
| 9935 | |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9936 | VkDescriptorSetObj descriptorSet(m_device); |
| 9937 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9938 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9939 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 9940 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9941 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9942 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9943 | } |
| 9944 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9945 | TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) { |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9946 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9947 | "not written by vertex shader"); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9948 | |
| 9949 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9950 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9951 | |
| 9952 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9953 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9954 | "\n" |
| 9955 | "out gl_PerVertex {\n" |
| 9956 | " vec4 gl_Position;\n" |
| 9957 | "};\n" |
| 9958 | "void main(){\n" |
| 9959 | " gl_Position = vec4(1);\n" |
| 9960 | "}\n"; |
| 9961 | char const *fsSource = |
| 9962 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9963 | "\n" |
| 9964 | "in block { layout(location=0) float x; } ins;\n" |
| 9965 | "layout(location=0) out vec4 color;\n" |
| 9966 | "void main(){\n" |
| 9967 | " color = vec4(ins.x);\n" |
| 9968 | "}\n"; |
| 9969 | |
| 9970 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9971 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 9972 | |
| 9973 | VkPipelineObj pipe(m_device); |
| 9974 | pipe.AddColorAttachment(); |
| 9975 | pipe.AddShader(&vs); |
| 9976 | pipe.AddShader(&fs); |
| 9977 | |
| 9978 | VkDescriptorSetObj descriptorSet(m_device); |
| 9979 | descriptorSet.AppendDummy(); |
| 9980 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 9981 | |
| 9982 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 9983 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9984 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9985 | } |
| 9986 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9987 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) { |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 9988 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 9989 | "Type mismatch on location 0.0: 'ptr to " |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9990 | "output arr[2] of float32' vs 'ptr to " |
| 9991 | "input arr[3] of float32'"); |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 9992 | |
| 9993 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9994 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9995 | |
| 9996 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9997 | "#version 450\n" |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 9998 | "\n" |
| 9999 | "layout(location=0) out float x[2];\n" |
| 10000 | "out gl_PerVertex {\n" |
| 10001 | " vec4 gl_Position;\n" |
| 10002 | "};\n" |
| 10003 | "void main(){\n" |
| 10004 | " x[0] = 0; x[1] = 0;\n" |
| 10005 | " gl_Position = vec4(1);\n" |
| 10006 | "}\n"; |
| 10007 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10008 | "#version 450\n" |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10009 | "\n" |
| 10010 | "layout(location=0) in float x[3];\n" |
| 10011 | "layout(location=0) out vec4 color;\n" |
| 10012 | "void main(){\n" |
| 10013 | " color = vec4(x[0] + x[1] + x[2]);\n" |
| 10014 | "}\n"; |
| 10015 | |
| 10016 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10017 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10018 | |
| 10019 | VkPipelineObj pipe(m_device); |
| 10020 | pipe.AddColorAttachment(); |
| 10021 | pipe.AddShader(&vs); |
| 10022 | pipe.AddShader(&fs); |
| 10023 | |
| 10024 | VkDescriptorSetObj descriptorSet(m_device); |
| 10025 | descriptorSet.AppendDummy(); |
| 10026 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10027 | |
| 10028 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10029 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10030 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10031 | } |
| 10032 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10033 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10034 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10035 | "Type mismatch on location 0"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10036 | |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10037 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10038 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10039 | |
| 10040 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10041 | "#version 450\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10042 | "\n" |
| 10043 | "layout(location=0) out int x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10044 | "out gl_PerVertex {\n" |
| 10045 | " vec4 gl_Position;\n" |
| 10046 | "};\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10047 | "void main(){\n" |
| 10048 | " x = 0;\n" |
| 10049 | " gl_Position = vec4(1);\n" |
| 10050 | "}\n"; |
| 10051 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10052 | "#version 450\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10053 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10054 | "layout(location=0) in float x;\n" /* VS writes int */ |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10055 | "layout(location=0) out vec4 color;\n" |
| 10056 | "void main(){\n" |
| 10057 | " color = vec4(x);\n" |
| 10058 | "}\n"; |
| 10059 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10060 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10061 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10062 | |
| 10063 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10064 | pipe.AddColorAttachment(); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10065 | pipe.AddShader(&vs); |
| 10066 | pipe.AddShader(&fs); |
| 10067 | |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10068 | VkDescriptorSetObj descriptorSet(m_device); |
| 10069 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10070 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10071 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10072 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10073 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10074 | m_errorMonitor->VerifyFound(); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10075 | } |
| 10076 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10077 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) { |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10078 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10079 | "Type mismatch on location 0"); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10080 | |
| 10081 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10082 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10083 | |
| 10084 | char const *vsSource = |
| 10085 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10086 | "\n" |
| 10087 | "out block { layout(location=0) int x; } outs;\n" |
| 10088 | "out gl_PerVertex {\n" |
| 10089 | " vec4 gl_Position;\n" |
| 10090 | "};\n" |
| 10091 | "void main(){\n" |
| 10092 | " outs.x = 0;\n" |
| 10093 | " gl_Position = vec4(1);\n" |
| 10094 | "}\n"; |
| 10095 | char const *fsSource = |
| 10096 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10097 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10098 | "in block { layout(location=0) float x; } ins;\n" /* VS writes int */ |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10099 | "layout(location=0) out vec4 color;\n" |
| 10100 | "void main(){\n" |
| 10101 | " color = vec4(ins.x);\n" |
| 10102 | "}\n"; |
| 10103 | |
| 10104 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10105 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10106 | |
| 10107 | VkPipelineObj pipe(m_device); |
| 10108 | pipe.AddColorAttachment(); |
| 10109 | pipe.AddShader(&vs); |
| 10110 | pipe.AddShader(&fs); |
| 10111 | |
| 10112 | VkDescriptorSetObj descriptorSet(m_device); |
| 10113 | descriptorSet.AppendDummy(); |
| 10114 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10115 | |
| 10116 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10117 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10118 | m_errorMonitor->VerifyFound(); |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10119 | } |
| 10120 | |
| 10121 | TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) { |
| 10122 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10123 | "location 0.0 which is not written by vertex shader"); |
| 10124 | |
| 10125 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10126 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10127 | |
| 10128 | char const *vsSource = |
| 10129 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10130 | "\n" |
| 10131 | "out block { layout(location=1) float x; } outs;\n" |
| 10132 | "out gl_PerVertex {\n" |
| 10133 | " vec4 gl_Position;\n" |
| 10134 | "};\n" |
| 10135 | "void main(){\n" |
| 10136 | " outs.x = 0;\n" |
| 10137 | " gl_Position = vec4(1);\n" |
| 10138 | "}\n"; |
| 10139 | char const *fsSource = |
| 10140 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10141 | "\n" |
| 10142 | "in block { layout(location=0) float x; } ins;\n" |
| 10143 | "layout(location=0) out vec4 color;\n" |
| 10144 | "void main(){\n" |
| 10145 | " color = vec4(ins.x);\n" |
| 10146 | "}\n"; |
| 10147 | |
| 10148 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10149 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10150 | |
| 10151 | VkPipelineObj pipe(m_device); |
| 10152 | pipe.AddColorAttachment(); |
| 10153 | pipe.AddShader(&vs); |
| 10154 | pipe.AddShader(&fs); |
| 10155 | |
| 10156 | VkDescriptorSetObj descriptorSet(m_device); |
| 10157 | descriptorSet.AppendDummy(); |
| 10158 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10159 | |
| 10160 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10161 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10162 | m_errorMonitor->VerifyFound(); |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10163 | } |
| 10164 | |
| 10165 | TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) { |
| 10166 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10167 | "location 0.1 which is not written by vertex shader"); |
| 10168 | |
| 10169 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10170 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10171 | |
| 10172 | char const *vsSource = |
| 10173 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10174 | "\n" |
| 10175 | "out block { layout(location=0, component=0) float x; } outs;\n" |
| 10176 | "out gl_PerVertex {\n" |
| 10177 | " vec4 gl_Position;\n" |
| 10178 | "};\n" |
| 10179 | "void main(){\n" |
| 10180 | " outs.x = 0;\n" |
| 10181 | " gl_Position = vec4(1);\n" |
| 10182 | "}\n"; |
| 10183 | char const *fsSource = |
| 10184 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10185 | "\n" |
| 10186 | "in block { layout(location=0, component=1) float x; } ins;\n" |
| 10187 | "layout(location=0) out vec4 color;\n" |
| 10188 | "void main(){\n" |
| 10189 | " color = vec4(ins.x);\n" |
| 10190 | "}\n"; |
| 10191 | |
| 10192 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10193 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10194 | |
| 10195 | VkPipelineObj pipe(m_device); |
| 10196 | pipe.AddColorAttachment(); |
| 10197 | pipe.AddShader(&vs); |
| 10198 | pipe.AddShader(&fs); |
| 10199 | |
| 10200 | VkDescriptorSetObj descriptorSet(m_device); |
| 10201 | descriptorSet.AppendDummy(); |
| 10202 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10203 | |
| 10204 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10205 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10206 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10207 | } |
| 10208 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10209 | TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 10210 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10211 | "location 0 not consumed by VS"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10212 | |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10213 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10214 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10215 | |
| 10216 | VkVertexInputBindingDescription input_binding; |
| 10217 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10218 | |
| 10219 | VkVertexInputAttributeDescription input_attrib; |
| 10220 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10221 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10222 | |
| 10223 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10224 | "#version 450\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10225 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10226 | "out gl_PerVertex {\n" |
| 10227 | " vec4 gl_Position;\n" |
| 10228 | "};\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10229 | "void main(){\n" |
| 10230 | " gl_Position = vec4(1);\n" |
| 10231 | "}\n"; |
| 10232 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10233 | "#version 450\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10234 | "\n" |
| 10235 | "layout(location=0) out vec4 color;\n" |
| 10236 | "void main(){\n" |
| 10237 | " color = vec4(1);\n" |
| 10238 | "}\n"; |
| 10239 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10240 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10241 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10242 | |
| 10243 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10244 | pipe.AddColorAttachment(); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10245 | pipe.AddShader(&vs); |
| 10246 | pipe.AddShader(&fs); |
| 10247 | |
| 10248 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10249 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10250 | |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10251 | VkDescriptorSetObj descriptorSet(m_device); |
| 10252 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10253 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10254 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10255 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10256 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10257 | m_errorMonitor->VerifyFound(); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10258 | } |
| 10259 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10260 | TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 10261 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10262 | "location 0 not consumed by VS"); |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10263 | |
| 10264 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10265 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10266 | |
| 10267 | VkVertexInputBindingDescription input_binding; |
| 10268 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10269 | |
| 10270 | VkVertexInputAttributeDescription input_attrib; |
| 10271 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10272 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10273 | |
| 10274 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10275 | "#version 450\n" |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10276 | "\n" |
| 10277 | "layout(location=1) in float x;\n" |
| 10278 | "out gl_PerVertex {\n" |
| 10279 | " vec4 gl_Position;\n" |
| 10280 | "};\n" |
| 10281 | "void main(){\n" |
| 10282 | " gl_Position = vec4(x);\n" |
| 10283 | "}\n"; |
| 10284 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10285 | "#version 450\n" |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10286 | "\n" |
| 10287 | "layout(location=0) out vec4 color;\n" |
| 10288 | "void main(){\n" |
| 10289 | " color = vec4(1);\n" |
| 10290 | "}\n"; |
| 10291 | |
| 10292 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10293 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10294 | |
| 10295 | VkPipelineObj pipe(m_device); |
| 10296 | pipe.AddColorAttachment(); |
| 10297 | pipe.AddShader(&vs); |
| 10298 | pipe.AddShader(&fs); |
| 10299 | |
| 10300 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10301 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10302 | |
| 10303 | VkDescriptorSetObj descriptorSet(m_device); |
| 10304 | descriptorSet.AppendDummy(); |
| 10305 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10306 | |
| 10307 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10308 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10309 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10310 | } |
| 10311 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10312 | TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) { |
| 10313 | m_errorMonitor->SetDesiredFailureMsg( |
| 10314 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10315 | "VS consumes input at location 0 but not provided"); |
| 10316 | |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10317 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10318 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10319 | |
| 10320 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10321 | "#version 450\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10322 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10323 | "layout(location=0) in vec4 x;\n" /* not provided */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10324 | "out gl_PerVertex {\n" |
| 10325 | " vec4 gl_Position;\n" |
| 10326 | "};\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10327 | "void main(){\n" |
| 10328 | " gl_Position = x;\n" |
| 10329 | "}\n"; |
| 10330 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10331 | "#version 450\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10332 | "\n" |
| 10333 | "layout(location=0) out vec4 color;\n" |
| 10334 | "void main(){\n" |
| 10335 | " color = vec4(1);\n" |
| 10336 | "}\n"; |
| 10337 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10338 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10339 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10340 | |
| 10341 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10342 | pipe.AddColorAttachment(); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10343 | pipe.AddShader(&vs); |
| 10344 | pipe.AddShader(&fs); |
| 10345 | |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10346 | VkDescriptorSetObj descriptorSet(m_device); |
| 10347 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10348 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10349 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10350 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10351 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10352 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10353 | } |
| 10354 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10355 | TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) { |
| 10356 | m_errorMonitor->SetDesiredFailureMsg( |
| 10357 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10358 | "location 0 does not match VS input type"); |
| 10359 | |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10360 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10361 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10362 | |
| 10363 | VkVertexInputBindingDescription input_binding; |
| 10364 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10365 | |
| 10366 | VkVertexInputAttributeDescription input_attrib; |
| 10367 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10368 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10369 | |
| 10370 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10371 | "#version 450\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10372 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10373 | "layout(location=0) in int x;\n" /* attrib provided float */ |
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 | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10377 | "void main(){\n" |
| 10378 | " gl_Position = vec4(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 | c97d98e | 2015-05-25 11:13:31 +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 | c97d98e | 2015-05-25 11:13:31 +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 | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10393 | pipe.AddShader(&vs); |
| 10394 | pipe.AddShader(&fs); |
| 10395 | |
| 10396 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10397 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10398 | |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10399 | VkDescriptorSetObj descriptorSet(m_device); |
| 10400 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10401 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10402 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10403 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10404 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10405 | m_errorMonitor->VerifyFound(); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10406 | } |
| 10407 | |
Chris Forbes | c68b43c | 2016-04-06 11:18:47 +1200 | [diff] [blame] | 10408 | TEST_F(VkLayerTest, CreatePipelineDuplicateStage) { |
| 10409 | m_errorMonitor->SetDesiredFailureMsg( |
| 10410 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10411 | "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT"); |
| 10412 | |
| 10413 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10414 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10415 | |
| 10416 | char const *vsSource = |
| 10417 | "#version 450\n" |
| 10418 | "\n" |
| 10419 | "out gl_PerVertex {\n" |
| 10420 | " vec4 gl_Position;\n" |
| 10421 | "};\n" |
| 10422 | "void main(){\n" |
| 10423 | " gl_Position = vec4(1);\n" |
| 10424 | "}\n"; |
| 10425 | char const *fsSource = |
| 10426 | "#version 450\n" |
| 10427 | "\n" |
| 10428 | "layout(location=0) out vec4 color;\n" |
| 10429 | "void main(){\n" |
| 10430 | " color = vec4(1);\n" |
| 10431 | "}\n"; |
| 10432 | |
| 10433 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10434 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10435 | |
| 10436 | VkPipelineObj pipe(m_device); |
| 10437 | pipe.AddColorAttachment(); |
| 10438 | pipe.AddShader(&vs); |
| 10439 | pipe.AddShader(&vs); |
| 10440 | pipe.AddShader(&fs); |
| 10441 | |
| 10442 | VkDescriptorSetObj descriptorSet(m_device); |
| 10443 | descriptorSet.AppendDummy(); |
| 10444 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10445 | |
| 10446 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10447 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10448 | m_errorMonitor->VerifyFound(); |
Chris Forbes | c68b43c | 2016-04-06 11:18:47 +1200 | [diff] [blame] | 10449 | } |
| 10450 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10451 | TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10452 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10453 | |
| 10454 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10455 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10456 | |
| 10457 | VkVertexInputBindingDescription input_binding; |
| 10458 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10459 | |
| 10460 | VkVertexInputAttributeDescription input_attribs[2]; |
| 10461 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 10462 | |
| 10463 | for (int i = 0; i < 2; i++) { |
| 10464 | input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 10465 | input_attribs[i].location = i; |
| 10466 | } |
| 10467 | |
| 10468 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10469 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10470 | "\n" |
| 10471 | "layout(location=0) in mat2x4 x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10472 | "out gl_PerVertex {\n" |
| 10473 | " vec4 gl_Position;\n" |
| 10474 | "};\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10475 | "void main(){\n" |
| 10476 | " gl_Position = x[0] + x[1];\n" |
| 10477 | "}\n"; |
| 10478 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10479 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10480 | "\n" |
| 10481 | "layout(location=0) out vec4 color;\n" |
| 10482 | "void main(){\n" |
| 10483 | " color = vec4(1);\n" |
| 10484 | "}\n"; |
| 10485 | |
| 10486 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10487 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10488 | |
| 10489 | VkPipelineObj pipe(m_device); |
| 10490 | pipe.AddColorAttachment(); |
| 10491 | pipe.AddShader(&vs); |
| 10492 | pipe.AddShader(&fs); |
| 10493 | |
| 10494 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10495 | pipe.AddVertexInputAttribs(input_attribs, 2); |
| 10496 | |
| 10497 | VkDescriptorSetObj descriptorSet(m_device); |
| 10498 | descriptorSet.AppendDummy(); |
| 10499 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10500 | |
| 10501 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10502 | |
| 10503 | /* expect success */ |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10504 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10505 | } |
| 10506 | |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10507 | TEST_F(VkLayerTest, CreatePipelineAttribArrayType) |
| 10508 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10509 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10510 | |
| 10511 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10512 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10513 | |
| 10514 | VkVertexInputBindingDescription input_binding; |
| 10515 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10516 | |
| 10517 | VkVertexInputAttributeDescription input_attribs[2]; |
| 10518 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 10519 | |
| 10520 | for (int i = 0; i < 2; i++) { |
| 10521 | input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 10522 | input_attribs[i].location = i; |
| 10523 | } |
| 10524 | |
| 10525 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10526 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10527 | "\n" |
| 10528 | "layout(location=0) in vec4 x[2];\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10529 | "out gl_PerVertex {\n" |
| 10530 | " vec4 gl_Position;\n" |
| 10531 | "};\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10532 | "void main(){\n" |
| 10533 | " gl_Position = x[0] + x[1];\n" |
| 10534 | "}\n"; |
| 10535 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10536 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10537 | "\n" |
| 10538 | "layout(location=0) out vec4 color;\n" |
| 10539 | "void main(){\n" |
| 10540 | " color = vec4(1);\n" |
| 10541 | "}\n"; |
| 10542 | |
| 10543 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10544 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10545 | |
| 10546 | VkPipelineObj pipe(m_device); |
| 10547 | pipe.AddColorAttachment(); |
| 10548 | pipe.AddShader(&vs); |
| 10549 | pipe.AddShader(&fs); |
| 10550 | |
| 10551 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10552 | pipe.AddVertexInputAttribs(input_attribs, 2); |
| 10553 | |
| 10554 | VkDescriptorSetObj descriptorSet(m_device); |
| 10555 | descriptorSet.AppendDummy(); |
| 10556 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10557 | |
| 10558 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10559 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10560 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10561 | } |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10562 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10563 | TEST_F(VkLayerTest, CreatePipelineSimplePositive) |
| 10564 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10565 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10566 | |
| 10567 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10568 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10569 | |
| 10570 | char const *vsSource = |
| 10571 | "#version 450\n" |
| 10572 | "out gl_PerVertex {\n" |
| 10573 | " vec4 gl_Position;\n" |
| 10574 | "};\n" |
| 10575 | "void main(){\n" |
| 10576 | " gl_Position = vec4(0);\n" |
| 10577 | "}\n"; |
| 10578 | char const *fsSource = |
| 10579 | "#version 450\n" |
| 10580 | "\n" |
| 10581 | "layout(location=0) out vec4 color;\n" |
| 10582 | "void main(){\n" |
| 10583 | " color = vec4(1);\n" |
| 10584 | "}\n"; |
| 10585 | |
| 10586 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10587 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10588 | |
| 10589 | VkPipelineObj pipe(m_device); |
| 10590 | pipe.AddColorAttachment(); |
| 10591 | pipe.AddShader(&vs); |
| 10592 | pipe.AddShader(&fs); |
| 10593 | |
| 10594 | VkDescriptorSetObj descriptorSet(m_device); |
| 10595 | descriptorSet.AppendDummy(); |
| 10596 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10597 | |
| 10598 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10599 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10600 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10601 | } |
| 10602 | |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 10603 | TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch) |
| 10604 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10605 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 10606 | |
| 10607 | // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block |
| 10608 | |
| 10609 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10610 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10611 | |
| 10612 | char const *vsSource = |
| 10613 | "#version 450\n" |
| 10614 | "out gl_PerVertex {\n" |
| 10615 | " vec4 gl_Position;\n" |
| 10616 | "};\n" |
| 10617 | "layout(location=0) out vec3 x;\n" |
| 10618 | "layout(location=1) out ivec3 y;\n" |
| 10619 | "layout(location=2) out vec3 z;\n" |
| 10620 | "void main(){\n" |
| 10621 | " gl_Position = vec4(0);\n" |
| 10622 | " x = vec3(0); y = ivec3(0); z = vec3(0);\n" |
| 10623 | "}\n"; |
| 10624 | char const *fsSource = |
| 10625 | "#version 450\n" |
| 10626 | "\n" |
| 10627 | "layout(location=0) out vec4 color;\n" |
| 10628 | "layout(location=0) in float x;\n" |
| 10629 | "layout(location=1) flat in int y;\n" |
| 10630 | "layout(location=2) in vec2 z;\n" |
| 10631 | "void main(){\n" |
| 10632 | " color = vec4(1 + x + y + z.x);\n" |
| 10633 | "}\n"; |
| 10634 | |
| 10635 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10636 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10637 | |
| 10638 | VkPipelineObj pipe(m_device); |
| 10639 | pipe.AddColorAttachment(); |
| 10640 | pipe.AddShader(&vs); |
| 10641 | pipe.AddShader(&fs); |
| 10642 | |
| 10643 | VkDescriptorSetObj descriptorSet(m_device); |
| 10644 | descriptorSet.AppendDummy(); |
| 10645 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10646 | |
| 10647 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10648 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10649 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 10650 | } |
| 10651 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10652 | TEST_F(VkLayerTest, CreatePipelineTessPerVertex) |
| 10653 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10654 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10655 | |
| 10656 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10657 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10658 | |
Chris Forbes | c1e852d | 2016-04-04 19:26:42 +1200 | [diff] [blame] | 10659 | if (!m_device->phy().features().tessellationShader) { |
| 10660 | printf("Device does not support tessellation shaders; skipped.\n"); |
| 10661 | return; |
| 10662 | } |
| 10663 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10664 | char const *vsSource = |
| 10665 | "#version 450\n" |
| 10666 | "void main(){}\n"; |
| 10667 | char const *tcsSource = |
| 10668 | "#version 450\n" |
| 10669 | "layout(location=0) out int x[];\n" |
| 10670 | "layout(vertices=3) out;\n" |
| 10671 | "void main(){\n" |
| 10672 | " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n" |
| 10673 | " gl_TessLevelInner[0] = 1;\n" |
| 10674 | " x[gl_InvocationID] = gl_InvocationID;\n" |
| 10675 | "}\n"; |
| 10676 | char const *tesSource = |
| 10677 | "#version 450\n" |
| 10678 | "layout(triangles, equal_spacing, cw) in;\n" |
| 10679 | "layout(location=0) in int x[];\n" |
| 10680 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 10681 | "void main(){\n" |
| 10682 | " gl_Position.xyz = gl_TessCoord;\n" |
| 10683 | " gl_Position.w = x[0] + x[1] + x[2];\n" |
| 10684 | "}\n"; |
| 10685 | char const *fsSource = |
| 10686 | "#version 450\n" |
| 10687 | "layout(location=0) out vec4 color;\n" |
| 10688 | "void main(){\n" |
| 10689 | " color = vec4(1);\n" |
| 10690 | "}\n"; |
| 10691 | |
| 10692 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10693 | VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this); |
| 10694 | VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this); |
| 10695 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10696 | |
| 10697 | VkPipelineInputAssemblyStateCreateInfo iasci{ |
| 10698 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, |
| 10699 | nullptr, |
| 10700 | 0, |
| 10701 | VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, |
| 10702 | VK_FALSE}; |
| 10703 | |
Chris Forbes | b4cacb6 | 2016-04-04 19:15:00 +1200 | [diff] [blame] | 10704 | VkPipelineTessellationStateCreateInfo tsci{ |
| 10705 | VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, |
| 10706 | nullptr, |
| 10707 | 0, |
| 10708 | 3}; |
| 10709 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10710 | VkPipelineObj pipe(m_device); |
| 10711 | pipe.SetInputAssembly(&iasci); |
Chris Forbes | b4cacb6 | 2016-04-04 19:15:00 +1200 | [diff] [blame] | 10712 | pipe.SetTessellation(&tsci); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10713 | pipe.AddColorAttachment(); |
| 10714 | pipe.AddShader(&vs); |
| 10715 | pipe.AddShader(&tcs); |
| 10716 | pipe.AddShader(&tes); |
| 10717 | pipe.AddShader(&fs); |
| 10718 | |
| 10719 | VkDescriptorSetObj descriptorSet(m_device); |
| 10720 | descriptorSet.AppendDummy(); |
| 10721 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10722 | |
| 10723 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10724 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10725 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10726 | } |
| 10727 | |
Chris Forbes | a0ab815 | 2016-04-20 13:34:27 +1200 | [diff] [blame] | 10728 | TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive) |
| 10729 | { |
| 10730 | m_errorMonitor->ExpectSuccess(); |
| 10731 | |
| 10732 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10733 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10734 | |
| 10735 | if (!m_device->phy().features().geometryShader) { |
| 10736 | printf("Device does not support geometry shaders; skipped.\n"); |
| 10737 | return; |
| 10738 | } |
| 10739 | |
| 10740 | char const *vsSource = |
| 10741 | "#version 450\n" |
| 10742 | "layout(location=0) out VertexData { vec4 x; } vs_out;\n" |
| 10743 | "void main(){\n" |
| 10744 | " vs_out.x = vec4(1);\n" |
| 10745 | "}\n"; |
| 10746 | char const *gsSource = |
| 10747 | "#version 450\n" |
| 10748 | "layout(triangles) in;\n" |
| 10749 | "layout(triangle_strip, max_vertices=3) out;\n" |
| 10750 | "layout(location=0) in VertexData { vec4 x; } gs_in[];\n" |
| 10751 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 10752 | "void main() {\n" |
| 10753 | " gl_Position = gs_in[0].x;\n" |
| 10754 | " EmitVertex();\n" |
| 10755 | "}\n"; |
| 10756 | char const *fsSource = |
| 10757 | "#version 450\n" |
| 10758 | "layout(location=0) out vec4 color;\n" |
| 10759 | "void main(){\n" |
| 10760 | " color = vec4(1);\n" |
| 10761 | "}\n"; |
| 10762 | |
| 10763 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10764 | VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this); |
| 10765 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10766 | |
| 10767 | VkPipelineObj pipe(m_device); |
| 10768 | pipe.AddColorAttachment(); |
| 10769 | pipe.AddShader(&vs); |
| 10770 | pipe.AddShader(&gs); |
| 10771 | pipe.AddShader(&fs); |
| 10772 | |
| 10773 | VkDescriptorSetObj descriptorSet(m_device); |
| 10774 | descriptorSet.AppendDummy(); |
| 10775 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10776 | |
| 10777 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10778 | |
| 10779 | m_errorMonitor->VerifyNotFound(); |
| 10780 | } |
| 10781 | |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 10782 | TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) |
| 10783 | { |
| 10784 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10785 | "is per-vertex in tessellation control shader stage " |
| 10786 | "but per-patch in tessellation evaluation shader stage"); |
| 10787 | |
| 10788 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10789 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10790 | |
Chris Forbes | c1e852d | 2016-04-04 19:26:42 +1200 | [diff] [blame] | 10791 | if (!m_device->phy().features().tessellationShader) { |
| 10792 | printf("Device does not support tessellation shaders; skipped.\n"); |
| 10793 | return; |
| 10794 | } |
| 10795 | |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 10796 | char const *vsSource = |
| 10797 | "#version 450\n" |
| 10798 | "void main(){}\n"; |
| 10799 | char const *tcsSource = |
| 10800 | "#version 450\n" |
| 10801 | "layout(location=0) out int x[];\n" |
| 10802 | "layout(vertices=3) out;\n" |
| 10803 | "void main(){\n" |
| 10804 | " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n" |
| 10805 | " gl_TessLevelInner[0] = 1;\n" |
| 10806 | " x[gl_InvocationID] = gl_InvocationID;\n" |
| 10807 | "}\n"; |
| 10808 | char const *tesSource = |
| 10809 | "#version 450\n" |
| 10810 | "layout(triangles, equal_spacing, cw) in;\n" |
| 10811 | "layout(location=0) patch in int x;\n" |
| 10812 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 10813 | "void main(){\n" |
| 10814 | " gl_Position.xyz = gl_TessCoord;\n" |
| 10815 | " gl_Position.w = x;\n" |
| 10816 | "}\n"; |
| 10817 | char const *fsSource = |
| 10818 | "#version 450\n" |
| 10819 | "layout(location=0) out vec4 color;\n" |
| 10820 | "void main(){\n" |
| 10821 | " color = vec4(1);\n" |
| 10822 | "}\n"; |
| 10823 | |
| 10824 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10825 | VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this); |
| 10826 | VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this); |
| 10827 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10828 | |
| 10829 | VkPipelineInputAssemblyStateCreateInfo iasci{ |
| 10830 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, |
| 10831 | nullptr, |
| 10832 | 0, |
| 10833 | VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, |
| 10834 | VK_FALSE}; |
| 10835 | |
| 10836 | VkPipelineTessellationStateCreateInfo tsci{ |
| 10837 | VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, |
| 10838 | nullptr, |
| 10839 | 0, |
| 10840 | 3}; |
| 10841 | |
| 10842 | VkPipelineObj pipe(m_device); |
| 10843 | pipe.SetInputAssembly(&iasci); |
| 10844 | pipe.SetTessellation(&tsci); |
| 10845 | pipe.AddColorAttachment(); |
| 10846 | pipe.AddShader(&vs); |
| 10847 | pipe.AddShader(&tcs); |
| 10848 | pipe.AddShader(&tes); |
| 10849 | pipe.AddShader(&fs); |
| 10850 | |
| 10851 | VkDescriptorSetObj descriptorSet(m_device); |
| 10852 | descriptorSet.AppendDummy(); |
| 10853 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10854 | |
| 10855 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10856 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10857 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 10858 | } |
| 10859 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10860 | TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) { |
| 10861 | m_errorMonitor->SetDesiredFailureMsg( |
| 10862 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10863 | "Duplicate vertex input binding descriptions for binding 0"); |
| 10864 | |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10865 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10866 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10867 | |
| 10868 | /* Two binding descriptions for binding 0 */ |
| 10869 | VkVertexInputBindingDescription input_bindings[2]; |
| 10870 | memset(input_bindings, 0, sizeof(input_bindings)); |
| 10871 | |
| 10872 | VkVertexInputAttributeDescription input_attrib; |
| 10873 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10874 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10875 | |
| 10876 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10877 | "#version 450\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10878 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10879 | "layout(location=0) in float x;\n" /* attrib provided float */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10880 | "out gl_PerVertex {\n" |
| 10881 | " vec4 gl_Position;\n" |
| 10882 | "};\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10883 | "void main(){\n" |
| 10884 | " gl_Position = vec4(x);\n" |
| 10885 | "}\n"; |
| 10886 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10887 | "#version 450\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10888 | "\n" |
| 10889 | "layout(location=0) out vec4 color;\n" |
| 10890 | "void main(){\n" |
| 10891 | " color = vec4(1);\n" |
| 10892 | "}\n"; |
| 10893 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10894 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10895 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10896 | |
| 10897 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10898 | pipe.AddColorAttachment(); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10899 | pipe.AddShader(&vs); |
| 10900 | pipe.AddShader(&fs); |
| 10901 | |
| 10902 | pipe.AddVertexInputBindings(input_bindings, 2); |
| 10903 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10904 | |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10905 | VkDescriptorSetObj descriptorSet(m_device); |
| 10906 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10907 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10908 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10909 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10910 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10911 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10912 | } |
Chris Forbes | 8f68b56 | 2015-05-25 11:13:32 +1200 | [diff] [blame] | 10913 | |
Chris Forbes | 35efec7 | 2016-04-21 14:32:08 +1200 | [diff] [blame] | 10914 | TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) { |
| 10915 | m_errorMonitor->ExpectSuccess(); |
| 10916 | |
| 10917 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10918 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10919 | |
| 10920 | if (!m_device->phy().features().tessellationShader) { |
| 10921 | printf("Device does not support 64bit vertex attributes; skipped.\n"); |
| 10922 | return; |
| 10923 | } |
| 10924 | |
| 10925 | VkVertexInputBindingDescription input_bindings[1]; |
| 10926 | memset(input_bindings, 0, sizeof(input_bindings)); |
| 10927 | |
| 10928 | VkVertexInputAttributeDescription input_attribs[4]; |
| 10929 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 10930 | input_attribs[0].location = 0; |
| 10931 | input_attribs[0].offset = 0; |
| 10932 | input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 10933 | input_attribs[1].location = 2; |
| 10934 | input_attribs[1].offset = 32; |
| 10935 | input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 10936 | input_attribs[2].location = 4; |
| 10937 | input_attribs[2].offset = 64; |
| 10938 | input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 10939 | input_attribs[3].location = 6; |
| 10940 | input_attribs[3].offset = 96; |
| 10941 | input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 10942 | |
| 10943 | char const *vsSource = |
| 10944 | "#version 450\n" |
| 10945 | "\n" |
| 10946 | "layout(location=0) in dmat4 x;\n" |
| 10947 | "out gl_PerVertex {\n" |
| 10948 | " vec4 gl_Position;\n" |
| 10949 | "};\n" |
| 10950 | "void main(){\n" |
| 10951 | " gl_Position = vec4(x[0][0]);\n" |
| 10952 | "}\n"; |
| 10953 | char const *fsSource = |
| 10954 | "#version 450\n" |
| 10955 | "\n" |
| 10956 | "layout(location=0) out vec4 color;\n" |
| 10957 | "void main(){\n" |
| 10958 | " color = vec4(1);\n" |
| 10959 | "}\n"; |
| 10960 | |
| 10961 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10962 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10963 | |
| 10964 | VkPipelineObj pipe(m_device); |
| 10965 | pipe.AddColorAttachment(); |
| 10966 | pipe.AddShader(&vs); |
| 10967 | pipe.AddShader(&fs); |
| 10968 | |
| 10969 | pipe.AddVertexInputBindings(input_bindings, 1); |
| 10970 | pipe.AddVertexInputAttribs(input_attribs, 4); |
| 10971 | |
| 10972 | VkDescriptorSetObj descriptorSet(m_device); |
| 10973 | descriptorSet.AppendDummy(); |
| 10974 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10975 | |
| 10976 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10977 | |
| 10978 | m_errorMonitor->VerifyNotFound(); |
| 10979 | } |
| 10980 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10981 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10982 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10983 | "Attachment 0 not written by FS"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10984 | |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10985 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10986 | |
| 10987 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10988 | "#version 450\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10989 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10990 | "out gl_PerVertex {\n" |
| 10991 | " vec4 gl_Position;\n" |
| 10992 | "};\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10993 | "void main(){\n" |
| 10994 | " gl_Position = vec4(1);\n" |
| 10995 | "}\n"; |
| 10996 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10997 | "#version 450\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10998 | "\n" |
| 10999 | "void main(){\n" |
| 11000 | "}\n"; |
| 11001 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11002 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11003 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11004 | |
| 11005 | VkPipelineObj pipe(m_device); |
| 11006 | pipe.AddShader(&vs); |
| 11007 | pipe.AddShader(&fs); |
| 11008 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11009 | /* set up CB 0, not written */ |
| 11010 | pipe.AddColorAttachment(); |
| 11011 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11012 | |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11013 | VkDescriptorSetObj descriptorSet(m_device); |
| 11014 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11015 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11016 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11017 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11018 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11019 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11020 | } |
| 11021 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11022 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11023 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 11024 | VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11025 | "FS writes to output location 1 with no matching attachment"); |
| 11026 | |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11027 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11028 | |
| 11029 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11030 | "#version 450\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11031 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11032 | "out gl_PerVertex {\n" |
| 11033 | " vec4 gl_Position;\n" |
| 11034 | "};\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11035 | "void main(){\n" |
| 11036 | " gl_Position = vec4(1);\n" |
| 11037 | "}\n"; |
| 11038 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11039 | "#version 450\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11040 | "\n" |
| 11041 | "layout(location=0) out vec4 x;\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11042 | "layout(location=1) out vec4 y;\n" /* no matching attachment for this */ |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11043 | "void main(){\n" |
| 11044 | " x = vec4(1);\n" |
| 11045 | " y = vec4(1);\n" |
| 11046 | "}\n"; |
| 11047 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11048 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11049 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11050 | |
| 11051 | VkPipelineObj pipe(m_device); |
| 11052 | pipe.AddShader(&vs); |
| 11053 | pipe.AddShader(&fs); |
| 11054 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11055 | /* set up CB 0, not written */ |
| 11056 | pipe.AddColorAttachment(); |
| 11057 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11058 | /* FS writes CB 1, but we don't configure it */ |
| 11059 | |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11060 | VkDescriptorSetObj descriptorSet(m_device); |
| 11061 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11062 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11063 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11064 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11065 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11066 | m_errorMonitor->VerifyFound(); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11067 | } |
| 11068 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11069 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11070 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11071 | "does not match FS output type"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11072 | |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11073 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11074 | |
| 11075 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11076 | "#version 450\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11077 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11078 | "out gl_PerVertex {\n" |
| 11079 | " vec4 gl_Position;\n" |
| 11080 | "};\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11081 | "void main(){\n" |
| 11082 | " gl_Position = vec4(1);\n" |
| 11083 | "}\n"; |
| 11084 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11085 | "#version 450\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11086 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11087 | "layout(location=0) out ivec4 x;\n" /* not UNORM */ |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11088 | "void main(){\n" |
| 11089 | " x = ivec4(1);\n" |
| 11090 | "}\n"; |
| 11091 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11092 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11093 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11094 | |
| 11095 | VkPipelineObj pipe(m_device); |
| 11096 | pipe.AddShader(&vs); |
| 11097 | pipe.AddShader(&fs); |
| 11098 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11099 | /* set up CB 0; type is UNORM by default */ |
| 11100 | pipe.AddColorAttachment(); |
| 11101 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11102 | |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11103 | VkDescriptorSetObj descriptorSet(m_device); |
| 11104 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11105 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11106 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11107 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11108 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11109 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11110 | } |
Chris Forbes | 7b1b893 | 2015-06-05 14:43:36 +1200 | [diff] [blame] | 11111 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11112 | TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11113 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11114 | "not declared in pipeline layout"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11115 | |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11116 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11117 | |
| 11118 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11119 | "#version 450\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11120 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11121 | "out gl_PerVertex {\n" |
| 11122 | " vec4 gl_Position;\n" |
| 11123 | "};\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11124 | "void main(){\n" |
| 11125 | " gl_Position = vec4(1);\n" |
| 11126 | "}\n"; |
| 11127 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11128 | "#version 450\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11129 | "\n" |
| 11130 | "layout(location=0) out vec4 x;\n" |
| 11131 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 11132 | "void main(){\n" |
| 11133 | " x = vec4(bar.y);\n" |
| 11134 | "}\n"; |
| 11135 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11136 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11137 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11138 | |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11139 | VkPipelineObj pipe(m_device); |
| 11140 | pipe.AddShader(&vs); |
| 11141 | pipe.AddShader(&fs); |
| 11142 | |
| 11143 | /* set up CB 0; type is UNORM by default */ |
| 11144 | pipe.AddColorAttachment(); |
| 11145 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11146 | |
| 11147 | VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11148 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11149 | |
| 11150 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11151 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11152 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11153 | } |
| 11154 | |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11155 | TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) { |
| 11156 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11157 | "not declared in layout"); |
| 11158 | |
| 11159 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11160 | |
| 11161 | char const *vsSource = |
| 11162 | "#version 450\n" |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11163 | "\n" |
| 11164 | "layout(push_constant, std430) uniform foo { float x; } consts;\n" |
| 11165 | "out gl_PerVertex {\n" |
| 11166 | " vec4 gl_Position;\n" |
| 11167 | "};\n" |
| 11168 | "void main(){\n" |
| 11169 | " gl_Position = vec4(consts.x);\n" |
| 11170 | "}\n"; |
| 11171 | char const *fsSource = |
| 11172 | "#version 450\n" |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11173 | "\n" |
| 11174 | "layout(location=0) out vec4 x;\n" |
| 11175 | "void main(){\n" |
| 11176 | " x = vec4(1);\n" |
| 11177 | "}\n"; |
| 11178 | |
| 11179 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11180 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11181 | |
| 11182 | VkPipelineObj pipe(m_device); |
| 11183 | pipe.AddShader(&vs); |
| 11184 | pipe.AddShader(&fs); |
| 11185 | |
| 11186 | /* set up CB 0; type is UNORM by default */ |
| 11187 | pipe.AddColorAttachment(); |
| 11188 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11189 | |
| 11190 | VkDescriptorSetObj descriptorSet(m_device); |
| 11191 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11192 | |
| 11193 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11194 | |
| 11195 | /* should have generated an error -- no push constant ranges provided! */ |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11196 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11197 | } |
| 11198 | |
Chris Forbes | 10eb9ae | 2016-05-31 16:09:42 +1200 | [diff] [blame] | 11199 | TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) { |
| 11200 | m_errorMonitor->SetDesiredFailureMsg( |
| 11201 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11202 | "Shader uses descriptor slot 0.0"); |
| 11203 | |
| 11204 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11205 | |
| 11206 | char const *csSource = |
| 11207 | "#version 450\n" |
| 11208 | "\n" |
| 11209 | "layout(local_size_x=1) in;\n" |
| 11210 | "layout(set=0, binding=0) buffer block { vec4 x; };\n" |
| 11211 | "void main(){\n" |
| 11212 | " x = vec4(1);\n" |
| 11213 | "}\n"; |
| 11214 | |
| 11215 | VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this); |
| 11216 | |
| 11217 | VkDescriptorSetObj descriptorSet(m_device); |
| 11218 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11219 | |
| 11220 | VkComputePipelineCreateInfo cpci = { |
| 11221 | VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, |
| 11222 | nullptr, 0, { |
| 11223 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 11224 | nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, |
| 11225 | cs.handle(), "main", nullptr |
| 11226 | }, |
| 11227 | descriptorSet.GetPipelineLayout(), |
| 11228 | VK_NULL_HANDLE, -1 |
| 11229 | }; |
| 11230 | |
| 11231 | VkPipeline pipe; |
| 11232 | VkResult err = vkCreateComputePipelines( |
| 11233 | m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe); |
| 11234 | |
| 11235 | m_errorMonitor->VerifyFound(); |
| 11236 | |
| 11237 | if (err == VK_SUCCESS) { |
| 11238 | vkDestroyPipeline(m_device->device(), pipe, nullptr); |
| 11239 | } |
| 11240 | } |
| 11241 | |
| 11242 | TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) { |
| 11243 | m_errorMonitor->ExpectSuccess(); |
| 11244 | |
| 11245 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11246 | |
| 11247 | char const *csSource = |
| 11248 | "#version 450\n" |
| 11249 | "\n" |
| 11250 | "layout(local_size_x=1) in;\n" |
| 11251 | "layout(set=0, binding=0) buffer block { vec4 x; };\n" |
| 11252 | "void main(){\n" |
| 11253 | " // x is not used.\n" |
| 11254 | "}\n"; |
| 11255 | |
| 11256 | VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this); |
| 11257 | |
| 11258 | VkDescriptorSetObj descriptorSet(m_device); |
| 11259 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11260 | |
| 11261 | VkComputePipelineCreateInfo cpci = { |
| 11262 | VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, |
| 11263 | nullptr, 0, { |
| 11264 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 11265 | nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, |
| 11266 | cs.handle(), "main", nullptr |
| 11267 | }, |
| 11268 | descriptorSet.GetPipelineLayout(), |
| 11269 | VK_NULL_HANDLE, -1 |
| 11270 | }; |
| 11271 | |
| 11272 | VkPipeline pipe; |
| 11273 | VkResult err = vkCreateComputePipelines( |
| 11274 | m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe); |
| 11275 | |
| 11276 | m_errorMonitor->VerifyNotFound(); |
| 11277 | |
| 11278 | if (err == VK_SUCCESS) { |
| 11279 | vkDestroyPipeline(m_device->device(), pipe, nullptr); |
| 11280 | } |
| 11281 | } |
| 11282 | |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 11283 | #endif // SHADER_CHECKER_TESTS |
| 11284 | |
| 11285 | #if DEVICE_LIMITS_TESTS |
Mark Young | c48c4c1 | 2016-04-11 14:26:49 -0600 | [diff] [blame] | 11286 | TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11287 | m_errorMonitor->SetDesiredFailureMsg( |
| 11288 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11289 | "CreateImage extents exceed allowable limits for format"); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11290 | |
| 11291 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11292 | |
| 11293 | // Create an image |
| 11294 | VkImage image; |
| 11295 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11296 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11297 | const int32_t tex_width = 32; |
| 11298 | const int32_t tex_height = 32; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11299 | |
| 11300 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11301 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11302 | image_create_info.pNext = NULL; |
| 11303 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11304 | image_create_info.format = tex_format; |
| 11305 | image_create_info.extent.width = tex_width; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11306 | image_create_info.extent.height = tex_height; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11307 | image_create_info.extent.depth = 1; |
| 11308 | image_create_info.mipLevels = 1; |
| 11309 | image_create_info.arrayLayers = 1; |
| 11310 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11311 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11312 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 11313 | image_create_info.flags = 0; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11314 | |
| 11315 | // Introduce error by sending down a bogus width extent |
| 11316 | image_create_info.extent.width = 65536; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11317 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11318 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11319 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11320 | } |
| 11321 | |
Mark Young | c48c4c1 | 2016-04-11 14:26:49 -0600 | [diff] [blame] | 11322 | TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) { |
| 11323 | m_errorMonitor->SetDesiredFailureMsg( |
| 11324 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11325 | "CreateImage extents is 0 for at least one required dimension"); |
| 11326 | |
| 11327 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11328 | |
| 11329 | // Create an image |
| 11330 | VkImage image; |
| 11331 | |
| 11332 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11333 | const int32_t tex_width = 32; |
| 11334 | const int32_t tex_height = 32; |
| 11335 | |
| 11336 | VkImageCreateInfo image_create_info = {}; |
| 11337 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11338 | image_create_info.pNext = NULL; |
| 11339 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11340 | image_create_info.format = tex_format; |
| 11341 | image_create_info.extent.width = tex_width; |
| 11342 | image_create_info.extent.height = tex_height; |
| 11343 | image_create_info.extent.depth = 1; |
| 11344 | image_create_info.mipLevels = 1; |
| 11345 | image_create_info.arrayLayers = 1; |
| 11346 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11347 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11348 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 11349 | image_create_info.flags = 0; |
| 11350 | |
| 11351 | // Introduce error by sending down a bogus width extent |
| 11352 | image_create_info.extent.width = 0; |
| 11353 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 11354 | |
| 11355 | m_errorMonitor->VerifyFound(); |
| 11356 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 11357 | #endif // DEVICE_LIMITS_TESTS |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11358 | |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11359 | #if IMAGE_TESTS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11360 | TEST_F(VkLayerTest, InvalidImageView) { |
| 11361 | VkResult err; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11362 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11363 | m_errorMonitor->SetDesiredFailureMsg( |
| 11364 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11365 | "vkCreateImageView called with baseMipLevel 10 "); |
| 11366 | |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11367 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11368 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11369 | // Create an image and try to create a view with bad baseMipLevel |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11370 | VkImage image; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11371 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11372 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11373 | const int32_t tex_width = 32; |
| 11374 | const int32_t tex_height = 32; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11375 | |
| 11376 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11377 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11378 | image_create_info.pNext = NULL; |
| 11379 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11380 | image_create_info.format = tex_format; |
| 11381 | image_create_info.extent.width = tex_width; |
| 11382 | image_create_info.extent.height = tex_height; |
| 11383 | image_create_info.extent.depth = 1; |
| 11384 | image_create_info.mipLevels = 1; |
| 11385 | image_create_info.arrayLayers = 1; |
| 11386 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11387 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11388 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 11389 | image_create_info.flags = 0; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11390 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11391 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11392 | ASSERT_VK_SUCCESS(err); |
| 11393 | |
| 11394 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11395 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11396 | image_view_create_info.image = image; |
| 11397 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 11398 | image_view_create_info.format = tex_format; |
| 11399 | image_view_create_info.subresourceRange.layerCount = 1; |
| 11400 | image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error |
| 11401 | image_view_create_info.subresourceRange.levelCount = 1; |
| 11402 | image_view_create_info.subresourceRange.aspectMask = |
| 11403 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11404 | |
| 11405 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11406 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 11407 | &view); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11408 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11409 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 11410 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11411 | } |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11412 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11413 | TEST_F(VkLayerTest, InvalidImageViewAspect) { |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11414 | TEST_DESCRIPTION( |
| 11415 | "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] | 11416 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11417 | "vkCreateImageView: Color image " |
| 11418 | "formats must have ONLY the " |
| 11419 | "VK_IMAGE_ASPECT_COLOR_BIT set"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11420 | |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11421 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11422 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11423 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11424 | VkImageObj image(m_device); |
| 11425 | image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, |
| 11426 | VK_IMAGE_TILING_LINEAR, 0); |
| 11427 | ASSERT_TRUE(image.initialized()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11428 | |
| 11429 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11430 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11431 | image_view_create_info.image = image.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11432 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 11433 | image_view_create_info.format = tex_format; |
| 11434 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 11435 | image_view_create_info.subresourceRange.levelCount = 1; |
| 11436 | // Cause an error by setting an invalid image aspect |
| 11437 | image_view_create_info.subresourceRange.aspectMask = |
| 11438 | VK_IMAGE_ASPECT_METADATA_BIT; |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11439 | |
| 11440 | VkImageView view; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11441 | vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11442 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11443 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11444 | } |
| 11445 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11446 | TEST_F(VkLayerTest, CopyImageLayerCountMismatch) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11447 | VkResult err; |
| 11448 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11449 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11450 | m_errorMonitor->SetDesiredFailureMsg( |
| 11451 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11452 | "vkCmdCopyImage: number of layers in source and destination subresources for pRegions"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11453 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11454 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11455 | |
| 11456 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11457 | VkImage srcImage; |
| 11458 | VkImage dstImage; |
| 11459 | VkDeviceMemory srcMem; |
| 11460 | VkDeviceMemory destMem; |
| 11461 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11462 | |
| 11463 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11464 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11465 | image_create_info.pNext = NULL; |
| 11466 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11467 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11468 | image_create_info.extent.width = 32; |
| 11469 | image_create_info.extent.height = 32; |
| 11470 | image_create_info.extent.depth = 1; |
| 11471 | image_create_info.mipLevels = 1; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11472 | image_create_info.arrayLayers = 4; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11473 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11474 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 11475 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11476 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11477 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11478 | err = |
| 11479 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11480 | ASSERT_VK_SUCCESS(err); |
| 11481 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11482 | err = |
| 11483 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11484 | ASSERT_VK_SUCCESS(err); |
| 11485 | |
| 11486 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11487 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11488 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 11489 | memAlloc.pNext = NULL; |
| 11490 | memAlloc.allocationSize = 0; |
| 11491 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11492 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 11493 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11494 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11495 | pass = |
| 11496 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 11497 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11498 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11499 | ASSERT_VK_SUCCESS(err); |
| 11500 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11501 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11502 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11503 | pass = |
| 11504 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11505 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11506 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11507 | ASSERT_VK_SUCCESS(err); |
| 11508 | |
| 11509 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 11510 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11511 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11512 | ASSERT_VK_SUCCESS(err); |
| 11513 | |
| 11514 | BeginCommandBuffer(); |
| 11515 | VkImageCopy copyRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11516 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11517 | copyRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 11518 | copyRegion.srcSubresource.baseArrayLayer = 0; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11519 | copyRegion.srcSubresource.layerCount = 1; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11520 | copyRegion.srcOffset.x = 0; |
| 11521 | copyRegion.srcOffset.y = 0; |
| 11522 | copyRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11523 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11524 | copyRegion.dstSubresource.mipLevel = 0; |
| 11525 | copyRegion.dstSubresource.baseArrayLayer = 0; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11526 | // Introduce failure by forcing the dst layerCount to differ from src |
| 11527 | copyRegion.dstSubresource.layerCount = 3; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11528 | copyRegion.dstOffset.x = 0; |
| 11529 | copyRegion.dstOffset.y = 0; |
| 11530 | copyRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11531 | copyRegion.extent.width = 1; |
| 11532 | copyRegion.extent.height = 1; |
| 11533 | copyRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11534 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 11535 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11536 | EndCommandBuffer(); |
| 11537 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11538 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11539 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11540 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11541 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11542 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 11543 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11544 | } |
| 11545 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11546 | TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) { |
| 11547 | |
| 11548 | TEST_DESCRIPTION("Creating images with unsuported formats "); |
| 11549 | |
| 11550 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11551 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11552 | VkImageObj image(m_device); |
| 11553 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 11554 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 11555 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 11556 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 11557 | ASSERT_TRUE(image.initialized()); |
| 11558 | |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11559 | // Create image with unsupported format - Expect FORMAT_UNSUPPORTED |
| 11560 | VkImageCreateInfo image_create_info; |
| 11561 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11562 | image_create_info.pNext = NULL; |
| 11563 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11564 | image_create_info.format = VK_FORMAT_UNDEFINED; |
| 11565 | image_create_info.extent.width = 32; |
| 11566 | image_create_info.extent.height = 32; |
| 11567 | image_create_info.extent.depth = 1; |
| 11568 | image_create_info.mipLevels = 1; |
| 11569 | image_create_info.arrayLayers = 1; |
| 11570 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11571 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 11572 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11573 | image_create_info.flags = 0; |
| 11574 | |
| 11575 | m_errorMonitor->SetDesiredFailureMsg( |
| 11576 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11577 | "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED"); |
| 11578 | |
| 11579 | VkImage localImage; |
| 11580 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage); |
| 11581 | m_errorMonitor->VerifyFound(); |
| 11582 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11583 | VkFormat unsupported = VK_FORMAT_UNDEFINED; |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11584 | // Look for a format that is COMPLETELY unsupported with this hardware |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11585 | for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) { |
| 11586 | VkFormat format = static_cast<VkFormat>(f); |
| 11587 | VkFormatProperties fProps = m_device->format_properties(format); |
| 11588 | if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && |
| 11589 | fProps.optimalTilingFeatures == 0) { |
| 11590 | unsupported = format; |
| 11591 | break; |
| 11592 | } |
| 11593 | } |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11594 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11595 | if (unsupported != VK_FORMAT_UNDEFINED) { |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11596 | image_create_info.format = unsupported; |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11597 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11598 | "is an unsupported format"); |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11599 | |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11600 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage); |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11601 | m_errorMonitor->VerifyFound(); |
| 11602 | } |
| 11603 | } |
| 11604 | |
| 11605 | TEST_F(VkLayerTest, ImageLayerViewTests) { |
| 11606 | VkResult ret; |
| 11607 | TEST_DESCRIPTION("Passing bad parameters to CreateImageView"); |
| 11608 | |
| 11609 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11610 | |
| 11611 | VkImageObj image(m_device); |
| 11612 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 11613 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 11614 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 11615 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 11616 | ASSERT_TRUE(image.initialized()); |
| 11617 | |
| 11618 | VkImageView imgView; |
| 11619 | VkImageViewCreateInfo imgViewInfo = {}; |
| 11620 | imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 11621 | imgViewInfo.image = image.handle(); |
| 11622 | imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 11623 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11624 | imgViewInfo.subresourceRange.layerCount = 1; |
| 11625 | imgViewInfo.subresourceRange.baseMipLevel = 0; |
| 11626 | imgViewInfo.subresourceRange.levelCount = 1; |
| 11627 | imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11628 | |
| 11629 | m_errorMonitor->SetDesiredFailureMsg( |
| 11630 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11631 | "vkCreateImageView called with baseMipLevel"); |
| 11632 | // View can't have baseMipLevel >= image's mipLevels - Expect |
| 11633 | // VIEW_CREATE_ERROR |
| 11634 | imgViewInfo.subresourceRange.baseMipLevel = 1; |
| 11635 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11636 | m_errorMonitor->VerifyFound(); |
| 11637 | imgViewInfo.subresourceRange.baseMipLevel = 0; |
| 11638 | |
| 11639 | m_errorMonitor->SetDesiredFailureMsg( |
| 11640 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11641 | "vkCreateImageView called with baseArrayLayer"); |
| 11642 | // View can't have baseArrayLayer >= image's arraySize - Expect |
| 11643 | // VIEW_CREATE_ERROR |
| 11644 | imgViewInfo.subresourceRange.baseArrayLayer = 1; |
| 11645 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11646 | m_errorMonitor->VerifyFound(); |
| 11647 | imgViewInfo.subresourceRange.baseArrayLayer = 0; |
| 11648 | |
| 11649 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11650 | "vkCreateImageView called with 0 in " |
| 11651 | "pCreateInfo->subresourceRange." |
| 11652 | "levelCount"); |
| 11653 | // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR |
| 11654 | imgViewInfo.subresourceRange.levelCount = 0; |
| 11655 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11656 | m_errorMonitor->VerifyFound(); |
| 11657 | imgViewInfo.subresourceRange.levelCount = 1; |
| 11658 | |
| 11659 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11660 | "vkCreateImageView called with 0 in " |
| 11661 | "pCreateInfo->subresourceRange." |
| 11662 | "layerCount"); |
| 11663 | // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR |
| 11664 | imgViewInfo.subresourceRange.layerCount = 0; |
| 11665 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11666 | m_errorMonitor->VerifyFound(); |
| 11667 | imgViewInfo.subresourceRange.layerCount = 1; |
| 11668 | |
| 11669 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11670 | "but both must be color formats"); |
| 11671 | // Can't use depth format for view into color image - Expect INVALID_FORMAT |
| 11672 | imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 11673 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11674 | m_errorMonitor->VerifyFound(); |
| 11675 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11676 | |
| 11677 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11678 | "Formats MUST be IDENTICAL unless " |
| 11679 | "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT " |
| 11680 | "was set on image creation."); |
| 11681 | // Same compatibility class but no MUTABLE_FORMAT bit - Expect |
| 11682 | // VIEW_CREATE_ERROR |
| 11683 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT; |
| 11684 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11685 | m_errorMonitor->VerifyFound(); |
| 11686 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11687 | |
| 11688 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11689 | "can support ImageViews with " |
| 11690 | "differing formats but they must be " |
| 11691 | "in the same compatibility class."); |
| 11692 | // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect |
| 11693 | // VIEW_CREATE_ERROR |
| 11694 | VkImageCreateInfo mutImgInfo = image.create_info(); |
| 11695 | VkImage mutImage; |
| 11696 | mutImgInfo.format = VK_FORMAT_R8_UINT; |
| 11697 | assert( |
| 11698 | m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & |
| 11699 | VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT); |
| 11700 | mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; |
| 11701 | mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 11702 | ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage); |
| 11703 | ASSERT_VK_SUCCESS(ret); |
| 11704 | imgViewInfo.image = mutImage; |
| 11705 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11706 | m_errorMonitor->VerifyFound(); |
| 11707 | imgViewInfo.image = image.handle(); |
| 11708 | vkDestroyImage(m_device->handle(), mutImage, NULL); |
| 11709 | } |
| 11710 | |
| 11711 | TEST_F(VkLayerTest, MiscImageLayerTests) { |
| 11712 | |
| 11713 | TEST_DESCRIPTION("Image layer tests that don't belong elsewhare"); |
| 11714 | |
| 11715 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11716 | |
| 11717 | VkImageObj image(m_device); |
| 11718 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 11719 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 11720 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 11721 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 11722 | ASSERT_TRUE(image.initialized()); |
| 11723 | |
| 11724 | m_errorMonitor->SetDesiredFailureMsg( |
| 11725 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11726 | "number of layers in image subresource is zero"); |
| 11727 | vk_testing::Buffer buffer; |
| 11728 | VkMemoryPropertyFlags reqs = 0; |
| 11729 | buffer.init_as_src(*m_device, 128 * 128 * 4, reqs); |
| 11730 | VkBufferImageCopy region = {}; |
| 11731 | region.bufferRowLength = 128; |
| 11732 | region.bufferImageHeight = 128; |
| 11733 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11734 | // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT |
| 11735 | region.imageSubresource.layerCount = 0; |
| 11736 | region.imageExtent.height = 4; |
| 11737 | region.imageExtent.width = 4; |
| 11738 | region.imageExtent.depth = 1; |
| 11739 | m_commandBuffer->BeginCommandBuffer(); |
| 11740 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 11741 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 11742 | 1, ®ion); |
| 11743 | m_errorMonitor->VerifyFound(); |
| 11744 | region.imageSubresource.layerCount = 1; |
| 11745 | |
| 11746 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11747 | "aspectMasks for each region must " |
| 11748 | "specify only COLOR or DEPTH or " |
| 11749 | "STENCIL"); |
| 11750 | // Expect MISMATCHED_IMAGE_ASPECT |
| 11751 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT; |
| 11752 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 11753 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 11754 | 1, ®ion); |
| 11755 | m_errorMonitor->VerifyFound(); |
| 11756 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11757 | |
| 11758 | m_errorMonitor->SetDesiredFailureMsg( |
| 11759 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11760 | "If the format of srcImage is a depth, stencil, depth stencil or " |
| 11761 | "integer-based format then filter must be VK_FILTER_NEAREST"); |
| 11762 | // Expect INVALID_FILTER |
| 11763 | VkImageObj intImage1(m_device); |
| 11764 | intImage1.init(128, 128, VK_FORMAT_R8_UINT, |
| 11765 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, |
| 11766 | 0); |
| 11767 | VkImageObj intImage2(m_device); |
| 11768 | intImage2.init(128, 128, VK_FORMAT_R8_UINT, |
| 11769 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, |
| 11770 | 0); |
| 11771 | VkImageBlit blitRegion = {}; |
| 11772 | blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11773 | blitRegion.srcSubresource.baseArrayLayer = 0; |
| 11774 | blitRegion.srcSubresource.layerCount = 1; |
| 11775 | blitRegion.srcSubresource.mipLevel = 0; |
| 11776 | blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11777 | blitRegion.dstSubresource.baseArrayLayer = 0; |
| 11778 | blitRegion.dstSubresource.layerCount = 1; |
| 11779 | blitRegion.dstSubresource.mipLevel = 0; |
| 11780 | |
| 11781 | vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), |
| 11782 | intImage1.layout(), intImage2.handle(), intImage2.layout(), |
| 11783 | 16, &blitRegion, VK_FILTER_LINEAR); |
| 11784 | m_errorMonitor->VerifyFound(); |
| 11785 | |
| 11786 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11787 | "called with 0 in ppMemoryBarriers"); |
| 11788 | VkImageMemoryBarrier img_barrier; |
| 11789 | img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 11790 | img_barrier.pNext = NULL; |
| 11791 | img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 11792 | img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 11793 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 11794 | img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 11795 | img_barrier.image = image.handle(); |
| 11796 | img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 11797 | img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 11798 | img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11799 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 11800 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 11801 | // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE |
| 11802 | img_barrier.subresourceRange.layerCount = 0; |
| 11803 | img_barrier.subresourceRange.levelCount = 1; |
| 11804 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 11805 | VK_PIPELINE_STAGE_HOST_BIT, |
| 11806 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 11807 | nullptr, 1, &img_barrier); |
| 11808 | m_errorMonitor->VerifyFound(); |
| 11809 | img_barrier.subresourceRange.layerCount = 1; |
| 11810 | } |
| 11811 | |
| 11812 | TEST_F(VkLayerTest, ImageFormatLimits) { |
| 11813 | |
| 11814 | TEST_DESCRIPTION("Exceed the limits of image format "); |
| 11815 | |
| 11816 | m_errorMonitor->SetDesiredFailureMsg( |
| 11817 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11818 | "CreateImage extents exceed allowable limits for format"); |
| 11819 | VkImageCreateInfo image_create_info = {}; |
| 11820 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11821 | image_create_info.pNext = NULL; |
| 11822 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11823 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11824 | image_create_info.extent.width = 32; |
| 11825 | image_create_info.extent.height = 32; |
| 11826 | image_create_info.extent.depth = 1; |
| 11827 | image_create_info.mipLevels = 1; |
| 11828 | image_create_info.arrayLayers = 1; |
| 11829 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11830 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11831 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11832 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 11833 | image_create_info.flags = 0; |
| 11834 | |
| 11835 | VkImage nullImg; |
| 11836 | VkImageFormatProperties imgFmtProps; |
| 11837 | vkGetPhysicalDeviceImageFormatProperties( |
| 11838 | gpu(), image_create_info.format, image_create_info.imageType, |
| 11839 | image_create_info.tiling, image_create_info.usage, |
| 11840 | image_create_info.flags, &imgFmtProps); |
| 11841 | image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1; |
| 11842 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 11843 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11844 | m_errorMonitor->VerifyFound(); |
| 11845 | image_create_info.extent.depth = 1; |
| 11846 | |
| 11847 | m_errorMonitor->SetDesiredFailureMsg( |
| 11848 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11849 | "exceeds allowable maximum supported by format of"); |
| 11850 | image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1; |
| 11851 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 11852 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11853 | m_errorMonitor->VerifyFound(); |
| 11854 | image_create_info.mipLevels = 1; |
| 11855 | |
| 11856 | m_errorMonitor->SetDesiredFailureMsg( |
| 11857 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11858 | "exceeds allowable maximum supported by format of"); |
| 11859 | image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1; |
| 11860 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 11861 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11862 | m_errorMonitor->VerifyFound(); |
| 11863 | image_create_info.arrayLayers = 1; |
| 11864 | |
| 11865 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11866 | "is not supported by format"); |
| 11867 | int samples = imgFmtProps.sampleCounts >> 1; |
| 11868 | image_create_info.samples = (VkSampleCountFlagBits)samples; |
| 11869 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 11870 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11871 | m_errorMonitor->VerifyFound(); |
| 11872 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11873 | |
| 11874 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11875 | "pCreateInfo->initialLayout, must be " |
| 11876 | "VK_IMAGE_LAYOUT_UNDEFINED or " |
| 11877 | "VK_IMAGE_LAYOUT_PREINITIALIZED"); |
| 11878 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 11879 | // Expect INVALID_LAYOUT |
| 11880 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11881 | m_errorMonitor->VerifyFound(); |
| 11882 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 11883 | } |
| 11884 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11885 | TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 11886 | VkResult err; |
| 11887 | bool pass; |
| 11888 | |
| 11889 | // Create color images with different format sizes and try to copy between them |
| 11890 | m_errorMonitor->SetDesiredFailureMsg( |
| 11891 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11892 | "vkCmdCopyImage called with unmatched source and dest image format sizes"); |
| 11893 | |
| 11894 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11895 | |
| 11896 | // Create two images of different types and try to copy between them |
| 11897 | VkImage srcImage; |
| 11898 | VkImage dstImage; |
| 11899 | VkDeviceMemory srcMem; |
| 11900 | VkDeviceMemory destMem; |
| 11901 | VkMemoryRequirements memReqs; |
| 11902 | |
| 11903 | VkImageCreateInfo image_create_info = {}; |
| 11904 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11905 | image_create_info.pNext = NULL; |
| 11906 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11907 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11908 | image_create_info.extent.width = 32; |
| 11909 | image_create_info.extent.height = 32; |
| 11910 | image_create_info.extent.depth = 1; |
| 11911 | image_create_info.mipLevels = 1; |
| 11912 | image_create_info.arrayLayers = 1; |
| 11913 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11914 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11915 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11916 | image_create_info.flags = 0; |
| 11917 | |
| 11918 | err = |
| 11919 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
| 11920 | ASSERT_VK_SUCCESS(err); |
| 11921 | |
| 11922 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 11923 | // Introduce failure by creating second image with a different-sized format. |
| 11924 | image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16; |
| 11925 | |
| 11926 | err = |
| 11927 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
| 11928 | ASSERT_VK_SUCCESS(err); |
| 11929 | |
| 11930 | // Allocate memory |
| 11931 | VkMemoryAllocateInfo memAlloc = {}; |
| 11932 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 11933 | memAlloc.pNext = NULL; |
| 11934 | memAlloc.allocationSize = 0; |
| 11935 | memAlloc.memoryTypeIndex = 0; |
| 11936 | |
| 11937 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
| 11938 | memAlloc.allocationSize = memReqs.size; |
| 11939 | pass = |
| 11940 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
| 11941 | ASSERT_TRUE(pass); |
| 11942 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
| 11943 | ASSERT_VK_SUCCESS(err); |
| 11944 | |
| 11945 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
| 11946 | memAlloc.allocationSize = memReqs.size; |
| 11947 | pass = |
| 11948 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
| 11949 | ASSERT_TRUE(pass); |
| 11950 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
| 11951 | ASSERT_VK_SUCCESS(err); |
| 11952 | |
| 11953 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 11954 | ASSERT_VK_SUCCESS(err); |
| 11955 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
| 11956 | ASSERT_VK_SUCCESS(err); |
| 11957 | |
| 11958 | BeginCommandBuffer(); |
| 11959 | VkImageCopy copyRegion; |
| 11960 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11961 | copyRegion.srcSubresource.mipLevel = 0; |
| 11962 | copyRegion.srcSubresource.baseArrayLayer = 0; |
| 11963 | copyRegion.srcSubresource.layerCount = 0; |
| 11964 | copyRegion.srcOffset.x = 0; |
| 11965 | copyRegion.srcOffset.y = 0; |
| 11966 | copyRegion.srcOffset.z = 0; |
| 11967 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11968 | copyRegion.dstSubresource.mipLevel = 0; |
| 11969 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 11970 | copyRegion.dstSubresource.layerCount = 0; |
| 11971 | copyRegion.dstOffset.x = 0; |
| 11972 | copyRegion.dstOffset.y = 0; |
| 11973 | copyRegion.dstOffset.z = 0; |
| 11974 | copyRegion.extent.width = 1; |
| 11975 | copyRegion.extent.height = 1; |
| 11976 | copyRegion.extent.depth = 1; |
| 11977 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 11978 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 11979 | EndCommandBuffer(); |
| 11980 | |
| 11981 | m_errorMonitor->VerifyFound(); |
| 11982 | |
| 11983 | vkDestroyImage(m_device->device(), srcImage, NULL); |
| 11984 | vkDestroyImage(m_device->device(), dstImage, NULL); |
| 11985 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 11986 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11987 | } |
| 11988 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11989 | TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) { |
| 11990 | VkResult err; |
| 11991 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11992 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11993 | // 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] | 11994 | m_errorMonitor->SetDesiredFailureMsg( |
| 11995 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11996 | "vkCmdCopyImage called with unmatched source and dest image depth"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11997 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11998 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11999 | |
| 12000 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12001 | VkImage srcImage; |
| 12002 | VkImage dstImage; |
| 12003 | VkDeviceMemory srcMem; |
| 12004 | VkDeviceMemory destMem; |
| 12005 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12006 | |
| 12007 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12008 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12009 | image_create_info.pNext = NULL; |
| 12010 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12011 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12012 | image_create_info.extent.width = 32; |
| 12013 | image_create_info.extent.height = 32; |
| 12014 | image_create_info.extent.depth = 1; |
| 12015 | image_create_info.mipLevels = 1; |
| 12016 | image_create_info.arrayLayers = 1; |
| 12017 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12018 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12019 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 12020 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12021 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12022 | err = |
| 12023 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12024 | ASSERT_VK_SUCCESS(err); |
| 12025 | |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 12026 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 12027 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12028 | // Introduce failure by creating second image with a depth/stencil format |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12029 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12030 | image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 12031 | image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12032 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12033 | err = |
| 12034 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12035 | ASSERT_VK_SUCCESS(err); |
| 12036 | |
| 12037 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12038 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12039 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12040 | memAlloc.pNext = NULL; |
| 12041 | memAlloc.allocationSize = 0; |
| 12042 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12043 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12044 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12045 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12046 | pass = |
| 12047 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12048 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12049 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12050 | ASSERT_VK_SUCCESS(err); |
| 12051 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12052 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12053 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12054 | pass = |
| 12055 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12056 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12057 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12058 | ASSERT_VK_SUCCESS(err); |
| 12059 | |
| 12060 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12061 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12062 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12063 | ASSERT_VK_SUCCESS(err); |
| 12064 | |
| 12065 | BeginCommandBuffer(); |
| 12066 | VkImageCopy copyRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12067 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12068 | copyRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12069 | copyRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12070 | copyRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12071 | copyRegion.srcOffset.x = 0; |
| 12072 | copyRegion.srcOffset.y = 0; |
| 12073 | copyRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12074 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12075 | copyRegion.dstSubresource.mipLevel = 0; |
| 12076 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 12077 | copyRegion.dstSubresource.layerCount = 0; |
| 12078 | copyRegion.dstOffset.x = 0; |
| 12079 | copyRegion.dstOffset.y = 0; |
| 12080 | copyRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12081 | copyRegion.extent.width = 1; |
| 12082 | copyRegion.extent.height = 1; |
| 12083 | copyRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12084 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12085 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12086 | EndCommandBuffer(); |
| 12087 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12088 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12089 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12090 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12091 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12092 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12093 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12094 | } |
| 12095 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12096 | TEST_F(VkLayerTest, ResolveImageLowSampleCount) { |
| 12097 | VkResult err; |
| 12098 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12099 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12100 | m_errorMonitor->SetDesiredFailureMsg( |
| 12101 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12102 | "vkCmdResolveImage called with source sample count less than 2."); |
| 12103 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12104 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12105 | |
| 12106 | // 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] | 12107 | VkImage srcImage; |
| 12108 | VkImage dstImage; |
| 12109 | VkDeviceMemory srcMem; |
| 12110 | VkDeviceMemory destMem; |
| 12111 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12112 | |
| 12113 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12114 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12115 | image_create_info.pNext = NULL; |
| 12116 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12117 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12118 | image_create_info.extent.width = 32; |
| 12119 | image_create_info.extent.height = 1; |
| 12120 | image_create_info.extent.depth = 1; |
| 12121 | image_create_info.mipLevels = 1; |
| 12122 | image_create_info.arrayLayers = 1; |
| 12123 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12124 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12125 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 12126 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12127 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12128 | err = |
| 12129 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12130 | ASSERT_VK_SUCCESS(err); |
| 12131 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12132 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12133 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12134 | err = |
| 12135 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12136 | ASSERT_VK_SUCCESS(err); |
| 12137 | |
| 12138 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12139 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12140 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12141 | memAlloc.pNext = NULL; |
| 12142 | memAlloc.allocationSize = 0; |
| 12143 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12144 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12145 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12146 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12147 | pass = |
| 12148 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12149 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12150 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12151 | ASSERT_VK_SUCCESS(err); |
| 12152 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12153 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12154 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12155 | pass = |
| 12156 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12157 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12158 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12159 | ASSERT_VK_SUCCESS(err); |
| 12160 | |
| 12161 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12162 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12163 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12164 | ASSERT_VK_SUCCESS(err); |
| 12165 | |
| 12166 | BeginCommandBuffer(); |
| 12167 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12168 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12169 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12170 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12171 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12172 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12173 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12174 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12175 | resolveRegion.srcOffset.x = 0; |
| 12176 | resolveRegion.srcOffset.y = 0; |
| 12177 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12178 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12179 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12180 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12181 | resolveRegion.dstSubresource.layerCount = 0; |
| 12182 | resolveRegion.dstOffset.x = 0; |
| 12183 | resolveRegion.dstOffset.y = 0; |
| 12184 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12185 | resolveRegion.extent.width = 1; |
| 12186 | resolveRegion.extent.height = 1; |
| 12187 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12188 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12189 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12190 | EndCommandBuffer(); |
| 12191 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12192 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12193 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12194 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12195 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12196 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12197 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12198 | } |
| 12199 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12200 | TEST_F(VkLayerTest, ResolveImageHighSampleCount) { |
| 12201 | VkResult err; |
| 12202 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12203 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12204 | m_errorMonitor->SetDesiredFailureMsg( |
| 12205 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12206 | "vkCmdResolveImage called with dest sample count greater than 1."); |
| 12207 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12208 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12209 | |
Chris Forbes | a753069 | 2016-05-08 12:35:39 +1200 | [diff] [blame] | 12210 | // 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] | 12211 | VkImage srcImage; |
| 12212 | VkImage dstImage; |
| 12213 | VkDeviceMemory srcMem; |
| 12214 | VkDeviceMemory destMem; |
| 12215 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12216 | |
| 12217 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12218 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12219 | image_create_info.pNext = NULL; |
| 12220 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12221 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12222 | image_create_info.extent.width = 32; |
| 12223 | image_create_info.extent.height = 1; |
| 12224 | image_create_info.extent.depth = 1; |
| 12225 | image_create_info.mipLevels = 1; |
| 12226 | image_create_info.arrayLayers = 1; |
Chris Forbes | a753069 | 2016-05-08 12:35:39 +1200 | [diff] [blame] | 12227 | image_create_info.samples = VK_SAMPLE_COUNT_4_BIT; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12228 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12229 | // Note: Some implementations expect color attachment usage for any |
| 12230 | // multisample surface |
| 12231 | image_create_info.usage = |
| 12232 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12233 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12234 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12235 | err = |
| 12236 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12237 | ASSERT_VK_SUCCESS(err); |
| 12238 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12239 | // Note: Some implementations expect color attachment usage for any |
| 12240 | // multisample surface |
| 12241 | image_create_info.usage = |
| 12242 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12243 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12244 | err = |
| 12245 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12246 | ASSERT_VK_SUCCESS(err); |
| 12247 | |
| 12248 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12249 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12250 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12251 | memAlloc.pNext = NULL; |
| 12252 | memAlloc.allocationSize = 0; |
| 12253 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12254 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12255 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12256 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12257 | pass = |
| 12258 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12259 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12260 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12261 | ASSERT_VK_SUCCESS(err); |
| 12262 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12263 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12264 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12265 | pass = |
| 12266 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12267 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12268 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12269 | ASSERT_VK_SUCCESS(err); |
| 12270 | |
| 12271 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12272 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12273 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12274 | ASSERT_VK_SUCCESS(err); |
| 12275 | |
| 12276 | BeginCommandBuffer(); |
| 12277 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12278 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12279 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12280 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12281 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12282 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12283 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12284 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12285 | resolveRegion.srcOffset.x = 0; |
| 12286 | resolveRegion.srcOffset.y = 0; |
| 12287 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12288 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12289 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12290 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12291 | resolveRegion.dstSubresource.layerCount = 0; |
| 12292 | resolveRegion.dstOffset.x = 0; |
| 12293 | resolveRegion.dstOffset.y = 0; |
| 12294 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12295 | resolveRegion.extent.width = 1; |
| 12296 | resolveRegion.extent.height = 1; |
| 12297 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12298 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12299 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12300 | EndCommandBuffer(); |
| 12301 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12302 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12303 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12304 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12305 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12306 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12307 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12308 | } |
| 12309 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12310 | TEST_F(VkLayerTest, ResolveImageFormatMismatch) { |
| 12311 | VkResult err; |
| 12312 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12313 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12314 | m_errorMonitor->SetDesiredFailureMsg( |
| 12315 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12316 | "vkCmdResolveImage called with unmatched source and dest formats."); |
| 12317 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12318 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12319 | |
| 12320 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12321 | VkImage srcImage; |
| 12322 | VkImage dstImage; |
| 12323 | VkDeviceMemory srcMem; |
| 12324 | VkDeviceMemory destMem; |
| 12325 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12326 | |
| 12327 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12328 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12329 | image_create_info.pNext = NULL; |
| 12330 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12331 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12332 | image_create_info.extent.width = 32; |
| 12333 | image_create_info.extent.height = 1; |
| 12334 | image_create_info.extent.depth = 1; |
| 12335 | image_create_info.mipLevels = 1; |
| 12336 | image_create_info.arrayLayers = 1; |
| 12337 | image_create_info.samples = VK_SAMPLE_COUNT_2_BIT; |
| 12338 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12339 | // Note: Some implementations expect color attachment usage for any |
| 12340 | // multisample surface |
| 12341 | image_create_info.usage = |
| 12342 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12343 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12344 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12345 | err = |
| 12346 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12347 | ASSERT_VK_SUCCESS(err); |
| 12348 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12349 | // Set format to something other than source image |
| 12350 | image_create_info.format = VK_FORMAT_R32_SFLOAT; |
| 12351 | // Note: Some implementations expect color attachment usage for any |
| 12352 | // multisample surface |
| 12353 | image_create_info.usage = |
| 12354 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12355 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12356 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12357 | err = |
| 12358 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12359 | ASSERT_VK_SUCCESS(err); |
| 12360 | |
| 12361 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12362 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12363 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12364 | memAlloc.pNext = NULL; |
| 12365 | memAlloc.allocationSize = 0; |
| 12366 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12367 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12368 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12369 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12370 | pass = |
| 12371 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12372 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12373 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12374 | ASSERT_VK_SUCCESS(err); |
| 12375 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12376 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12377 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12378 | pass = |
| 12379 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12380 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12381 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12382 | ASSERT_VK_SUCCESS(err); |
| 12383 | |
| 12384 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12385 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12386 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12387 | ASSERT_VK_SUCCESS(err); |
| 12388 | |
| 12389 | BeginCommandBuffer(); |
| 12390 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12391 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12392 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12393 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12394 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12395 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12396 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12397 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12398 | resolveRegion.srcOffset.x = 0; |
| 12399 | resolveRegion.srcOffset.y = 0; |
| 12400 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12401 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12402 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12403 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12404 | resolveRegion.dstSubresource.layerCount = 0; |
| 12405 | resolveRegion.dstOffset.x = 0; |
| 12406 | resolveRegion.dstOffset.y = 0; |
| 12407 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12408 | resolveRegion.extent.width = 1; |
| 12409 | resolveRegion.extent.height = 1; |
| 12410 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12411 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12412 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12413 | EndCommandBuffer(); |
| 12414 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12415 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12416 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12417 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12418 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12419 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12420 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12421 | } |
| 12422 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12423 | TEST_F(VkLayerTest, ResolveImageTypeMismatch) { |
| 12424 | VkResult err; |
| 12425 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12426 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12427 | m_errorMonitor->SetDesiredFailureMsg( |
| 12428 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12429 | "vkCmdResolveImage called with unmatched source and dest image types."); |
| 12430 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12431 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12432 | |
| 12433 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12434 | VkImage srcImage; |
| 12435 | VkImage dstImage; |
| 12436 | VkDeviceMemory srcMem; |
| 12437 | VkDeviceMemory destMem; |
| 12438 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12439 | |
| 12440 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12441 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12442 | image_create_info.pNext = NULL; |
| 12443 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12444 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12445 | image_create_info.extent.width = 32; |
| 12446 | image_create_info.extent.height = 1; |
| 12447 | image_create_info.extent.depth = 1; |
| 12448 | image_create_info.mipLevels = 1; |
| 12449 | image_create_info.arrayLayers = 1; |
| 12450 | image_create_info.samples = VK_SAMPLE_COUNT_2_BIT; |
| 12451 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12452 | // Note: Some implementations expect color attachment usage for any |
| 12453 | // multisample surface |
| 12454 | image_create_info.usage = |
| 12455 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12456 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12457 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12458 | err = |
| 12459 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12460 | ASSERT_VK_SUCCESS(err); |
| 12461 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12462 | image_create_info.imageType = VK_IMAGE_TYPE_1D; |
| 12463 | // Note: Some implementations expect color attachment usage for any |
| 12464 | // multisample surface |
| 12465 | image_create_info.usage = |
| 12466 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12467 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12468 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12469 | err = |
| 12470 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12471 | ASSERT_VK_SUCCESS(err); |
| 12472 | |
| 12473 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12474 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12475 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12476 | memAlloc.pNext = NULL; |
| 12477 | memAlloc.allocationSize = 0; |
| 12478 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12479 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12480 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12481 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12482 | pass = |
| 12483 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12484 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12485 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12486 | ASSERT_VK_SUCCESS(err); |
| 12487 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12488 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12489 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12490 | pass = |
| 12491 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12492 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12493 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12494 | ASSERT_VK_SUCCESS(err); |
| 12495 | |
| 12496 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12497 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12498 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12499 | ASSERT_VK_SUCCESS(err); |
| 12500 | |
| 12501 | BeginCommandBuffer(); |
| 12502 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12503 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12504 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12505 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12506 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12507 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12508 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12509 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12510 | resolveRegion.srcOffset.x = 0; |
| 12511 | resolveRegion.srcOffset.y = 0; |
| 12512 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12513 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12514 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12515 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12516 | resolveRegion.dstSubresource.layerCount = 0; |
| 12517 | resolveRegion.dstOffset.x = 0; |
| 12518 | resolveRegion.dstOffset.y = 0; |
| 12519 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12520 | resolveRegion.extent.width = 1; |
| 12521 | resolveRegion.extent.height = 1; |
| 12522 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12523 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12524 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12525 | EndCommandBuffer(); |
| 12526 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12527 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12528 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12529 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12530 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12531 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12532 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12533 | } |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12534 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12535 | TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) { |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12536 | // 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] | 12537 | // to using a DS format, then cause it to hit error due to COLOR_BIT not |
| 12538 | // set in aspect |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12539 | // The image format check comes 2nd in validation so we trigger it first, |
| 12540 | // 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] | 12541 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12542 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12543 | m_errorMonitor->SetDesiredFailureMsg( |
| 12544 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12545 | "Combination depth/stencil image formats can have only the "); |
| 12546 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12547 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12548 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 12549 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12550 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 12551 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12552 | |
| 12553 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12554 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 12555 | ds_pool_ci.pNext = NULL; |
| 12556 | ds_pool_ci.maxSets = 1; |
| 12557 | ds_pool_ci.poolSizeCount = 1; |
| 12558 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12559 | |
| 12560 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12561 | err = |
| 12562 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12563 | ASSERT_VK_SUCCESS(err); |
| 12564 | |
| 12565 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12566 | dsl_binding.binding = 0; |
| 12567 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 12568 | dsl_binding.descriptorCount = 1; |
| 12569 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 12570 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12571 | |
| 12572 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12573 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 12574 | ds_layout_ci.pNext = NULL; |
| 12575 | ds_layout_ci.bindingCount = 1; |
| 12576 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12577 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12578 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 12579 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12580 | ASSERT_VK_SUCCESS(err); |
| 12581 | |
| 12582 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12583 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 12584 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 12585 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12586 | alloc_info.descriptorPool = ds_pool; |
| 12587 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12588 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 12589 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12590 | ASSERT_VK_SUCCESS(err); |
| 12591 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12592 | VkImage image_bad; |
| 12593 | VkImage image_good; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12594 | // One bad format and one good format for Color attachment |
Tobin Ehlis | 269f032 | 2016-05-25 16:24:21 -0600 | [diff] [blame] | 12595 | const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12596 | const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12597 | const int32_t tex_width = 32; |
| 12598 | const int32_t tex_height = 32; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12599 | |
| 12600 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12601 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12602 | image_create_info.pNext = NULL; |
| 12603 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12604 | image_create_info.format = tex_format_bad; |
| 12605 | image_create_info.extent.width = tex_width; |
| 12606 | image_create_info.extent.height = tex_height; |
| 12607 | image_create_info.extent.depth = 1; |
| 12608 | image_create_info.mipLevels = 1; |
| 12609 | image_create_info.arrayLayers = 1; |
| 12610 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12611 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12612 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | |
| 12613 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 12614 | image_create_info.flags = 0; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12615 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12616 | err = |
| 12617 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12618 | ASSERT_VK_SUCCESS(err); |
| 12619 | image_create_info.format = tex_format_good; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12620 | image_create_info.usage = |
| 12621 | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12622 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, |
| 12623 | &image_good); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12624 | ASSERT_VK_SUCCESS(err); |
| 12625 | |
| 12626 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12627 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12628 | image_view_create_info.image = image_bad; |
| 12629 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 12630 | image_view_create_info.format = tex_format_bad; |
| 12631 | image_view_create_info.subresourceRange.baseArrayLayer = 0; |
| 12632 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 12633 | image_view_create_info.subresourceRange.layerCount = 1; |
| 12634 | image_view_create_info.subresourceRange.levelCount = 1; |
| 12635 | image_view_create_info.subresourceRange.aspectMask = |
| 12636 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12637 | |
| 12638 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12639 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 12640 | &view); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12641 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12642 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12643 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12644 | vkDestroyImage(m_device->device(), image_bad, NULL); |
| 12645 | vkDestroyImage(m_device->device(), image_good, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12646 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 12647 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12648 | } |
Tobin Ehlis | 6e23d77 | 2016-05-19 11:08:34 -0600 | [diff] [blame] | 12649 | |
| 12650 | TEST_F(VkLayerTest, ClearImageErrors) { |
| 12651 | TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and " |
| 12652 | "ClearDepthStencilImage with a color image."); |
| 12653 | |
| 12654 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12655 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 12656 | |
| 12657 | // Renderpass is started here so end it as Clear cmds can't be in renderpass |
| 12658 | BeginCommandBuffer(); |
| 12659 | m_commandBuffer->EndRenderPass(); |
| 12660 | |
| 12661 | // Color image |
| 12662 | VkClearColorValue clear_color; |
| 12663 | memset(clear_color.uint32, 0, sizeof(uint32_t) * 4); |
| 12664 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 12665 | const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12666 | const int32_t img_width = 32; |
| 12667 | const int32_t img_height = 32; |
| 12668 | VkImageCreateInfo image_create_info = {}; |
| 12669 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12670 | image_create_info.pNext = NULL; |
| 12671 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12672 | image_create_info.format = color_format; |
| 12673 | image_create_info.extent.width = img_width; |
| 12674 | image_create_info.extent.height = img_height; |
| 12675 | image_create_info.extent.depth = 1; |
| 12676 | image_create_info.mipLevels = 1; |
| 12677 | image_create_info.arrayLayers = 1; |
| 12678 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12679 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12680 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 12681 | |
| 12682 | vk_testing::Image color_image; |
| 12683 | color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 12684 | reqs); |
| 12685 | |
| 12686 | const VkImageSubresourceRange color_range = |
| 12687 | vk_testing::Image::subresource_range(image_create_info, |
| 12688 | VK_IMAGE_ASPECT_COLOR_BIT); |
| 12689 | |
| 12690 | // Depth/Stencil image |
| 12691 | VkClearDepthStencilValue clear_value = {0}; |
| 12692 | reqs = 0; // don't need HOST_VISIBLE DS image |
| 12693 | VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info(); |
| 12694 | ds_image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12695 | ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 12696 | ds_image_create_info.extent.width = 64; |
| 12697 | ds_image_create_info.extent.height = 64; |
| 12698 | ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12699 | ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 12700 | |
| 12701 | vk_testing::Image ds_image; |
| 12702 | ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, |
| 12703 | reqs); |
| 12704 | |
| 12705 | const VkImageSubresourceRange ds_range = |
| 12706 | vk_testing::Image::subresource_range(ds_image_create_info, |
| 12707 | VK_IMAGE_ASPECT_DEPTH_BIT); |
| 12708 | |
| 12709 | m_errorMonitor->SetDesiredFailureMsg( |
| 12710 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12711 | "vkCmdClearColorImage called with depth/stencil image."); |
| 12712 | |
| 12713 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), |
| 12714 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, |
| 12715 | &color_range); |
| 12716 | |
| 12717 | m_errorMonitor->VerifyFound(); |
| 12718 | |
Tony Barbour | 26434b9 | 2016-06-02 09:43:50 -0600 | [diff] [blame] | 12719 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12720 | "vkCmdClearColorImage called with " |
| 12721 | "image created without " |
| 12722 | "VK_IMAGE_USAGE_TRANSFER_DST_BIT"); |
| 12723 | |
| 12724 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), |
| 12725 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, |
| 12726 | &color_range); |
| 12727 | |
| 12728 | m_errorMonitor->VerifyFound(); |
| 12729 | |
Tobin Ehlis | 6e23d77 | 2016-05-19 11:08:34 -0600 | [diff] [blame] | 12730 | // Call CmdClearDepthStencilImage with color image |
| 12731 | m_errorMonitor->SetDesiredFailureMsg( |
| 12732 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12733 | "vkCmdClearDepthStencilImage called without a depth/stencil image."); |
| 12734 | |
| 12735 | vkCmdClearDepthStencilImage( |
| 12736 | m_commandBuffer->GetBufferHandle(), color_image.handle(), |
| 12737 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, |
| 12738 | &ds_range); |
| 12739 | |
| 12740 | m_errorMonitor->VerifyFound(); |
| 12741 | } |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12742 | #endif // IMAGE_TESTS |
| 12743 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 12744 | int main(int argc, char **argv) { |
| 12745 | int result; |
| 12746 | |
Cody Northrop | 8e54a40 | 2016-03-08 22:25:52 -0700 | [diff] [blame] | 12747 | #ifdef ANDROID |
| 12748 | int vulkanSupport = InitVulkan(); |
| 12749 | if (vulkanSupport == 0) |
| 12750 | return 1; |
| 12751 | #endif |
| 12752 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 12753 | ::testing::InitGoogleTest(&argc, argv); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 12754 | VkTestFramework::InitArgs(&argc, argv); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 12755 | |
| 12756 | ::testing::AddGlobalTestEnvironment(new TestEnvironment); |
| 12757 | |
| 12758 | result = RUN_ALL_TESTS(); |
| 12759 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 12760 | VkTestFramework::Finish(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 12761 | return result; |
| 12762 | } |