Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015-2016 The Khronos Group Inc. |
| 3 | * Copyright (c) 2015-2016 Valve Corporation |
| 4 | * Copyright (c) 2015-2016 LunarG, Inc. |
Michael Lentine | 0a369f6 | 2016-02-03 16:51:46 -0600 | [diff] [blame] | 5 | * Copyright (c) 2015-2016 Google, Inc. |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12 | * |
| 13 | * Author: Chia-I Wu <olvaffe@gmail.com> |
| 14 | * Author: Chris Forbes <chrisf@ijw.co.nz> |
| 15 | * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
| 16 | * Author: Mark Lobodzinski <mark@lunarg.com> |
| 17 | * Author: Mike Stroyan <mike@LunarG.com> |
| 18 | * Author: Tobin Ehlis <tobine@google.com> |
| 19 | * Author: Tony Barbour <tony@LunarG.com> |
| 20 | */ |
Tony Barbour | 65c48b3 | 2015-11-17 10:02:56 -0700 | [diff] [blame] | 21 | |
Cody Northrop | 8e54a40 | 2016-03-08 22:25:52 -0700 | [diff] [blame] | 22 | #ifdef ANDROID |
| 23 | #include "vulkan_wrapper.h" |
| 24 | #else |
David Pinedo | 9316d3b | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 25 | #include <vulkan/vulkan.h> |
Cody Northrop | 8e54a40 | 2016-03-08 22:25:52 -0700 | [diff] [blame] | 26 | #endif |
Courtney Goeltzenleuchter | 58f3eff | 2015-10-07 13:28:58 -0600 | [diff] [blame] | 27 | #include "test_common.h" |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 28 | #include "vkrenderframework.h" |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 29 | #include "vk_layer_config.h" |
Jon Ashburn | 7fa7e22 | 2016-02-02 12:08:10 -0700 | [diff] [blame] | 30 | #include "icd-spv.h" |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 31 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 32 | #define GLM_FORCE_RADIANS |
| 33 | #include "glm/glm.hpp" |
| 34 | #include <glm/gtc/matrix_transform.hpp> |
| 35 | |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 36 | #define PARAMETER_VALIDATION_TESTS 1 |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 37 | #define MEM_TRACKER_TESTS 1 |
| 38 | #define OBJ_TRACKER_TESTS 1 |
| 39 | #define DRAW_STATE_TESTS 1 |
| 40 | #define THREADING_TESTS 1 |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 41 | #define SHADER_CHECKER_TESTS 1 |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 42 | #define DEVICE_LIMITS_TESTS 1 |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 43 | #define IMAGE_TESTS 1 |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 44 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 45 | //-------------------------------------------------------------------------------------- |
| 46 | // Mesh and VertexFormat Data |
| 47 | //-------------------------------------------------------------------------------------- |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 48 | struct Vertex { |
| 49 | float posX, posY, posZ, posW; // Position data |
| 50 | float r, g, b, a; // Color |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 51 | }; |
| 52 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 53 | #define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 54 | |
| 55 | typedef enum _BsoFailSelect { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 56 | BsoFailNone = 0x00000000, |
| 57 | BsoFailLineWidth = 0x00000001, |
| 58 | BsoFailDepthBias = 0x00000002, |
| 59 | BsoFailViewport = 0x00000004, |
| 60 | BsoFailScissor = 0x00000008, |
| 61 | BsoFailBlend = 0x00000010, |
| 62 | BsoFailDepthBounds = 0x00000020, |
| 63 | BsoFailStencilReadMask = 0x00000040, |
| 64 | BsoFailStencilWriteMask = 0x00000080, |
| 65 | BsoFailStencilReference = 0x00000100, |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 66 | BsoFailCmdClearAttachments = 0x00000200, |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 67 | } BsoFailSelect; |
| 68 | |
| 69 | struct vktriangle_vs_uniform { |
| 70 | // Must start with MVP |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 71 | float mvp[4][4]; |
| 72 | float position[3][4]; |
| 73 | float color[3][4]; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 74 | }; |
| 75 | |
Mark Lobodzinski | 75a97e6 | 2015-06-02 09:41:30 -0500 | [diff] [blame] | 76 | static const char bindStateVertShaderText[] = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 77 | "#version 450\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 78 | "vec2 vertices[3];\n" |
| 79 | "out gl_PerVertex {\n" |
| 80 | " vec4 gl_Position;\n" |
| 81 | "};\n" |
| 82 | "void main() {\n" |
| 83 | " vertices[0] = vec2(-1.0, -1.0);\n" |
| 84 | " vertices[1] = vec2( 1.0, -1.0);\n" |
| 85 | " vertices[2] = vec2( 0.0, 1.0);\n" |
| 86 | " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n" |
| 87 | "}\n"; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 88 | |
Mark Lobodzinski | 75a97e6 | 2015-06-02 09:41:30 -0500 | [diff] [blame] | 89 | static const char bindStateFragShaderText[] = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 90 | "#version 450\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 91 | "\n" |
| 92 | "layout(location = 0) out vec4 uFragColor;\n" |
| 93 | "void main(){\n" |
| 94 | " uFragColor = vec4(0,1,0,1);\n" |
| 95 | "}\n"; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 96 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 97 | static VKAPI_ATTR VkBool32 VKAPI_CALL |
| 98 | myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, |
| 99 | uint64_t srcObject, size_t location, int32_t msgCode, |
| 100 | const char *pLayerPrefix, const char *pMsg, void *pUserData); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 101 | |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 102 | // ******************************************************** |
| 103 | // ErrorMonitor Usage: |
| 104 | // |
| 105 | // Call SetDesiredFailureMsg with a string to be compared against all |
| 106 | // encountered log messages. Passing NULL will match all log messages. |
| 107 | // logMsg will return true for skipCall only if msg is matched or NULL. |
| 108 | // |
| 109 | // Call DesiredMsgFound to determine if the desired failure message |
| 110 | // was encountered. |
| 111 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 112 | class ErrorMonitor { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 113 | public: |
| 114 | ErrorMonitor() { |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 115 | test_platform_thread_create_mutex(&m_mutex); |
| 116 | test_platform_thread_lock_mutex(&m_mutex); |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 117 | m_msgFlags = VK_DEBUG_REPORT_INFORMATION_BIT_EXT; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 118 | m_bailout = NULL; |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 119 | test_platform_thread_unlock_mutex(&m_mutex); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 120 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 121 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 122 | ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); } |
| 123 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 124 | void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 125 | // also discard all collected messages to this point |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 126 | test_platform_thread_lock_mutex(&m_mutex); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 127 | m_failureMsg.clear(); |
| 128 | m_otherMsgs.clear(); |
| 129 | m_desiredMsg = msgString; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 130 | m_msgFound = VK_FALSE; |
| 131 | m_msgFlags = msgFlags; |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 132 | test_platform_thread_unlock_mutex(&m_mutex); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 133 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 134 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 135 | VkBool32 CheckForDesiredMsg(VkFlags msgFlags, const char *msgString) { |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 136 | VkBool32 result = VK_FALSE; |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 137 | test_platform_thread_lock_mutex(&m_mutex); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 138 | if (m_bailout != NULL) { |
| 139 | *m_bailout = true; |
| 140 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 141 | string errorString(msgString); |
| 142 | if (msgFlags & m_msgFlags) { |
| 143 | if (errorString.find(m_desiredMsg) != string::npos) { |
Chris Forbes | c7b8ad7 | 2016-04-04 18:50:38 +1200 | [diff] [blame] | 144 | if (m_msgFound) { /* if multiple matches, don't lose all but the last! */ |
| 145 | m_otherMsgs.push_back(m_failureMsg); |
| 146 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 147 | m_failureMsg = errorString; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 148 | m_msgFound = VK_TRUE; |
| 149 | result = VK_TRUE; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 150 | } else { |
| 151 | m_otherMsgs.push_back(errorString); |
| 152 | } |
| 153 | } |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 154 | test_platform_thread_unlock_mutex(&m_mutex); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 155 | return result; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 156 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 157 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 158 | vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 159 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 160 | string GetFailureMsg(void) { return m_failureMsg; } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 161 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 162 | VkBool32 DesiredMsgFound(void) { return m_msgFound; } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 163 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 164 | void SetBailout(bool *bailout) { m_bailout = bailout; } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 165 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 166 | void DumpFailureMsgs(void) { |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 167 | vector<string> otherMsgs = GetOtherFailureMsgs(); |
| 168 | cout << "Other error messages logged for this test were:" << endl; |
| 169 | for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) { |
| 170 | cout << " " << *iter << endl; |
| 171 | } |
| 172 | } |
| 173 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 174 | /* helpers */ |
| 175 | |
| 176 | void ExpectSuccess() { |
| 177 | // match anything |
| 178 | SetDesiredFailureMsg(~0u, ""); |
| 179 | } |
| 180 | |
| 181 | void VerifyFound() { |
| 182 | // Not seeing the desired message is a failure. /Before/ throwing, dump |
| 183 | // any other messages. |
| 184 | if (!DesiredMsgFound()) { |
| 185 | DumpFailureMsgs(); |
| 186 | FAIL() << "Did not receive expected error '" << m_desiredMsg << "'"; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | void VerifyNotFound() { |
| 191 | // ExpectSuccess() configured us to match anything. Any error is a |
| 192 | // failure. |
| 193 | if (DesiredMsgFound()) { |
| 194 | DumpFailureMsgs(); |
| 195 | FAIL() << "Expected to succeed but got error: " << GetFailureMsg(); |
| 196 | } |
| 197 | } |
| 198 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 199 | private: |
| 200 | VkFlags m_msgFlags; |
| 201 | string m_desiredMsg; |
| 202 | string m_failureMsg; |
| 203 | vector<string> m_otherMsgs; |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 204 | test_platform_thread_mutex m_mutex; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 205 | bool *m_bailout; |
| 206 | VkBool32 m_msgFound; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 207 | }; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 208 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 209 | static VKAPI_ATTR VkBool32 VKAPI_CALL |
| 210 | myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, |
| 211 | uint64_t srcObject, size_t location, int32_t msgCode, |
| 212 | const char *pLayerPrefix, const char *pMsg, void *pUserData) { |
| 213 | if (msgFlags & |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 214 | (VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 215 | VK_DEBUG_REPORT_ERROR_BIT_EXT)) { |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 216 | ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 217 | return errMonitor->CheckForDesiredMsg(msgFlags, pMsg); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 218 | } |
Courtney Goeltzenleuchter | 0664083 | 2015-09-04 13:52:24 -0600 | [diff] [blame] | 219 | return false; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 220 | } |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 221 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 222 | class VkLayerTest : public VkRenderFramework { |
| 223 | public: |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 224 | VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer); |
| 225 | VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 226 | void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, |
| 227 | BsoFailSelect failMask); |
| 228 | void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, |
| 229 | VkPipelineObj &pipelineobj, |
| 230 | VkDescriptorSetObj &descriptorSet, |
| 231 | BsoFailSelect failMask); |
| 232 | void GenericDrawPreparation(VkPipelineObj &pipelineobj, |
| 233 | VkDescriptorSetObj &descriptorSet, |
| 234 | BsoFailSelect failMask) { |
| 235 | GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, |
| 236 | failMask); |
| 237 | } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 238 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 239 | /* Convenience functions that use built-in command buffer */ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 240 | VkResult BeginCommandBuffer() { |
| 241 | return BeginCommandBuffer(*m_commandBuffer); |
| 242 | } |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 243 | VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 244 | void Draw(uint32_t vertexCount, uint32_t instanceCount, |
| 245 | uint32_t firstVertex, uint32_t firstInstance) { |
| 246 | m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, |
| 247 | firstInstance); |
| 248 | } |
| 249 | void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, |
| 250 | uint32_t firstIndex, int32_t vertexOffset, |
| 251 | uint32_t firstInstance) { |
| 252 | m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, |
| 253 | vertexOffset, firstInstance); |
| 254 | } |
Mark Lobodzinski | cf0ae75 | 2016-06-23 10:02:24 -0600 | [diff] [blame] | 255 | void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 256 | void QueueCommandBuffer(const VkFence &fence) { |
| 257 | m_commandBuffer->QueueCommandBuffer(fence); |
| 258 | } |
| 259 | void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, |
| 260 | VkDeviceSize offset, uint32_t binding) { |
| 261 | m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding); |
| 262 | } |
| 263 | void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) { |
| 264 | m_commandBuffer->BindIndexBuffer(indexBuffer, offset); |
| 265 | } |
| 266 | |
| 267 | protected: |
| 268 | ErrorMonitor *m_errorMonitor; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 269 | bool m_enableWSI; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 270 | |
| 271 | virtual void SetUp() { |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 272 | std::vector<const char *> instance_layer_names; |
| 273 | std::vector<const char *> device_layer_names; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 274 | std::vector<const char *> instance_extension_names; |
| 275 | std::vector<const char *> device_extension_names; |
Tony Barbour | 3fdff9e | 2015-04-23 12:55:36 -0600 | [diff] [blame] | 276 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 277 | instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); |
Courtney Goeltzenleuchter | c2b06fe | 2015-06-16 15:59:11 -0600 | [diff] [blame] | 278 | /* |
| 279 | * Since CreateDbgMsgCallback is an instance level extension call |
| 280 | * any extension / layer that utilizes that feature also needs |
| 281 | * to be enabled at create instance time. |
| 282 | */ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 283 | // Use Threading layer first to protect others from |
| 284 | // ThreadCommandBufferCollision test |
Courtney Goeltzenleuchter | 7688532 | 2016-02-06 17:11:22 -0700 | [diff] [blame] | 285 | instance_layer_names.push_back("VK_LAYER_GOOGLE_threading"); |
Tobin Ehlis | 24aab04 | 2016-03-24 10:54:18 -0600 | [diff] [blame] | 286 | instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation"); |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 287 | instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker"); |
Tobin Ehlis | c96f806 | 2016-03-09 16:12:48 -0700 | [diff] [blame] | 288 | instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation"); |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 289 | instance_layer_names.push_back("VK_LAYER_LUNARG_device_limits"); |
| 290 | instance_layer_names.push_back("VK_LAYER_LUNARG_image"); |
Ian Elliott | e48a138 | 2016-04-28 14:22:58 -0600 | [diff] [blame] | 291 | instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain"); |
Dustin Graves | eaa78cd | 2016-01-26 16:30:22 -0700 | [diff] [blame] | 292 | instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects"); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 293 | |
Courtney Goeltzenleuchter | 7688532 | 2016-02-06 17:11:22 -0700 | [diff] [blame] | 294 | device_layer_names.push_back("VK_LAYER_GOOGLE_threading"); |
Tobin Ehlis | 24aab04 | 2016-03-24 10:54:18 -0600 | [diff] [blame] | 295 | device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation"); |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 296 | device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker"); |
Tobin Ehlis | c96f806 | 2016-03-09 16:12:48 -0700 | [diff] [blame] | 297 | device_layer_names.push_back("VK_LAYER_LUNARG_core_validation"); |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 298 | device_layer_names.push_back("VK_LAYER_LUNARG_device_limits"); |
| 299 | device_layer_names.push_back("VK_LAYER_LUNARG_image"); |
Ian Elliott | e48a138 | 2016-04-28 14:22:58 -0600 | [diff] [blame] | 300 | device_layer_names.push_back("VK_LAYER_LUNARG_swapchain"); |
Dustin Graves | eaa78cd | 2016-01-26 16:30:22 -0700 | [diff] [blame] | 301 | device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects"); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 302 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 303 | if (m_enableWSI) { |
| 304 | instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME); |
| 305 | device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME); |
| 306 | #ifdef NEED_TO_TEST_THIS_ON_PLATFORM |
| 307 | #if defined(VK_USE_PLATFORM_ANDROID_KHR) |
| 308 | instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME); |
| 309 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 310 | #if defined(VK_USE_PLATFORM_MIR_KHR) |
| 311 | instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME); |
| 312 | #endif // VK_USE_PLATFORM_MIR_KHR |
| 313 | #if defined(VK_USE_PLATFORM_WAYLAND_KHR) |
| 314 | instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME); |
| 315 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
| 316 | #if defined(VK_USE_PLATFORM_WIN32_KHR) |
| 317 | instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); |
| 318 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 319 | #endif // NEED_TO_TEST_THIS_ON_PLATFORM |
| 320 | #if defined(VK_USE_PLATFORM_XCB_KHR) |
| 321 | instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME); |
| 322 | #elif defined(VK_USE_PLATFORM_XLIB_KHR) |
| 323 | instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME); |
| 324 | #endif // VK_USE_PLATFORM_XLIB_KHR |
| 325 | } |
| 326 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 327 | this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 328 | this->app_info.pNext = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 329 | this->app_info.pApplicationName = "layer_tests"; |
| 330 | this->app_info.applicationVersion = 1; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 331 | this->app_info.pEngineName = "unittest"; |
| 332 | this->app_info.engineVersion = 1; |
Jon Ashburn | c5012ff | 2016-03-22 13:57:46 -0600 | [diff] [blame] | 333 | this->app_info.apiVersion = VK_API_VERSION_1_0; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 334 | |
Tony Barbour | 15524c3 | 2015-04-29 17:34:29 -0600 | [diff] [blame] | 335 | m_errorMonitor = new ErrorMonitor; |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 336 | InitFramework(instance_layer_names, device_layer_names, |
| 337 | instance_extension_names, device_extension_names, |
| 338 | myDbgFunc, m_errorMonitor); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | virtual void TearDown() { |
| 342 | // Clean up resources before we reset |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 343 | ShutdownFramework(); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 344 | delete m_errorMonitor; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 345 | } |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 346 | |
| 347 | VkLayerTest() { |
| 348 | m_enableWSI = false; |
| 349 | } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 350 | }; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 351 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 352 | VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 353 | VkResult result; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 354 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 355 | result = commandBuffer.BeginCommandBuffer(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 356 | |
| 357 | /* |
| 358 | * For render test all drawing happens in a single render pass |
| 359 | * on a single command buffer. |
| 360 | */ |
Chris Forbes | 76a5eeb | 2015-06-16 14:05:59 +1200 | [diff] [blame] | 361 | if (VK_SUCCESS == result && renderPass()) { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 362 | commandBuffer.BeginRenderPass(renderPassBeginInfo()); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | return result; |
| 366 | } |
| 367 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 368 | VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 369 | VkResult result; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 370 | |
Chris Forbes | 76a5eeb | 2015-06-16 14:05:59 +1200 | [diff] [blame] | 371 | if (renderPass()) { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 372 | commandBuffer.EndRenderPass(); |
Chris Forbes | 76a5eeb | 2015-06-16 14:05:59 +1200 | [diff] [blame] | 373 | } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 374 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 375 | result = commandBuffer.EndCommandBuffer(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 376 | |
| 377 | return result; |
| 378 | } |
| 379 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 380 | void VkLayerTest::VKTriangleTest(const char *vertShaderText, |
| 381 | const char *fragShaderText, |
| 382 | BsoFailSelect failMask) { |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 383 | // Create identity matrix |
| 384 | int i; |
| 385 | struct vktriangle_vs_uniform data; |
| 386 | |
| 387 | glm::mat4 Projection = glm::mat4(1.0f); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 388 | glm::mat4 View = glm::mat4(1.0f); |
| 389 | glm::mat4 Model = glm::mat4(1.0f); |
| 390 | glm::mat4 MVP = Projection * View * Model; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 391 | const int matrixSize = sizeof(MVP); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 392 | const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 393 | |
| 394 | memcpy(&data.mvp, &MVP[0][0], matrixSize); |
| 395 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 396 | static const Vertex tri_data[] = { |
| 397 | {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, |
| 398 | {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, |
| 399 | {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)}, |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 400 | }; |
| 401 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 402 | for (i = 0; i < 3; i++) { |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 403 | data.position[i][0] = tri_data[i].posX; |
| 404 | data.position[i][1] = tri_data[i].posY; |
| 405 | data.position[i][2] = tri_data[i].posZ; |
| 406 | data.position[i][3] = tri_data[i].posW; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 407 | data.color[i][0] = tri_data[i].r; |
| 408 | data.color[i][1] = tri_data[i].g; |
| 409 | data.color[i][2] = tri_data[i].b; |
| 410 | data.color[i][3] = tri_data[i].a; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 414 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 415 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 416 | VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), |
| 417 | (const void *)&data); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 418 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 419 | VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 420 | VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, |
| 421 | this); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 422 | |
| 423 | VkPipelineObj pipelineobj(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 424 | pipelineobj.AddColorAttachment(); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 425 | pipelineobj.AddShader(&vs); |
| 426 | pipelineobj.AddShader(&ps); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 427 | if (failMask & BsoFailLineWidth) { |
| 428 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH); |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 429 | VkPipelineInputAssemblyStateCreateInfo ia_state = {}; |
| 430 | ia_state.sType = |
| 431 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 432 | ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST; |
| 433 | pipelineobj.SetInputAssembly(&ia_state); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 434 | } |
| 435 | if (failMask & BsoFailDepthBias) { |
| 436 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS); |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 437 | VkPipelineRasterizationStateCreateInfo rs_state = {}; |
| 438 | rs_state.sType = |
| 439 | VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 440 | rs_state.depthBiasEnable = VK_TRUE; |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 441 | rs_state.lineWidth = 1.0f; |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 442 | pipelineobj.SetRasterization(&rs_state); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 443 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 444 | // Viewport and scissors must stay in synch or other errors will occur than |
| 445 | // the ones we want |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 446 | if (failMask & BsoFailViewport) { |
| 447 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 448 | m_viewports.clear(); |
| 449 | m_scissors.clear(); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 450 | } |
| 451 | if (failMask & BsoFailScissor) { |
| 452 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 453 | m_scissors.clear(); |
| 454 | m_viewports.clear(); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 455 | } |
| 456 | if (failMask & BsoFailBlend) { |
| 457 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS); |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 458 | VkPipelineColorBlendAttachmentState att_state = {}; |
| 459 | att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR; |
| 460 | att_state.blendEnable = VK_TRUE; |
| 461 | pipelineobj.AddColorAttachment(0, &att_state); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 462 | } |
| 463 | if (failMask & BsoFailDepthBounds) { |
| 464 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS); |
| 465 | } |
| 466 | if (failMask & BsoFailStencilReadMask) { |
| 467 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK); |
| 468 | } |
| 469 | if (failMask & BsoFailStencilWriteMask) { |
| 470 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK); |
| 471 | } |
| 472 | if (failMask & BsoFailStencilReference) { |
| 473 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE); |
| 474 | } |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 475 | |
| 476 | VkDescriptorSetObj descriptorSet(m_device); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 477 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, |
| 478 | constantBuffer); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 479 | |
| 480 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 481 | ASSERT_VK_SUCCESS(BeginCommandBuffer()); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 482 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 483 | GenericDrawPreparation(pipelineobj, descriptorSet, failMask); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 484 | |
| 485 | // render triangle |
Courtney Goeltzenleuchter | 08c2637 | 2015-09-23 12:31:50 -0600 | [diff] [blame] | 486 | Draw(3, 1, 0, 0); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 487 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 488 | if (failMask & BsoFailCmdClearAttachments) { |
| 489 | VkClearAttachment color_attachment = {}; |
| 490 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 491 | color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index; |
| 492 | VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0}; |
| 493 | |
| 494 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 495 | &color_attachment, 1, &clear_rect); |
| 496 | } |
| 497 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 498 | // finalize recording of the command buffer |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 499 | EndCommandBuffer(); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 500 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 501 | QueueCommandBuffer(); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 502 | } |
| 503 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 504 | void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, |
| 505 | VkPipelineObj &pipelineobj, |
| 506 | VkDescriptorSetObj &descriptorSet, |
| 507 | BsoFailSelect failMask) { |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 508 | if (m_depthStencil->Initialized()) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 509 | commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 510 | m_stencil_clear_color, m_depthStencil); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 511 | } else { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 512 | commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 513 | m_stencil_clear_color, NULL); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 514 | } |
| 515 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 516 | commandBuffer->PrepareAttachments(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 517 | // Make sure depthWriteEnable is set so that Depth fail test will work |
| 518 | // correctly |
| 519 | // Make sure stencilTestEnable is set so that Stencil fail test will work |
| 520 | // correctly |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 521 | VkStencilOpState stencil = {}; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 522 | stencil.failOp = VK_STENCIL_OP_KEEP; |
| 523 | stencil.passOp = VK_STENCIL_OP_KEEP; |
| 524 | stencil.depthFailOp = VK_STENCIL_OP_KEEP; |
| 525 | stencil.compareOp = VK_COMPARE_OP_NEVER; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 526 | |
| 527 | VkPipelineDepthStencilStateCreateInfo ds_ci = {}; |
| 528 | ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 529 | ds_ci.pNext = NULL; |
| 530 | ds_ci.depthTestEnable = VK_FALSE; |
| 531 | ds_ci.depthWriteEnable = VK_TRUE; |
| 532 | ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER; |
| 533 | ds_ci.depthBoundsTestEnable = VK_FALSE; |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 534 | if (failMask & BsoFailDepthBounds) { |
| 535 | ds_ci.depthBoundsTestEnable = VK_TRUE; |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 536 | ds_ci.maxDepthBounds = 0.0f; |
| 537 | ds_ci.minDepthBounds = 0.0f; |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 538 | } |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 539 | ds_ci.stencilTestEnable = VK_TRUE; |
| 540 | ds_ci.front = stencil; |
| 541 | ds_ci.back = stencil; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 542 | |
Tobin Ehlis | 4bf96d1 | 2015-06-25 11:58:41 -0600 | [diff] [blame] | 543 | pipelineobj.SetDepthStencil(&ds_ci); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 544 | pipelineobj.SetViewport(m_viewports); |
| 545 | pipelineobj.SetScissor(m_scissors); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 546 | descriptorSet.CreateVKDescriptorSet(commandBuffer); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 547 | VkResult err = pipelineobj.CreateVKPipeline( |
| 548 | descriptorSet.GetPipelineLayout(), renderPass()); |
Cody Northrop | 29a08f2 | 2015-08-27 10:20:35 -0600 | [diff] [blame] | 549 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 550 | commandBuffer->BindPipeline(pipelineobj); |
| 551 | commandBuffer->BindDescriptorSet(descriptorSet); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 552 | } |
| 553 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 554 | class VkWsiEnabledLayerTest : public VkLayerTest { |
| 555 | public: |
| 556 | protected: |
| 557 | VkWsiEnabledLayerTest() { |
| 558 | m_enableWSI = true; |
| 559 | } |
| 560 | }; |
| 561 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 562 | // ******************************************************************************************************************** |
| 563 | // ******************************************************************************************************************** |
| 564 | // ******************************************************************************************************************** |
| 565 | // ******************************************************************************************************************** |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 566 | #if PARAMETER_VALIDATION_TESTS |
| 567 | TEST_F(VkLayerTest, RequiredParameter) { |
| 568 | TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, " |
| 569 | "pointer, array, and array count parameters"); |
| 570 | |
| 571 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 572 | |
| 573 | m_errorMonitor->SetDesiredFailureMsg( |
| 574 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 575 | "required parameter pFeatures specified as NULL"); |
| 576 | // Specify NULL for a pointer to a handle |
| 577 | // Expected to trigger an error with |
| 578 | // parameter_validation::validate_required_pointer |
| 579 | vkGetPhysicalDeviceFeatures(gpu(), NULL); |
| 580 | m_errorMonitor->VerifyFound(); |
| 581 | |
| 582 | m_errorMonitor->SetDesiredFailureMsg( |
| 583 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Dustin Graves | a4bb8c1 | 2016-05-16 17:22:51 -0600 | [diff] [blame] | 584 | "required parameter pQueueFamilyPropertyCount specified as NULL"); |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 585 | // Specify NULL for pointer to array count |
| 586 | // Expected to trigger an error with parameter_validation::validate_array |
Dustin Graves | a4bb8c1 | 2016-05-16 17:22:51 -0600 | [diff] [blame] | 587 | vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL); |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 588 | m_errorMonitor->VerifyFound(); |
| 589 | |
| 590 | m_errorMonitor->SetDesiredFailureMsg( |
| 591 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 592 | "parameter viewportCount must be greater than 0"); |
| 593 | // Specify 0 for a required array count |
| 594 | // Expected to trigger an error with parameter_validation::validate_array |
| 595 | VkViewport view_port = {}; |
| 596 | m_commandBuffer->SetViewport(0, 0, &view_port); |
| 597 | m_errorMonitor->VerifyFound(); |
| 598 | |
| 599 | m_errorMonitor->SetDesiredFailureMsg( |
| 600 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 601 | "required parameter pViewports specified as NULL"); |
| 602 | // Specify NULL for a required array |
| 603 | // Expected to trigger an error with parameter_validation::validate_array |
| 604 | m_commandBuffer->SetViewport(0, 1, NULL); |
| 605 | m_errorMonitor->VerifyFound(); |
| 606 | |
| 607 | m_errorMonitor->SetDesiredFailureMsg( |
| 608 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 609 | "required parameter memory specified as VK_NULL_HANDLE"); |
| 610 | // Specify VK_NULL_HANDLE for a required handle |
| 611 | // Expected to trigger an error with |
| 612 | // parameter_validation::validate_required_handle |
| 613 | vkUnmapMemory(device(), VK_NULL_HANDLE); |
| 614 | m_errorMonitor->VerifyFound(); |
| 615 | |
| 616 | m_errorMonitor->SetDesiredFailureMsg( |
| 617 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 618 | "required parameter pFences[0] specified as VK_NULL_HANDLE"); |
| 619 | // Specify VK_NULL_HANDLE for a required handle array entry |
| 620 | // Expected to trigger an error with |
| 621 | // parameter_validation::validate_required_handle_array |
| 622 | VkFence fence = VK_NULL_HANDLE; |
| 623 | vkResetFences(device(), 1, &fence); |
| 624 | m_errorMonitor->VerifyFound(); |
| 625 | |
| 626 | m_errorMonitor->SetDesiredFailureMsg( |
| 627 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 628 | "required parameter pAllocateInfo specified as NULL"); |
| 629 | // Specify NULL for a required struct pointer |
| 630 | // Expected to trigger an error with |
| 631 | // parameter_validation::validate_struct_type |
| 632 | VkDeviceMemory memory = VK_NULL_HANDLE; |
| 633 | vkAllocateMemory(device(), NULL, NULL, &memory); |
| 634 | m_errorMonitor->VerifyFound(); |
| 635 | |
| 636 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 637 | "value of faceMask must not be 0"); |
| 638 | // Specify 0 for a required VkFlags parameter |
| 639 | // Expected to trigger an error with parameter_validation::validate_flags |
| 640 | m_commandBuffer->SetStencilReference(0, 0); |
| 641 | m_errorMonitor->VerifyFound(); |
| 642 | |
| 643 | m_errorMonitor->SetDesiredFailureMsg( |
| 644 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 645 | "value of pSubmits[i].pWaitDstStageMask[0] must not be 0"); |
| 646 | // Specify 0 for a required VkFlags array entry |
| 647 | // Expected to trigger an error with |
| 648 | // parameter_validation::validate_flags_array |
| 649 | VkSemaphore semaphore = VK_NULL_HANDLE; |
| 650 | VkPipelineStageFlags stageFlags = 0; |
| 651 | VkSubmitInfo submitInfo = {}; |
| 652 | submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 653 | submitInfo.waitSemaphoreCount = 1; |
| 654 | submitInfo.pWaitSemaphores = &semaphore; |
| 655 | submitInfo.pWaitDstStageMask = &stageFlags; |
| 656 | vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE); |
| 657 | m_errorMonitor->VerifyFound(); |
| 658 | } |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 659 | |
Dustin Graves | fce74c0 | 2016-05-10 11:42:58 -0600 | [diff] [blame] | 660 | TEST_F(VkLayerTest, ReservedParameter) { |
| 661 | TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter"); |
| 662 | |
| 663 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 664 | |
| 665 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 666 | " must be 0"); |
| 667 | // Specify 0 for a reserved VkFlags parameter |
| 668 | // Expected to trigger an error with |
| 669 | // parameter_validation::validate_reserved_flags |
| 670 | VkEvent event_handle = VK_NULL_HANDLE; |
| 671 | VkEventCreateInfo event_info = {}; |
| 672 | event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 673 | event_info.flags = 1; |
| 674 | vkCreateEvent(device(), &event_info, NULL, &event_handle); |
| 675 | m_errorMonitor->VerifyFound(); |
| 676 | } |
| 677 | |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 678 | TEST_F(VkLayerTest, InvalidStructSType) { |
| 679 | TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan " |
| 680 | "structure's sType field"); |
| 681 | |
| 682 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 683 | |
| 684 | m_errorMonitor->SetDesiredFailureMsg( |
| 685 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 686 | "parameter pAllocateInfo->sType must be"); |
| 687 | // Zero struct memory, effectively setting sType to |
| 688 | // VK_STRUCTURE_TYPE_APPLICATION_INFO |
| 689 | // Expected to trigger an error with |
| 690 | // parameter_validation::validate_struct_type |
| 691 | VkMemoryAllocateInfo alloc_info = {}; |
| 692 | VkDeviceMemory memory = VK_NULL_HANDLE; |
| 693 | vkAllocateMemory(device(), &alloc_info, NULL, &memory); |
| 694 | m_errorMonitor->VerifyFound(); |
| 695 | |
| 696 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 697 | "parameter pSubmits[0].sType must be"); |
| 698 | // Zero struct memory, effectively setting sType to |
| 699 | // VK_STRUCTURE_TYPE_APPLICATION_INFO |
| 700 | // Expected to trigger an error with |
| 701 | // parameter_validation::validate_struct_type_array |
| 702 | VkSubmitInfo submit_info = {}; |
| 703 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 704 | m_errorMonitor->VerifyFound(); |
| 705 | } |
| 706 | |
| 707 | TEST_F(VkLayerTest, InvalidStructPNext) { |
| 708 | TEST_DESCRIPTION( |
| 709 | "Specify an invalid value for a Vulkan structure's pNext field"); |
| 710 | |
| 711 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 712 | |
| 713 | m_errorMonitor->SetDesiredFailureMsg( |
| 714 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 715 | "value of pAllocateInfo->pNext must be NULL"); |
| 716 | // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be |
| 717 | // NULL |
| 718 | // Expected to trigger an error with |
| 719 | // parameter_validation::validate_struct_pnext |
| 720 | VkDeviceMemory memory = VK_NULL_HANDLE; |
| 721 | // Zero-initialization will provide the correct sType |
| 722 | VkApplicationInfo app_info = {}; |
Dustin Graves | 47b6cba | 2016-05-10 17:34:38 -0600 | [diff] [blame] | 723 | VkMemoryAllocateInfo memory_alloc_info = {}; |
| 724 | memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 725 | memory_alloc_info.pNext = &app_info; |
| 726 | vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory); |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 727 | m_errorMonitor->VerifyFound(); |
| 728 | |
Dustin Graves | 47b6cba | 2016-05-10 17:34:38 -0600 | [diff] [blame] | 729 | m_errorMonitor->SetDesiredFailureMsg( |
| 730 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 731 | " chain includes a structure with unexpected VkStructureType "); |
| 732 | // Set VkGraphicsPipelineCreateInfo::VkPipelineRasterizationStateCreateInfo::pNext to an invalid structure, when pNext is allowed to be a non-NULL value |
| 733 | // Expected to trigger an error with |
| 734 | // parameter_validation::validate_struct_pnext |
| 735 | VkDescriptorPoolSize ds_type_count = {}; |
| 736 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 737 | ds_type_count.descriptorCount = 1; |
| 738 | |
| 739 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 740 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 741 | ds_pool_ci.pNext = NULL; |
| 742 | ds_pool_ci.maxSets = 1; |
| 743 | ds_pool_ci.poolSizeCount = 1; |
| 744 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 745 | |
| 746 | VkDescriptorPool ds_pool; |
| 747 | VkResult err = |
| 748 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 749 | ASSERT_VK_SUCCESS(err); |
| 750 | |
| 751 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 752 | dsl_binding.binding = 0; |
| 753 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 754 | dsl_binding.descriptorCount = 1; |
| 755 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 756 | dsl_binding.pImmutableSamplers = NULL; |
| 757 | |
| 758 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 759 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 760 | ds_layout_ci.pNext = NULL; |
| 761 | ds_layout_ci.bindingCount = 1; |
| 762 | ds_layout_ci.pBindings = &dsl_binding; |
| 763 | |
| 764 | VkDescriptorSetLayout ds_layout; |
| 765 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 766 | &ds_layout); |
| 767 | ASSERT_VK_SUCCESS(err); |
| 768 | |
| 769 | VkDescriptorSet descriptorSet; |
| 770 | VkDescriptorSetAllocateInfo ds_alloc_info = {}; |
| 771 | ds_alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 772 | ds_alloc_info.descriptorSetCount = 1; |
| 773 | ds_alloc_info.descriptorPool = ds_pool; |
| 774 | ds_alloc_info.pSetLayouts = &ds_layout; |
| 775 | err = vkAllocateDescriptorSets(m_device->device(), &ds_alloc_info, |
| 776 | &descriptorSet); |
| 777 | ASSERT_VK_SUCCESS(err); |
| 778 | |
| 779 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 780 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 781 | pipeline_layout_ci.setLayoutCount = 1; |
| 782 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 783 | |
| 784 | VkPipelineLayout pipeline_layout; |
| 785 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 786 | &pipeline_layout); |
| 787 | ASSERT_VK_SUCCESS(err); |
| 788 | |
| 789 | VkViewport vp = {}; // Just need dummy vp to point to |
| 790 | VkRect2D sc = {}; // dummy scissor to point to |
| 791 | |
| 792 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 793 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 794 | vp_state_ci.scissorCount = 1; |
| 795 | vp_state_ci.pScissors = ≻ |
| 796 | vp_state_ci.viewportCount = 1; |
| 797 | vp_state_ci.pViewports = &vp; |
| 798 | |
| 799 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 800 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 801 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 802 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 803 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 804 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 805 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 806 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 807 | |
| 808 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 809 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 810 | gp_ci.pViewportState = &vp_state_ci; |
| 811 | gp_ci.pRasterizationState = &rs_state_ci; |
| 812 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 813 | gp_ci.layout = pipeline_layout; |
| 814 | gp_ci.renderPass = renderPass(); |
| 815 | |
| 816 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 817 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 818 | pc_ci.initialDataSize = 0; |
| 819 | pc_ci.pInitialData = 0; |
| 820 | |
| 821 | VkPipeline pipeline; |
| 822 | VkPipelineCache pipelineCache; |
| 823 | |
| 824 | err = |
| 825 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 826 | ASSERT_VK_SUCCESS(err); |
| 827 | |
| 828 | // Set VkPipelineRasterizationStateCreateInfo::pNext to an invalid value |
| 829 | VkApplicationInfo invalid_pnext_struct = {}; |
| 830 | rs_state_ci.pNext = &invalid_pnext_struct; |
| 831 | |
| 832 | vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 833 | &gp_ci, NULL, &pipeline); |
| 834 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 835 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 836 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 837 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 838 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 839 | |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 840 | } |
Dustin Graves | 5d33d53 | 2016-05-09 16:21:12 -0600 | [diff] [blame] | 841 | |
| 842 | TEST_F(VkLayerTest, UnrecognizedValue) { |
| 843 | TEST_DESCRIPTION( |
| 844 | "Specify unrecognized Vulkan enumeration, flags, and VkBool32 values"); |
| 845 | |
| 846 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 847 | |
| 848 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 849 | "does not fall within the begin..end " |
| 850 | "range of the core VkFormat " |
| 851 | "enumeration tokens"); |
| 852 | // Specify an invalid VkFormat value |
| 853 | // Expected to trigger an error with |
| 854 | // parameter_validation::validate_ranged_enum |
| 855 | VkFormatProperties format_properties; |
| 856 | vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), |
| 857 | &format_properties); |
| 858 | m_errorMonitor->VerifyFound(); |
| 859 | |
| 860 | m_errorMonitor->SetDesiredFailureMsg( |
| 861 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 862 | "contains flag bits that are not recognized members of"); |
| 863 | // Specify an invalid VkFlags bitmask value |
| 864 | // Expected to trigger an error with parameter_validation::validate_flags |
| 865 | VkImageFormatProperties image_format_properties; |
| 866 | vkGetPhysicalDeviceImageFormatProperties( |
| 867 | gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, |
| 868 | VK_IMAGE_TILING_OPTIMAL, static_cast<VkImageUsageFlags>(1 << 25), 0, |
| 869 | &image_format_properties); |
| 870 | m_errorMonitor->VerifyFound(); |
| 871 | |
| 872 | m_errorMonitor->SetDesiredFailureMsg( |
| 873 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 874 | "contains flag bits that are not recognized members of"); |
| 875 | // Specify an invalid VkFlags array entry |
| 876 | // Expected to trigger an error with |
| 877 | // parameter_validation::validate_flags_array |
| 878 | VkSemaphore semaphore = VK_NULL_HANDLE; |
| 879 | VkPipelineStageFlags stage_flags = |
| 880 | static_cast<VkPipelineStageFlags>(1 << 25); |
| 881 | VkSubmitInfo submit_info = {}; |
| 882 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 883 | submit_info.waitSemaphoreCount = 1; |
| 884 | submit_info.pWaitSemaphores = &semaphore; |
| 885 | submit_info.pWaitDstStageMask = &stage_flags; |
| 886 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 887 | m_errorMonitor->VerifyFound(); |
| 888 | |
| 889 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
| 890 | "is neither VK_TRUE nor VK_FALSE"); |
| 891 | // Specify an invalid VkBool32 value |
| 892 | // Expected to trigger a warning with |
| 893 | // parameter_validation::validate_bool32 |
| 894 | VkSampler sampler = VK_NULL_HANDLE; |
| 895 | VkSamplerCreateInfo sampler_info = {}; |
| 896 | sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 897 | sampler_info.pNext = NULL; |
| 898 | sampler_info.magFilter = VK_FILTER_NEAREST; |
| 899 | sampler_info.minFilter = VK_FILTER_NEAREST; |
| 900 | sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 901 | sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 902 | sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 903 | sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 904 | sampler_info.mipLodBias = 1.0; |
| 905 | sampler_info.maxAnisotropy = 1; |
| 906 | sampler_info.compareEnable = VK_FALSE; |
| 907 | sampler_info.compareOp = VK_COMPARE_OP_NEVER; |
| 908 | sampler_info.minLod = 1.0; |
| 909 | sampler_info.maxLod = 1.0; |
| 910 | sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 911 | sampler_info.unnormalizedCoordinates = VK_FALSE; |
| 912 | // Not VK_TRUE or VK_FALSE |
| 913 | sampler_info.anisotropyEnable = 3; |
| 914 | vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler); |
| 915 | m_errorMonitor->VerifyFound(); |
| 916 | } |
Dustin Graves | fce74c0 | 2016-05-10 11:42:58 -0600 | [diff] [blame] | 917 | |
| 918 | TEST_F(VkLayerTest, FailedReturnValue) { |
| 919 | TEST_DESCRIPTION("Check for a message describing a VkResult failure code"); |
| 920 | |
| 921 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 922 | |
Dustin Graves | 13c1e2b | 2016-05-16 15:31:02 -0600 | [diff] [blame] | 923 | // Find an unsupported image format |
| 924 | VkFormat unsupported = VK_FORMAT_UNDEFINED; |
| 925 | for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) { |
| 926 | VkFormat format = static_cast<VkFormat>(f); |
| 927 | VkFormatProperties fProps = m_device->format_properties(format); |
| 928 | if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && |
| 929 | fProps.optimalTilingFeatures == 0) { |
| 930 | unsupported = format; |
| 931 | break; |
| 932 | } |
| 933 | } |
| 934 | |
| 935 | if (unsupported != VK_FORMAT_UNDEFINED) { |
| 936 | m_errorMonitor->SetDesiredFailureMsg( |
| 937 | VK_DEBUG_REPORT_WARNING_BIT_EXT, |
| 938 | "the requested format is not supported on this device"); |
| 939 | // Specify an unsupported VkFormat value to generate a |
| 940 | // VK_ERROR_FORMAT_NOT_SUPPORTED return code |
| 941 | // Expected to trigger a warning from |
| 942 | // parameter_validation::validate_result |
| 943 | VkImageFormatProperties image_format_properties; |
| 944 | VkResult err = vkGetPhysicalDeviceImageFormatProperties( |
| 945 | gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL, |
| 946 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties); |
| 947 | ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED); |
| 948 | m_errorMonitor->VerifyFound(); |
| 949 | } |
Dustin Graves | fce74c0 | 2016-05-10 11:42:58 -0600 | [diff] [blame] | 950 | } |
Mark Lobodzinski | e090fef | 2016-06-09 17:04:56 -0600 | [diff] [blame] | 951 | |
| 952 | TEST_F(VkLayerTest, UpdateBufferAlignment) { |
| 953 | TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer"); |
| 954 | uint32_t updateData[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; |
| 955 | |
| 956 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 957 | |
| 958 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 959 | vk_testing::Buffer buffer; |
| 960 | buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs); |
| 961 | |
| 962 | BeginCommandBuffer(); |
| 963 | // Introduce failure by using dstOffset that is not multiple of 4 |
| 964 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 965 | " is not a multiple of 4"); |
| 966 | m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData); |
| 967 | m_errorMonitor->VerifyFound(); |
| 968 | |
| 969 | // Introduce failure by using dataSize that is not multiple of 4 |
| 970 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 971 | " is not a multiple of 4"); |
| 972 | m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData); |
| 973 | m_errorMonitor->VerifyFound(); |
| 974 | |
| 975 | // Introduce failure by using dataSize that is < 0 |
| 976 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 977 | "must be greater than zero and less than or equal to 65536"); |
| 978 | m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData); |
| 979 | m_errorMonitor->VerifyFound(); |
| 980 | |
| 981 | // Introduce failure by using dataSize that is > 65536 |
| 982 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 983 | "must be greater than zero and less than or equal to 65536"); |
| 984 | m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData); |
| 985 | m_errorMonitor->VerifyFound(); |
| 986 | |
| 987 | EndCommandBuffer(); |
| 988 | } |
| 989 | |
| 990 | TEST_F(VkLayerTest, FillBufferAlignment) { |
| 991 | TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer"); |
| 992 | |
| 993 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 994 | |
| 995 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 996 | vk_testing::Buffer buffer; |
| 997 | buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs); |
| 998 | |
| 999 | BeginCommandBuffer(); |
| 1000 | |
| 1001 | // Introduce failure by using dstOffset that is not multiple of 4 |
| 1002 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1003 | " is not a multiple of 4"); |
| 1004 | m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111); |
| 1005 | m_errorMonitor->VerifyFound(); |
| 1006 | |
| 1007 | // Introduce failure by using size that is not multiple of 4 |
| 1008 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1009 | " is not a multiple of 4"); |
| 1010 | m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111); |
| 1011 | m_errorMonitor->VerifyFound(); |
| 1012 | |
| 1013 | // Introduce failure by using size that is zero |
| 1014 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1015 | "must be greater than zero"); |
| 1016 | m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111); |
| 1017 | m_errorMonitor->VerifyFound(); |
| 1018 | |
| 1019 | EndCommandBuffer(); |
| 1020 | } |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 1021 | #endif // PARAMETER_VALIDATION_TESTS |
| 1022 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 1023 | #if MEM_TRACKER_TESTS |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 1024 | #if 0 |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1025 | TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion) |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1026 | { |
| 1027 | vk_testing::Fence testFence; |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1028 | VkFenceCreateInfo fenceInfo = {}; |
| 1029 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 1030 | fenceInfo.pNext = NULL; |
| 1031 | fenceInfo.flags = 0; |
| 1032 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1033 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 1034 | |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1035 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tony Barbour | c1eb1a5 | 2015-07-20 13:00:10 -0600 | [diff] [blame] | 1036 | |
| 1037 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 1038 | vk_testing::Buffer buffer; |
| 1039 | buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1040 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1041 | BeginCommandBuffer(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1042 | m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1043 | EndCommandBuffer(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1044 | |
| 1045 | testFence.init(*m_device, fenceInfo); |
| 1046 | |
| 1047 | // Bypass framework since it does the waits automatically |
| 1048 | VkResult err = VK_SUCCESS; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1049 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 1050 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 1051 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1052 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1053 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 1054 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1055 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1056 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1057 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1058 | submit_info.pSignalSemaphores = NULL; |
Courtney Goeltzenleuchter | 646b907 | 2015-10-20 18:04:07 -0600 | [diff] [blame] | 1059 | |
| 1060 | err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle()); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1061 | ASSERT_VK_SUCCESS( err ); |
| 1062 | |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1063 | // Introduce failure by calling begin again before checking fence |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1064 | vkResetCommandBuffer(m_commandBuffer->handle(), 0); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1065 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 1066 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1067 | } |
| 1068 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1069 | TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion) |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1070 | { |
| 1071 | vk_testing::Fence testFence; |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1072 | VkFenceCreateInfo fenceInfo = {}; |
| 1073 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 1074 | fenceInfo.pNext = NULL; |
| 1075 | fenceInfo.flags = 0; |
| 1076 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1077 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active CB"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 1078 | |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1079 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1080 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1081 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 1082 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1083 | BeginCommandBuffer(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1084 | m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1085 | EndCommandBuffer(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1086 | |
| 1087 | testFence.init(*m_device, fenceInfo); |
| 1088 | |
| 1089 | // Bypass framework since it does the waits automatically |
| 1090 | VkResult err = VK_SUCCESS; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1091 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 1092 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 1093 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1094 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1095 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 1096 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1097 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1098 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1099 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1100 | submit_info.pSignalSemaphores = NULL; |
Courtney Goeltzenleuchter | 646b907 | 2015-10-20 18:04:07 -0600 | [diff] [blame] | 1101 | |
| 1102 | err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle()); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1103 | ASSERT_VK_SUCCESS( err ); |
| 1104 | |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 1105 | VkCommandBufferInheritanceInfo hinfo = {}; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1106 | VkCommandBufferBeginInfo info = {}; |
| 1107 | info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
| 1108 | info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 1109 | info.renderPass = VK_NULL_HANDLE; |
| 1110 | info.subpass = 0; |
| 1111 | info.framebuffer = VK_NULL_HANDLE; |
Chia-I Wu | b8d47ae | 2015-11-11 10:18:12 +0800 | [diff] [blame] | 1112 | info.occlusionQueryEnable = VK_FALSE; |
| 1113 | info.queryFlags = 0; |
| 1114 | info.pipelineStatistics = 0; |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 1115 | |
| 1116 | // Introduce failure by calling BCB again before checking fence |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1117 | vkBeginCommandBuffer(m_commandBuffer->handle(), &info); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1118 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 1119 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1120 | } |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 1121 | #endif |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 1122 | |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1123 | // This is a positive test. No failures are expected. |
| 1124 | TEST_F(VkLayerTest, TestAliasedMemoryTracking) { |
| 1125 | VkResult err; |
| 1126 | bool pass; |
| 1127 | |
| 1128 | TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy " |
| 1129 | "the buffer, create an image, and bind the same memory to " |
| 1130 | "it"); |
| 1131 | |
| 1132 | m_errorMonitor->ExpectSuccess(); |
| 1133 | |
| 1134 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1135 | |
| 1136 | VkBuffer buffer; |
| 1137 | VkImage image; |
| 1138 | VkDeviceMemory mem; |
| 1139 | VkMemoryRequirements mem_reqs; |
| 1140 | |
| 1141 | VkBufferCreateInfo buf_info = {}; |
| 1142 | buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1143 | buf_info.pNext = NULL; |
| 1144 | buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 1145 | buf_info.size = 256; |
| 1146 | buf_info.queueFamilyIndexCount = 0; |
| 1147 | buf_info.pQueueFamilyIndices = NULL; |
| 1148 | buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1149 | buf_info.flags = 0; |
| 1150 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer); |
| 1151 | ASSERT_VK_SUCCESS(err); |
| 1152 | |
| 1153 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs); |
| 1154 | |
| 1155 | VkMemoryAllocateInfo alloc_info = {}; |
| 1156 | alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1157 | alloc_info.pNext = NULL; |
| 1158 | alloc_info.memoryTypeIndex = 0; |
| 1159 | |
| 1160 | // Ensure memory is big enough for both bindings |
| 1161 | alloc_info.allocationSize = 0x10000; |
| 1162 | |
| 1163 | pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, |
| 1164 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 1165 | if (!pass) { |
| 1166 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1167 | return; |
| 1168 | } |
| 1169 | |
| 1170 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem); |
| 1171 | ASSERT_VK_SUCCESS(err); |
| 1172 | |
| 1173 | uint8_t *pData; |
| 1174 | err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, |
| 1175 | (void **)&pData); |
| 1176 | ASSERT_VK_SUCCESS(err); |
| 1177 | |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 1178 | memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size)); |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1179 | |
| 1180 | vkUnmapMemory(m_device->device(), mem); |
| 1181 | |
| 1182 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 1183 | ASSERT_VK_SUCCESS(err); |
| 1184 | |
| 1185 | // NOW, destroy the buffer. Obviously, the resource no longer occupies this |
| 1186 | // memory. In fact, it was never used by the GPU. |
| 1187 | // Just be be sure, wait for idle. |
| 1188 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1189 | vkDeviceWaitIdle(m_device->device()); |
| 1190 | |
| 1191 | VkImageCreateInfo image_create_info = {}; |
| 1192 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 1193 | image_create_info.pNext = NULL; |
| 1194 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 1195 | image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 1196 | image_create_info.extent.width = 64; |
| 1197 | image_create_info.extent.height = 64; |
| 1198 | image_create_info.extent.depth = 1; |
| 1199 | image_create_info.mipLevels = 1; |
| 1200 | image_create_info.arrayLayers = 1; |
| 1201 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 1202 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 1203 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 1204 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 1205 | image_create_info.queueFamilyIndexCount = 0; |
| 1206 | image_create_info.pQueueFamilyIndices = NULL; |
| 1207 | image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1208 | image_create_info.flags = 0; |
| 1209 | |
| 1210 | VkMemoryAllocateInfo mem_alloc = {}; |
| 1211 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1212 | mem_alloc.pNext = NULL; |
| 1213 | mem_alloc.allocationSize = 0; |
| 1214 | mem_alloc.memoryTypeIndex = 0; |
| 1215 | |
| 1216 | /* Create a mappable image. It will be the texture if linear images are ok |
| 1217 | * to be textures or it will be the staging image if they are not. |
| 1218 | */ |
| 1219 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 1220 | ASSERT_VK_SUCCESS(err); |
| 1221 | |
| 1222 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 1223 | |
| 1224 | mem_alloc.allocationSize = mem_reqs.size; |
| 1225 | |
| 1226 | pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, |
| 1227 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 1228 | if (!pass) { |
| 1229 | vkDestroyImage(m_device->device(), image, NULL); |
| 1230 | return; |
| 1231 | } |
| 1232 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1233 | // VALIDATION FAILURE: |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1234 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 1235 | ASSERT_VK_SUCCESS(err); |
| 1236 | |
| 1237 | m_errorMonitor->VerifyNotFound(); |
| 1238 | |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 1239 | vkFreeMemory(m_device->device(), mem, NULL); |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1240 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1241 | vkDestroyImage(m_device->device(), image, NULL); |
| 1242 | } |
| 1243 | |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1244 | TEST_F(VkLayerTest, InvalidMemoryAliasing) { |
| 1245 | TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the " |
| 1246 | "buffer and image to memory such that they will alias."); |
| 1247 | VkResult err; |
| 1248 | bool pass; |
| 1249 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1250 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1251 | VkBuffer buffer, buffer2; |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1252 | VkImage image; |
| 1253 | VkDeviceMemory mem; // buffer will be bound first |
| 1254 | VkDeviceMemory mem_img; // image bound first |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1255 | VkMemoryRequirements buff_mem_reqs, img_mem_reqs; |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1256 | |
| 1257 | VkBufferCreateInfo buf_info = {}; |
| 1258 | buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1259 | buf_info.pNext = NULL; |
| 1260 | buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 1261 | buf_info.size = 256; |
| 1262 | buf_info.queueFamilyIndexCount = 0; |
| 1263 | buf_info.pQueueFamilyIndices = NULL; |
| 1264 | buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1265 | buf_info.flags = 0; |
| 1266 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer); |
| 1267 | ASSERT_VK_SUCCESS(err); |
| 1268 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1269 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1270 | |
| 1271 | VkImageCreateInfo image_create_info = {}; |
| 1272 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 1273 | image_create_info.pNext = NULL; |
| 1274 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 1275 | image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 1276 | image_create_info.extent.width = 64; |
| 1277 | image_create_info.extent.height = 64; |
| 1278 | image_create_info.extent.depth = 1; |
| 1279 | image_create_info.mipLevels = 1; |
| 1280 | image_create_info.arrayLayers = 1; |
| 1281 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 1282 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 1283 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 1284 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 1285 | image_create_info.queueFamilyIndexCount = 0; |
| 1286 | image_create_info.pQueueFamilyIndices = NULL; |
| 1287 | image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1288 | image_create_info.flags = 0; |
| 1289 | |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1290 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 1291 | ASSERT_VK_SUCCESS(err); |
| 1292 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1293 | vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs); |
| 1294 | |
| 1295 | VkMemoryAllocateInfo alloc_info = {}; |
| 1296 | alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1297 | alloc_info.pNext = NULL; |
| 1298 | alloc_info.memoryTypeIndex = 0; |
| 1299 | // Ensure memory is big enough for both bindings |
| 1300 | alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size; |
| 1301 | pass = m_device->phy().set_memory_type( |
| 1302 | buff_mem_reqs.memoryTypeBits | img_mem_reqs.memoryTypeBits, &alloc_info, |
| 1303 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1304 | if (!pass) { |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1305 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1306 | vkDestroyImage(m_device->device(), image, NULL); |
| 1307 | return; |
| 1308 | } |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1309 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem); |
| 1310 | ASSERT_VK_SUCCESS(err); |
| 1311 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 1312 | ASSERT_VK_SUCCESS(err); |
| 1313 | |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1314 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1315 | " is aliased with buffer 0x"); |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1316 | // VALIDATION FAILURE due to image mapping overlapping buffer mapping |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1317 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 1318 | m_errorMonitor->VerifyFound(); |
| 1319 | |
| 1320 | // Now correctly bind image to second mem allocation before incorrectly |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1321 | // aliasing buffer2 |
| 1322 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2); |
| 1323 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1324 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img); |
| 1325 | ASSERT_VK_SUCCESS(err); |
| 1326 | err = vkBindImageMemory(m_device->device(), image, mem_img, 0); |
| 1327 | ASSERT_VK_SUCCESS(err); |
| 1328 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1329 | " is aliased with image 0x"); |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1330 | err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1331 | m_errorMonitor->VerifyFound(); |
| 1332 | |
| 1333 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1334 | vkDestroyBuffer(m_device->device(), buffer2, NULL); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1335 | vkDestroyImage(m_device->device(), image, NULL); |
| 1336 | vkFreeMemory(m_device->device(), mem, NULL); |
| 1337 | vkFreeMemory(m_device->device(), mem_img, NULL); |
| 1338 | } |
| 1339 | |
Tobin Ehlis | 3537252 | 2016-05-12 08:32:31 -0600 | [diff] [blame] | 1340 | TEST_F(VkLayerTest, InvalidMemoryMapping) { |
| 1341 | TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways"); |
| 1342 | VkResult err; |
| 1343 | bool pass; |
| 1344 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1345 | |
| 1346 | VkBuffer buffer; |
| 1347 | VkDeviceMemory mem; |
| 1348 | VkMemoryRequirements mem_reqs; |
| 1349 | |
| 1350 | VkBufferCreateInfo buf_info = {}; |
| 1351 | buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1352 | buf_info.pNext = NULL; |
| 1353 | buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 1354 | buf_info.size = 256; |
| 1355 | buf_info.queueFamilyIndexCount = 0; |
| 1356 | buf_info.pQueueFamilyIndices = NULL; |
| 1357 | buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1358 | buf_info.flags = 0; |
| 1359 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer); |
| 1360 | ASSERT_VK_SUCCESS(err); |
| 1361 | |
| 1362 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs); |
| 1363 | VkMemoryAllocateInfo alloc_info = {}; |
| 1364 | alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1365 | alloc_info.pNext = NULL; |
| 1366 | alloc_info.memoryTypeIndex = 0; |
| 1367 | |
| 1368 | // Ensure memory is big enough for both bindings |
| 1369 | static const VkDeviceSize allocation_size = 0x10000; |
| 1370 | alloc_info.allocationSize = allocation_size; |
| 1371 | pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, |
| 1372 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 1373 | if (!pass) { |
| 1374 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1375 | return; |
| 1376 | } |
| 1377 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem); |
| 1378 | ASSERT_VK_SUCCESS(err); |
| 1379 | |
| 1380 | uint8_t *pData; |
| 1381 | // Attempt to map memory size 0 is invalid |
| 1382 | m_errorMonitor->SetDesiredFailureMsg( |
| 1383 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1384 | "VkMapMemory: Attempting to map memory range of size zero"); |
| 1385 | err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData); |
| 1386 | m_errorMonitor->VerifyFound(); |
| 1387 | // Map memory twice |
| 1388 | err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, |
| 1389 | (void **)&pData); |
| 1390 | ASSERT_VK_SUCCESS(err); |
| 1391 | m_errorMonitor->SetDesiredFailureMsg( |
| 1392 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1393 | "VkMapMemory: Attempting to map memory on an already-mapped object "); |
| 1394 | err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, |
| 1395 | (void **)&pData); |
| 1396 | m_errorMonitor->VerifyFound(); |
| 1397 | |
| 1398 | // Unmap the memory to avoid re-map error |
| 1399 | vkUnmapMemory(m_device->device(), mem); |
| 1400 | // overstep allocation with VK_WHOLE_SIZE |
| 1401 | m_errorMonitor->SetDesiredFailureMsg( |
| 1402 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1403 | " with size of VK_WHOLE_SIZE oversteps total array size 0x"); |
| 1404 | err = vkMapMemory(m_device->device(), mem, allocation_size + 1, |
| 1405 | VK_WHOLE_SIZE, 0, (void **)&pData); |
| 1406 | m_errorMonitor->VerifyFound(); |
| 1407 | // overstep allocation w/o VK_WHOLE_SIZE |
| 1408 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1409 | " oversteps total array size 0x"); |
| 1410 | err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, |
| 1411 | (void **)&pData); |
| 1412 | m_errorMonitor->VerifyFound(); |
| 1413 | // Now error due to unmapping memory that's not mapped |
| 1414 | m_errorMonitor->SetDesiredFailureMsg( |
| 1415 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1416 | "Unmapping Memory without memory being mapped: "); |
| 1417 | vkUnmapMemory(m_device->device(), mem); |
| 1418 | m_errorMonitor->VerifyFound(); |
| 1419 | // Now map memory and cause errors due to flushing invalid ranges |
| 1420 | err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0, |
| 1421 | (void **)&pData); |
| 1422 | ASSERT_VK_SUCCESS(err); |
| 1423 | VkMappedMemoryRange mmr = {}; |
Chris Forbes | 3aec089 | 2016-06-13 10:29:26 +1200 | [diff] [blame] | 1424 | mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; |
Tobin Ehlis | 3537252 | 2016-05-12 08:32:31 -0600 | [diff] [blame] | 1425 | mmr.memory = mem; |
| 1426 | mmr.offset = 15; // Error b/c offset less than offset of mapped mem |
| 1427 | m_errorMonitor->SetDesiredFailureMsg( |
| 1428 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1429 | ") is less than Memory Object's offset ("); |
| 1430 | vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr); |
| 1431 | m_errorMonitor->VerifyFound(); |
| 1432 | // Now flush range that oversteps mapped range |
| 1433 | vkUnmapMemory(m_device->device(), mem); |
| 1434 | err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData); |
| 1435 | ASSERT_VK_SUCCESS(err); |
| 1436 | mmr.offset = 16; |
| 1437 | mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256) |
| 1438 | m_errorMonitor->SetDesiredFailureMsg( |
| 1439 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1440 | ") exceeds the Memory Object's upper-bound ("); |
| 1441 | vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr); |
| 1442 | m_errorMonitor->VerifyFound(); |
| 1443 | |
| 1444 | pass = |
| 1445 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, |
| 1446 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, |
| 1447 | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); |
| 1448 | if (!pass) { |
| 1449 | vkFreeMemory(m_device->device(), mem, NULL); |
| 1450 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1451 | return; |
| 1452 | } |
| 1453 | // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of |
| 1454 | // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver() |
| 1455 | |
| 1456 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1457 | vkFreeMemory(m_device->device(), mem, NULL); |
| 1458 | } |
| 1459 | |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1460 | TEST_F(VkLayerTest, EnableWsiBeforeUse) { |
| 1461 | VkResult err; |
| 1462 | bool pass; |
| 1463 | |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1464 | // FIXME: After we turn on this code for non-Linux platforms, uncomment the |
| 1465 | // following declaration (which is temporarily being moved below): |
| 1466 | // VkSurfaceKHR surface = VK_NULL_HANDLE; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1467 | VkSwapchainKHR swapchain = VK_NULL_HANDLE; |
| 1468 | VkSwapchainCreateInfoKHR swapchain_create_info = {}; |
| 1469 | uint32_t swapchain_image_count = 0; |
| 1470 | // VkImage swapchain_images[1] = {VK_NULL_HANDLE}; |
| 1471 | uint32_t image_index = 0; |
| 1472 | // VkPresentInfoKHR present_info = {}; |
| 1473 | |
| 1474 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1475 | |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1476 | #ifdef NEED_TO_TEST_THIS_ON_PLATFORM |
| 1477 | #if defined(VK_USE_PLATFORM_ANDROID_KHR) |
| 1478 | // Use the functions from the VK_KHR_android_surface extension without |
| 1479 | // enabling that extension: |
| 1480 | |
| 1481 | // Create a surface: |
| 1482 | VkAndroidSurfaceCreateInfoKHR android_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1483 | m_errorMonitor->SetDesiredFailureMsg( |
| 1484 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1485 | "extension was not enabled for this"); |
| 1486 | err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, |
| 1487 | &surface); |
| 1488 | pass = (err != VK_SUCCESS); |
| 1489 | ASSERT_TRUE(pass); |
| 1490 | m_errorMonitor->VerifyFound(); |
| 1491 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 1492 | |
| 1493 | |
| 1494 | #if defined(VK_USE_PLATFORM_MIR_KHR) |
| 1495 | // Use the functions from the VK_KHR_mir_surface extension without enabling |
| 1496 | // that extension: |
| 1497 | |
| 1498 | // Create a surface: |
| 1499 | VkMirSurfaceCreateInfoKHR mir_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1500 | m_errorMonitor->SetDesiredFailureMsg( |
| 1501 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1502 | "extension was not enabled for this"); |
| 1503 | err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface); |
| 1504 | pass = (err != VK_SUCCESS); |
| 1505 | ASSERT_TRUE(pass); |
| 1506 | m_errorMonitor->VerifyFound(); |
| 1507 | |
| 1508 | // Tell whether an mir_connection supports presentation: |
| 1509 | MirConnection *mir_connection = NULL; |
| 1510 | m_errorMonitor->SetDesiredFailureMsg( |
| 1511 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1512 | "extension was not enabled for this"); |
| 1513 | vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, |
| 1514 | visual_id); |
| 1515 | m_errorMonitor->VerifyFound(); |
| 1516 | #endif // VK_USE_PLATFORM_MIR_KHR |
| 1517 | |
| 1518 | |
| 1519 | #if defined(VK_USE_PLATFORM_WAYLAND_KHR) |
| 1520 | // Use the functions from the VK_KHR_wayland_surface extension without |
| 1521 | // enabling that extension: |
| 1522 | |
| 1523 | // Create a surface: |
| 1524 | VkWaylandSurfaceCreateInfoKHR wayland_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1525 | m_errorMonitor->SetDesiredFailureMsg( |
| 1526 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1527 | "extension was not enabled for this"); |
| 1528 | err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, |
| 1529 | &surface); |
| 1530 | pass = (err != VK_SUCCESS); |
| 1531 | ASSERT_TRUE(pass); |
| 1532 | m_errorMonitor->VerifyFound(); |
| 1533 | |
| 1534 | // Tell whether an wayland_display supports presentation: |
| 1535 | struct wl_display wayland_display = {}; |
| 1536 | m_errorMonitor->SetDesiredFailureMsg( |
| 1537 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1538 | "extension was not enabled for this"); |
| 1539 | vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, |
| 1540 | &wayland_display); |
| 1541 | m_errorMonitor->VerifyFound(); |
| 1542 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1543 | #endif // NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1544 | |
| 1545 | |
| 1546 | #if defined(VK_USE_PLATFORM_WIN32_KHR) |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1547 | // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED |
| 1548 | // TO NON-LINUX PLATFORMS: |
| 1549 | VkSurfaceKHR surface = VK_NULL_HANDLE; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1550 | // Use the functions from the VK_KHR_win32_surface extension without |
| 1551 | // enabling that extension: |
| 1552 | |
| 1553 | // Create a surface: |
| 1554 | VkWin32SurfaceCreateInfoKHR win32_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1555 | m_errorMonitor->SetDesiredFailureMsg( |
| 1556 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1557 | "extension was not enabled for this"); |
| 1558 | err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, |
| 1559 | &surface); |
| 1560 | pass = (err != VK_SUCCESS); |
| 1561 | ASSERT_TRUE(pass); |
| 1562 | m_errorMonitor->VerifyFound(); |
| 1563 | |
| 1564 | // Tell whether win32 supports presentation: |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1565 | m_errorMonitor->SetDesiredFailureMsg( |
| 1566 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1567 | "extension was not enabled for this"); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1568 | vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0); |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1569 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1570 | // Set this (for now, until all platforms are supported and tested): |
| 1571 | #define NEED_TO_TEST_THIS_ON_PLATFORM |
| 1572 | #endif // VK_USE_PLATFORM_WIN32_KHR |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1573 | |
| 1574 | |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1575 | #if defined(VK_USE_PLATFORM_XCB_KHR) |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1576 | // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED |
| 1577 | // TO NON-LINUX PLATFORMS: |
| 1578 | VkSurfaceKHR surface = VK_NULL_HANDLE; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1579 | // Use the functions from the VK_KHR_xcb_surface extension without enabling |
| 1580 | // that extension: |
| 1581 | |
| 1582 | // Create a surface: |
| 1583 | VkXcbSurfaceCreateInfoKHR xcb_create_info = {}; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1584 | m_errorMonitor->SetDesiredFailureMsg( |
| 1585 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1586 | "extension was not enabled for this"); |
| 1587 | err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface); |
| 1588 | pass = (err != VK_SUCCESS); |
| 1589 | ASSERT_TRUE(pass); |
| 1590 | m_errorMonitor->VerifyFound(); |
| 1591 | |
| 1592 | // Tell whether an xcb_visualid_t supports presentation: |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1593 | xcb_connection_t *xcb_connection = NULL; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1594 | xcb_visualid_t visual_id = 0; |
| 1595 | m_errorMonitor->SetDesiredFailureMsg( |
| 1596 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1597 | "extension was not enabled for this"); |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1598 | vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1599 | visual_id); |
| 1600 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1601 | // Set this (for now, until all platforms are supported and tested): |
| 1602 | #define NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1603 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 1604 | |
| 1605 | |
Ian Elliott | 1263081 | 2016-04-29 14:35:43 -0600 | [diff] [blame] | 1606 | #if defined(VK_USE_PLATFORM_XLIB_KHR) |
| 1607 | // Use the functions from the VK_KHR_xlib_surface extension without enabling |
| 1608 | // that extension: |
| 1609 | |
| 1610 | // Create a surface: |
| 1611 | VkXlibSurfaceCreateInfoKHR xlib_create_info = {}; |
Ian Elliott | 1263081 | 2016-04-29 14:35:43 -0600 | [diff] [blame] | 1612 | m_errorMonitor->SetDesiredFailureMsg( |
| 1613 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1614 | "extension was not enabled for this"); |
| 1615 | err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface); |
| 1616 | pass = (err != VK_SUCCESS); |
| 1617 | ASSERT_TRUE(pass); |
| 1618 | m_errorMonitor->VerifyFound(); |
| 1619 | |
| 1620 | // Tell whether an Xlib VisualID supports presentation: |
| 1621 | Display *dpy = NULL; |
| 1622 | VisualID visual = 0; |
| 1623 | m_errorMonitor->SetDesiredFailureMsg( |
| 1624 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1625 | "extension was not enabled for this"); |
| 1626 | vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual); |
| 1627 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1628 | // Set this (for now, until all platforms are supported and tested): |
| 1629 | #define NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1263081 | 2016-04-29 14:35:43 -0600 | [diff] [blame] | 1630 | #endif // VK_USE_PLATFORM_XLIB_KHR |
| 1631 | |
| 1632 | |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1633 | // Use the functions from the VK_KHR_surface extension without enabling |
| 1634 | // that extension: |
| 1635 | |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1636 | #ifdef NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1637 | // Destroy a surface: |
| 1638 | m_errorMonitor->SetDesiredFailureMsg( |
| 1639 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1640 | "extension was not enabled for this"); |
| 1641 | vkDestroySurfaceKHR(instance(), surface, NULL); |
| 1642 | m_errorMonitor->VerifyFound(); |
| 1643 | |
| 1644 | // Check if surface supports presentation: |
| 1645 | VkBool32 supported = false; |
| 1646 | m_errorMonitor->SetDesiredFailureMsg( |
| 1647 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1648 | "extension was not enabled for this"); |
| 1649 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported); |
| 1650 | pass = (err != VK_SUCCESS); |
| 1651 | ASSERT_TRUE(pass); |
| 1652 | m_errorMonitor->VerifyFound(); |
| 1653 | |
| 1654 | // Check surface capabilities: |
| 1655 | VkSurfaceCapabilitiesKHR capabilities = {}; |
| 1656 | m_errorMonitor->SetDesiredFailureMsg( |
| 1657 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1658 | "extension was not enabled for this"); |
| 1659 | err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, |
| 1660 | &capabilities); |
| 1661 | pass = (err != VK_SUCCESS); |
| 1662 | ASSERT_TRUE(pass); |
| 1663 | m_errorMonitor->VerifyFound(); |
| 1664 | |
| 1665 | // Check surface formats: |
| 1666 | uint32_t format_count = 0; |
| 1667 | VkSurfaceFormatKHR *formats = NULL; |
| 1668 | m_errorMonitor->SetDesiredFailureMsg( |
| 1669 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1670 | "extension was not enabled for this"); |
| 1671 | err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, |
| 1672 | &format_count, formats); |
| 1673 | pass = (err != VK_SUCCESS); |
| 1674 | ASSERT_TRUE(pass); |
| 1675 | m_errorMonitor->VerifyFound(); |
| 1676 | |
| 1677 | // Check surface present modes: |
| 1678 | uint32_t present_mode_count = 0; |
| 1679 | VkSurfaceFormatKHR *present_modes = NULL; |
| 1680 | m_errorMonitor->SetDesiredFailureMsg( |
| 1681 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1682 | "extension was not enabled for this"); |
| 1683 | err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, |
| 1684 | &present_mode_count, present_modes); |
| 1685 | pass = (err != VK_SUCCESS); |
| 1686 | ASSERT_TRUE(pass); |
| 1687 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1688 | #endif // NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1689 | |
| 1690 | |
| 1691 | // Use the functions from the VK_KHR_swapchain extension without enabling |
| 1692 | // that extension: |
| 1693 | |
| 1694 | // Create a swapchain: |
| 1695 | m_errorMonitor->SetDesiredFailureMsg( |
| 1696 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1697 | "extension was not enabled for this"); |
| 1698 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 1699 | swapchain_create_info.pNext = NULL; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1700 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, |
| 1701 | NULL, &swapchain); |
| 1702 | pass = (err != VK_SUCCESS); |
| 1703 | ASSERT_TRUE(pass); |
| 1704 | m_errorMonitor->VerifyFound(); |
| 1705 | |
| 1706 | // Get the images from the swapchain: |
| 1707 | m_errorMonitor->SetDesiredFailureMsg( |
| 1708 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1709 | "extension was not enabled for this"); |
| 1710 | err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, |
| 1711 | &swapchain_image_count, NULL); |
| 1712 | pass = (err != VK_SUCCESS); |
| 1713 | ASSERT_TRUE(pass); |
| 1714 | m_errorMonitor->VerifyFound(); |
| 1715 | |
| 1716 | // Try to acquire an image: |
| 1717 | m_errorMonitor->SetDesiredFailureMsg( |
| 1718 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1719 | "extension was not enabled for this"); |
| 1720 | err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, |
| 1721 | VK_NULL_HANDLE, VK_NULL_HANDLE, &image_index); |
| 1722 | pass = (err != VK_SUCCESS); |
| 1723 | ASSERT_TRUE(pass); |
| 1724 | m_errorMonitor->VerifyFound(); |
| 1725 | |
| 1726 | // Try to present an image: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1727 | // |
| 1728 | // NOTE: Currently can't test this because a real swapchain is needed (as |
| 1729 | // opposed to the fake one we created) in order for the layer to lookup the |
| 1730 | // VkDevice used to enable the extension: |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1731 | |
| 1732 | // Destroy the swapchain: |
| 1733 | m_errorMonitor->SetDesiredFailureMsg( |
| 1734 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1735 | "extension was not enabled for this"); |
| 1736 | vkDestroySwapchainKHR(m_device->device(), swapchain, NULL); |
| 1737 | m_errorMonitor->VerifyFound(); |
| 1738 | } |
| 1739 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1740 | TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) { |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1741 | |
Dustin Graves | 6c6d898 | 2016-05-17 10:09:21 -0600 | [diff] [blame] | 1742 | #if defined(VK_USE_PLATFORM_XCB_KHR) |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1743 | VkSurfaceKHR surface = VK_NULL_HANDLE; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1744 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1745 | VkResult err; |
| 1746 | bool pass; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1747 | VkSwapchainKHR swapchain = VK_NULL_HANDLE; |
| 1748 | VkSwapchainCreateInfoKHR swapchain_create_info = {}; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1749 | // uint32_t swapchain_image_count = 0; |
| 1750 | // VkImage swapchain_images[1] = {VK_NULL_HANDLE}; |
| 1751 | // uint32_t image_index = 0; |
| 1752 | // VkPresentInfoKHR present_info = {}; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1753 | |
| 1754 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1755 | |
| 1756 | // Use the create function from one of the VK_KHR_*_surface extension in |
| 1757 | // order to create a surface, testing all known errors in the process, |
| 1758 | // before successfully creating a surface: |
| 1759 | // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1760 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1761 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1762 | err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface); |
| 1763 | pass = (err != VK_SUCCESS); |
| 1764 | ASSERT_TRUE(pass); |
| 1765 | m_errorMonitor->VerifyFound(); |
| 1766 | |
| 1767 | // Next, try to create a surface with the wrong |
| 1768 | // VkXcbSurfaceCreateInfoKHR::sType: |
| 1769 | VkXcbSurfaceCreateInfoKHR xcb_create_info = {}; |
| 1770 | xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1771 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1772 | "called with the wrong value for"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1773 | err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface); |
| 1774 | pass = (err != VK_SUCCESS); |
| 1775 | ASSERT_TRUE(pass); |
| 1776 | m_errorMonitor->VerifyFound(); |
| 1777 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1778 | // Create a native window, and then correctly create a surface: |
| 1779 | xcb_connection_t *connection; |
| 1780 | xcb_screen_t *screen; |
| 1781 | xcb_window_t xcb_window; |
| 1782 | xcb_intern_atom_reply_t *atom_wm_delete_window; |
| 1783 | |
| 1784 | const xcb_setup_t *setup; |
| 1785 | xcb_screen_iterator_t iter; |
| 1786 | int scr; |
| 1787 | uint32_t value_mask, value_list[32]; |
| 1788 | int width = 1; |
| 1789 | int height = 1; |
| 1790 | |
| 1791 | connection = xcb_connect(NULL, &scr); |
| 1792 | ASSERT_TRUE(connection != NULL); |
| 1793 | setup = xcb_get_setup(connection); |
| 1794 | iter = xcb_setup_roots_iterator(setup); |
| 1795 | while (scr-- > 0) |
| 1796 | xcb_screen_next(&iter); |
| 1797 | screen = iter.data; |
| 1798 | |
| 1799 | xcb_window = xcb_generate_id(connection); |
| 1800 | |
| 1801 | value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; |
| 1802 | value_list[0] = screen->black_pixel; |
| 1803 | value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | |
| 1804 | XCB_EVENT_MASK_STRUCTURE_NOTIFY; |
| 1805 | |
| 1806 | xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, |
| 1807 | screen->root, 0, 0, width, height, 0, |
| 1808 | XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, |
| 1809 | value_mask, value_list); |
| 1810 | |
| 1811 | /* Magic code that will send notification when window is destroyed */ |
| 1812 | xcb_intern_atom_cookie_t cookie = |
| 1813 | xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS"); |
| 1814 | xcb_intern_atom_reply_t *reply = |
| 1815 | xcb_intern_atom_reply(connection, cookie, 0); |
| 1816 | |
| 1817 | xcb_intern_atom_cookie_t cookie2 = |
| 1818 | xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW"); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1819 | atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1820 | xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, |
| 1821 | (*reply).atom, 4, 32, 1, |
| 1822 | &(*atom_wm_delete_window).atom); |
| 1823 | free(reply); |
| 1824 | |
| 1825 | xcb_map_window(connection, xcb_window); |
| 1826 | |
| 1827 | // Force the x/y coordinates to 100,100 results are identical in consecutive |
| 1828 | // runs |
| 1829 | const uint32_t coords[] = {100, 100}; |
| 1830 | xcb_configure_window(connection, xcb_window, |
| 1831 | XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords); |
| 1832 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1833 | // Finally, try to correctly create a surface: |
| 1834 | xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; |
| 1835 | xcb_create_info.pNext = NULL; |
| 1836 | xcb_create_info.flags = 0; |
| 1837 | xcb_create_info.connection = connection; |
| 1838 | xcb_create_info.window = xcb_window; |
| 1839 | err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface); |
| 1840 | pass = (err == VK_SUCCESS); |
| 1841 | ASSERT_TRUE(pass); |
| 1842 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1843 | // Check if surface supports presentation: |
| 1844 | |
| 1845 | // 1st, do so without having queried the queue families: |
| 1846 | VkBool32 supported = false; |
| 1847 | // TODO: Get the following error to come out: |
| 1848 | m_errorMonitor->SetDesiredFailureMsg( |
| 1849 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1850 | "called before calling the vkGetPhysicalDeviceQueueFamilyProperties " |
| 1851 | "function"); |
| 1852 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported); |
| 1853 | pass = (err != VK_SUCCESS); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1854 | // ASSERT_TRUE(pass); |
| 1855 | // m_errorMonitor->VerifyFound(); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1856 | |
| 1857 | // Next, query a queue family index that's too large: |
| 1858 | m_errorMonitor->SetDesiredFailureMsg( |
| 1859 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1860 | "called with a queueFamilyIndex that is too large"); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1861 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, |
| 1862 | &supported); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1863 | pass = (err != VK_SUCCESS); |
| 1864 | ASSERT_TRUE(pass); |
| 1865 | m_errorMonitor->VerifyFound(); |
| 1866 | |
| 1867 | // Finally, do so correctly: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1868 | // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S |
| 1869 | // SUPPORTED |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1870 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported); |
| 1871 | pass = (err == VK_SUCCESS); |
| 1872 | ASSERT_TRUE(pass); |
| 1873 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1874 | // Before proceeding, try to create a swapchain without having called |
| 1875 | // vkGetPhysicalDeviceSurfaceCapabilitiesKHR(): |
| 1876 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 1877 | swapchain_create_info.pNext = NULL; |
| 1878 | swapchain_create_info.flags = 0; |
| 1879 | m_errorMonitor->SetDesiredFailureMsg( |
| 1880 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1881 | "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR()."); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1882 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 1883 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1884 | pass = (err != VK_SUCCESS); |
| 1885 | ASSERT_TRUE(pass); |
| 1886 | m_errorMonitor->VerifyFound(); |
| 1887 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1888 | // Get the surface capabilities: |
| 1889 | VkSurfaceCapabilitiesKHR surface_capabilities; |
| 1890 | |
| 1891 | // Do so correctly (only error logged by this entrypoint is if the |
| 1892 | // extension isn't enabled): |
| 1893 | err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, |
| 1894 | &surface_capabilities); |
| 1895 | pass = (err == VK_SUCCESS); |
| 1896 | ASSERT_TRUE(pass); |
| 1897 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1898 | // Get the surface formats: |
| 1899 | uint32_t surface_format_count; |
| 1900 | |
| 1901 | // First, try without a pointer to surface_format_count: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1902 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1903 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1904 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL); |
| 1905 | pass = (err == VK_SUCCESS); |
| 1906 | ASSERT_TRUE(pass); |
| 1907 | m_errorMonitor->VerifyFound(); |
| 1908 | |
| 1909 | // Next, call with a non-NULL pSurfaceFormats, even though we haven't |
| 1910 | // correctly done a 1st try (to get the count): |
| 1911 | m_errorMonitor->SetDesiredFailureMsg( |
| 1912 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1913 | "but no prior positive value has been seen for"); |
| 1914 | surface_format_count = 0; |
| 1915 | vkGetPhysicalDeviceSurfaceFormatsKHR( |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1916 | gpu(), surface, &surface_format_count, |
| 1917 | (VkSurfaceFormatKHR *)&surface_format_count); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1918 | pass = (err == VK_SUCCESS); |
| 1919 | ASSERT_TRUE(pass); |
| 1920 | m_errorMonitor->VerifyFound(); |
| 1921 | |
| 1922 | // Next, correctly do a 1st try (with a NULL pointer to surface_formats): |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1923 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
| 1924 | NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1925 | pass = (err == VK_SUCCESS); |
| 1926 | ASSERT_TRUE(pass); |
| 1927 | |
| 1928 | // Allocate memory for the correct number of VkSurfaceFormatKHR's: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1929 | VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc( |
| 1930 | surface_format_count * sizeof(VkSurfaceFormatKHR)); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1931 | |
| 1932 | // Next, do a 2nd try with surface_format_count being set too high: |
| 1933 | surface_format_count += 5; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1934 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1935 | "that is greater than the value"); |
| 1936 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1937 | surface_formats); |
| 1938 | pass = (err == VK_SUCCESS); |
| 1939 | ASSERT_TRUE(pass); |
| 1940 | m_errorMonitor->VerifyFound(); |
| 1941 | |
| 1942 | // Finally, do a correct 1st and 2nd try: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1943 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
| 1944 | NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1945 | pass = (err == VK_SUCCESS); |
| 1946 | ASSERT_TRUE(pass); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1947 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1948 | surface_formats); |
| 1949 | pass = (err == VK_SUCCESS); |
| 1950 | ASSERT_TRUE(pass); |
| 1951 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1952 | // Get the surface present modes: |
| 1953 | uint32_t surface_present_mode_count; |
| 1954 | |
| 1955 | // First, try without a pointer to surface_format_count: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1956 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1957 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1958 | vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL); |
| 1959 | pass = (err == VK_SUCCESS); |
| 1960 | ASSERT_TRUE(pass); |
| 1961 | m_errorMonitor->VerifyFound(); |
| 1962 | |
| 1963 | // Next, call with a non-NULL VkPresentModeKHR, even though we haven't |
| 1964 | // correctly done a 1st try (to get the count): |
| 1965 | m_errorMonitor->SetDesiredFailureMsg( |
| 1966 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1967 | "but no prior positive value has been seen for"); |
| 1968 | surface_present_mode_count = 0; |
| 1969 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1970 | gpu(), surface, &surface_present_mode_count, |
| 1971 | (VkPresentModeKHR *)&surface_present_mode_count); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1972 | pass = (err == VK_SUCCESS); |
| 1973 | ASSERT_TRUE(pass); |
| 1974 | m_errorMonitor->VerifyFound(); |
| 1975 | |
| 1976 | // Next, correctly do a 1st try (with a NULL pointer to surface_formats): |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1977 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 1978 | gpu(), surface, &surface_present_mode_count, NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1979 | pass = (err == VK_SUCCESS); |
| 1980 | ASSERT_TRUE(pass); |
| 1981 | |
| 1982 | // Allocate memory for the correct number of VkSurfaceFormatKHR's: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1983 | VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc( |
| 1984 | surface_present_mode_count * sizeof(VkPresentModeKHR)); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1985 | |
| 1986 | // Next, do a 2nd try with surface_format_count being set too high: |
| 1987 | surface_present_mode_count += 5; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1988 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1989 | "that is greater than the value"); |
| 1990 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 1991 | gpu(), surface, &surface_present_mode_count, surface_present_modes); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1992 | pass = (err == VK_SUCCESS); |
| 1993 | ASSERT_TRUE(pass); |
| 1994 | m_errorMonitor->VerifyFound(); |
| 1995 | |
| 1996 | // Finally, do a correct 1st and 2nd try: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1997 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 1998 | gpu(), surface, &surface_present_mode_count, NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1999 | pass = (err == VK_SUCCESS); |
| 2000 | ASSERT_TRUE(pass); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2001 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 2002 | gpu(), surface, &surface_present_mode_count, surface_present_modes); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2003 | pass = (err == VK_SUCCESS); |
| 2004 | ASSERT_TRUE(pass); |
| 2005 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2006 | // Create a swapchain: |
| 2007 | |
| 2008 | // First, try without a pointer to swapchain_create_info: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2009 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2010 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2011 | err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain); |
| 2012 | pass = (err != VK_SUCCESS); |
| 2013 | ASSERT_TRUE(pass); |
| 2014 | m_errorMonitor->VerifyFound(); |
| 2015 | |
| 2016 | // Next, call with a non-NULL swapchain_create_info, that has the wrong |
| 2017 | // sType: |
| 2018 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2019 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2020 | "called with the wrong value for"); |
| 2021 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2022 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2023 | pass = (err != VK_SUCCESS); |
| 2024 | ASSERT_TRUE(pass); |
| 2025 | m_errorMonitor->VerifyFound(); |
| 2026 | |
| 2027 | // Next, call with a NULL swapchain pointer: |
| 2028 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 2029 | swapchain_create_info.pNext = NULL; |
| 2030 | swapchain_create_info.flags = 0; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2031 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2032 | "called with NULL pointer"); |
| 2033 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2034 | NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2035 | pass = (err != VK_SUCCESS); |
| 2036 | ASSERT_TRUE(pass); |
| 2037 | m_errorMonitor->VerifyFound(); |
| 2038 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2039 | // TODO: Enhance swapchain layer so that |
| 2040 | // swapchain_create_info.queueFamilyIndexCount is checked against something? |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2041 | |
| 2042 | // Next, call with a queue family index that's too large: |
| 2043 | uint32_t queueFamilyIndex[2] = {100000, 0}; |
| 2044 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT; |
| 2045 | swapchain_create_info.queueFamilyIndexCount = 2; |
| 2046 | swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex; |
| 2047 | m_errorMonitor->SetDesiredFailureMsg( |
| 2048 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2049 | "called with a queueFamilyIndex that is too large"); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2050 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2051 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2052 | pass = (err != VK_SUCCESS); |
| 2053 | ASSERT_TRUE(pass); |
| 2054 | m_errorMonitor->VerifyFound(); |
| 2055 | |
| 2056 | // Next, call a queueFamilyIndexCount that's too small for CONCURRENT: |
| 2057 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT; |
| 2058 | swapchain_create_info.queueFamilyIndexCount = 1; |
| 2059 | m_errorMonitor->SetDesiredFailureMsg( |
| 2060 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2061 | "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or " |
| 2062 | "pCreateInfo->pQueueFamilyIndices)."); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2063 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2064 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2065 | pass = (err != VK_SUCCESS); |
| 2066 | ASSERT_TRUE(pass); |
| 2067 | m_errorMonitor->VerifyFound(); |
| 2068 | |
| 2069 | // Next, call with an invalid imageSharingMode: |
| 2070 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM; |
| 2071 | swapchain_create_info.queueFamilyIndexCount = 1; |
| 2072 | m_errorMonitor->SetDesiredFailureMsg( |
| 2073 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2074 | "called with a non-supported pCreateInfo->imageSharingMode (i.e."); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2075 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 2076 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2077 | pass = (err != VK_SUCCESS); |
| 2078 | ASSERT_TRUE(pass); |
| 2079 | m_errorMonitor->VerifyFound(); |
| 2080 | // Fix for the future: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2081 | // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S |
| 2082 | // SUPPORTED |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2083 | swapchain_create_info.queueFamilyIndexCount = 0; |
| 2084 | queueFamilyIndex[0] = 0; |
| 2085 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 2086 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2087 | // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ... |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2088 | // Get the images from a swapchain: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2089 | // Acquire an image from a swapchain: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2090 | // Present an image to a swapchain: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2091 | // Destroy the swapchain: |
| 2092 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2093 | // TODOs: |
| 2094 | // |
| 2095 | // - Try destroying the device without first destroying the swapchain |
| 2096 | // |
| 2097 | // - Try destroying the device without first destroying the surface |
| 2098 | // |
| 2099 | // - Try destroying the surface without first destroying the swapchain |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2100 | |
| 2101 | // Destroy the surface: |
| 2102 | vkDestroySurfaceKHR(instance(), surface, NULL); |
| 2103 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2104 | // Tear down the window: |
| 2105 | xcb_destroy_window(connection, xcb_window); |
| 2106 | xcb_disconnect(connection); |
| 2107 | |
| 2108 | #else // VK_USE_PLATFORM_XCB_KHR |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2109 | return; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2110 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 2111 | } |
| 2112 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2113 | TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) { |
| 2114 | VkResult err; |
| 2115 | bool pass; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2116 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2117 | m_errorMonitor->SetDesiredFailureMsg( |
| 2118 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2119 | "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT"); |
| 2120 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2121 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2122 | |
| 2123 | // Create an image, allocate memory, free it, and then try to bind it |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2124 | VkImage image; |
| 2125 | VkDeviceMemory mem; |
| 2126 | VkMemoryRequirements mem_reqs; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2127 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2128 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2129 | const int32_t tex_width = 32; |
| 2130 | const int32_t tex_height = 32; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2131 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2132 | VkImageCreateInfo image_create_info = {}; |
| 2133 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2134 | image_create_info.pNext = NULL; |
| 2135 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2136 | image_create_info.format = tex_format; |
| 2137 | image_create_info.extent.width = tex_width; |
| 2138 | image_create_info.extent.height = tex_height; |
| 2139 | image_create_info.extent.depth = 1; |
| 2140 | image_create_info.mipLevels = 1; |
| 2141 | image_create_info.arrayLayers = 1; |
| 2142 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2143 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2144 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2145 | image_create_info.flags = 0; |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 2146 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2147 | VkMemoryAllocateInfo mem_alloc = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 2148 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2149 | mem_alloc.pNext = NULL; |
| 2150 | mem_alloc.allocationSize = 0; |
| 2151 | // Introduce failure, do NOT set memProps to |
| 2152 | // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
| 2153 | mem_alloc.memoryTypeIndex = 1; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2154 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2155 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2156 | ASSERT_VK_SUCCESS(err); |
| 2157 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2158 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2159 | |
Mark Lobodzinski | 2306535 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 2160 | mem_alloc.allocationSize = mem_reqs.size; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2161 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2162 | pass = |
| 2163 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, |
| 2164 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 2165 | if (!pass) { // If we can't find any unmappable memory this test doesn't |
| 2166 | // make sense |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2167 | vkDestroyImage(m_device->device(), image, NULL); |
Tony Barbour | 02fdc7d | 2015-08-04 16:13:01 -0600 | [diff] [blame] | 2168 | return; |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2169 | } |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 2170 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2171 | // allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2172 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2173 | ASSERT_VK_SUCCESS(err); |
| 2174 | |
| 2175 | // Try to bind free memory that has been freed |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 2176 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2177 | ASSERT_VK_SUCCESS(err); |
| 2178 | |
| 2179 | // Map memory as if to initialize the image |
| 2180 | void *mappedAddress = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2181 | err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, |
| 2182 | &mappedAddress); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2183 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2184 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2185 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2186 | vkDestroyImage(m_device->device(), image, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 2187 | vkFreeMemory(m_device->device(), mem, NULL); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2188 | } |
| 2189 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2190 | TEST_F(VkLayerTest, RebindMemory) { |
| 2191 | VkResult err; |
| 2192 | bool pass; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2193 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2194 | m_errorMonitor->SetDesiredFailureMsg( |
| 2195 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2196 | "which has already been bound to mem object"); |
| 2197 | |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2198 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2199 | |
| 2200 | // Create an image, allocate memory, free it, and then try to bind it |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2201 | VkImage image; |
| 2202 | VkDeviceMemory mem1; |
| 2203 | VkDeviceMemory mem2; |
| 2204 | VkMemoryRequirements mem_reqs; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2205 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2206 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2207 | const int32_t tex_width = 32; |
| 2208 | const int32_t tex_height = 32; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2209 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2210 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2211 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2212 | image_create_info.pNext = NULL; |
| 2213 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2214 | image_create_info.format = tex_format; |
| 2215 | image_create_info.extent.width = tex_width; |
| 2216 | image_create_info.extent.height = tex_height; |
| 2217 | image_create_info.extent.depth = 1; |
| 2218 | image_create_info.mipLevels = 1; |
| 2219 | image_create_info.arrayLayers = 1; |
| 2220 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2221 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2222 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2223 | image_create_info.flags = 0; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2224 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2225 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2226 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2227 | mem_alloc.pNext = NULL; |
| 2228 | mem_alloc.allocationSize = 0; |
| 2229 | mem_alloc.memoryTypeIndex = 0; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2230 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2231 | // Introduce failure, do NOT set memProps to |
| 2232 | // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2233 | mem_alloc.memoryTypeIndex = 1; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2234 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2235 | ASSERT_VK_SUCCESS(err); |
| 2236 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2237 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2238 | |
| 2239 | mem_alloc.allocationSize = mem_reqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2240 | pass = |
| 2241 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 2242 | ASSERT_TRUE(pass); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2243 | |
| 2244 | // allocate 2 memory objects |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2245 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2246 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2247 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2248 | ASSERT_VK_SUCCESS(err); |
| 2249 | |
| 2250 | // Bind first memory object to Image object |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 2251 | err = vkBindImageMemory(m_device->device(), image, mem1, 0); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2252 | ASSERT_VK_SUCCESS(err); |
| 2253 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2254 | // Introduce validation failure, try to bind a different memory object to |
| 2255 | // the same image object |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 2256 | err = vkBindImageMemory(m_device->device(), image, mem2, 0); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2257 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2258 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2259 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2260 | vkDestroyImage(m_device->device(), image, NULL); |
| 2261 | vkFreeMemory(m_device->device(), mem1, NULL); |
| 2262 | vkFreeMemory(m_device->device(), mem2, NULL); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2263 | } |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2264 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2265 | TEST_F(VkLayerTest, SubmitSignaledFence) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2266 | vk_testing::Fence testFence; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2267 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2268 | m_errorMonitor->SetDesiredFailureMsg( |
| 2269 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences " |
| 2270 | "must be reset before being submitted"); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 2271 | |
| 2272 | VkFenceCreateInfo fenceInfo = {}; |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2273 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 2274 | fenceInfo.pNext = NULL; |
| 2275 | fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2276 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2277 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2278 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 2279 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 2280 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2281 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2282 | m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 2283 | m_stencil_clear_color, NULL); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2284 | EndCommandBuffer(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2285 | |
| 2286 | testFence.init(*m_device, fenceInfo); |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 2287 | |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 2288 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 2289 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 2290 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 2291 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 2292 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 2293 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 2294 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2295 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 2296 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 2297 | submit_info.pSignalSemaphores = NULL; |
Courtney Goeltzenleuchter | 646b907 | 2015-10-20 18:04:07 -0600 | [diff] [blame] | 2298 | |
| 2299 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2300 | vkQueueWaitIdle(m_device->m_queue); |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 2301 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2302 | m_errorMonitor->VerifyFound(); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2303 | } |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2304 | // This is a positive test. We used to expect error in this case but spec now |
| 2305 | // allows it |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2306 | TEST_F(VkLayerTest, ResetUnsignaledFence) { |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2307 | m_errorMonitor->ExpectSuccess(); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2308 | vk_testing::Fence testFence; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 2309 | VkFenceCreateInfo fenceInfo = {}; |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2310 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 2311 | fenceInfo.pNext = NULL; |
| 2312 | |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2313 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2314 | testFence.init(*m_device, fenceInfo); |
Chia-I Wu | d9e8e82 | 2015-07-03 11:45:55 +0800 | [diff] [blame] | 2315 | VkFence fences[1] = {testFence.handle()}; |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2316 | VkResult result = vkResetFences(m_device->device(), 1, fences); |
| 2317 | ASSERT_VK_SUCCESS(result); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2318 | |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2319 | m_errorMonitor->VerifyNotFound(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2320 | } |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2321 | |
Chris Forbes | e70b7d3 | 2016-06-15 15:49:12 +1200 | [diff] [blame] | 2322 | #if 0 |
| 2323 | TEST_F(VkLayerTest, LongFenceChain) |
| 2324 | { |
| 2325 | m_errorMonitor->ExpectSuccess(); |
| 2326 | |
| 2327 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2328 | VkResult err; |
| 2329 | |
| 2330 | std::vector<VkFence> fences; |
| 2331 | |
| 2332 | const int chainLength = 32768; |
| 2333 | |
| 2334 | for (int i = 0; i < chainLength; i++) { |
| 2335 | VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 }; |
| 2336 | VkFence fence; |
| 2337 | err = vkCreateFence(m_device->device(), &fci, nullptr, &fence); |
| 2338 | ASSERT_VK_SUCCESS(err); |
| 2339 | |
| 2340 | fences.push_back(fence); |
| 2341 | |
| 2342 | VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, |
| 2343 | 0, nullptr, 0, nullptr }; |
| 2344 | err = vkQueueSubmit(m_device->m_queue, 1, &si, fence); |
| 2345 | ASSERT_VK_SUCCESS(err); |
| 2346 | |
| 2347 | } |
| 2348 | |
| 2349 | // BOOM, stack overflow. |
| 2350 | vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX); |
| 2351 | |
| 2352 | for (auto fence : fences) |
| 2353 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 2354 | |
| 2355 | m_errorMonitor->VerifyNotFound(); |
| 2356 | } |
| 2357 | #endif |
| 2358 | |
Chris Forbes | 18127d1 | 2016-06-08 16:52:28 +1200 | [diff] [blame] | 2359 | TEST_F(VkLayerTest, CommandBufferSimultaneousUseSync) |
| 2360 | { |
| 2361 | m_errorMonitor->ExpectSuccess(); |
| 2362 | |
| 2363 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2364 | VkResult err; |
| 2365 | |
| 2366 | // Record (empty!) command buffer that can be submitted multiple times |
| 2367 | // simultaneously. |
| 2368 | VkCommandBufferBeginInfo cbbi = { |
| 2369 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, |
| 2370 | VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr |
| 2371 | }; |
| 2372 | m_commandBuffer->BeginCommandBuffer(&cbbi); |
| 2373 | m_commandBuffer->EndCommandBuffer(); |
| 2374 | |
| 2375 | VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 }; |
| 2376 | VkFence fence; |
| 2377 | err = vkCreateFence(m_device->device(), &fci, nullptr, &fence); |
| 2378 | ASSERT_VK_SUCCESS(err); |
| 2379 | |
| 2380 | VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 }; |
| 2381 | VkSemaphore s1, s2; |
| 2382 | err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1); |
| 2383 | ASSERT_VK_SUCCESS(err); |
| 2384 | err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2); |
| 2385 | ASSERT_VK_SUCCESS(err); |
| 2386 | |
| 2387 | // Submit CB once signaling s1, with fence so we can roll forward to its retirement. |
| 2388 | VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, |
| 2389 | 1, &m_commandBuffer->handle(), 1, &s1 }; |
| 2390 | err = vkQueueSubmit(m_device->m_queue, 1, &si, fence); |
| 2391 | ASSERT_VK_SUCCESS(err); |
| 2392 | |
| 2393 | // Submit CB again, signaling s2. |
| 2394 | si.pSignalSemaphores = &s2; |
| 2395 | err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE); |
| 2396 | ASSERT_VK_SUCCESS(err); |
| 2397 | |
| 2398 | // Wait for fence. |
| 2399 | err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 2400 | ASSERT_VK_SUCCESS(err); |
| 2401 | |
| 2402 | // CB is still in flight from second submission, but semaphore s1 is no |
| 2403 | // longer in flight. delete it. |
| 2404 | vkDestroySemaphore(m_device->device(), s1, nullptr); |
| 2405 | |
| 2406 | m_errorMonitor->VerifyNotFound(); |
| 2407 | |
| 2408 | // Force device idle and clean up remaining objects |
| 2409 | vkDeviceWaitIdle(m_device->device()); |
| 2410 | vkDestroySemaphore(m_device->device(), s2, nullptr); |
| 2411 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 2412 | } |
| 2413 | |
Chris Forbes | 4e44c91 | 2016-06-16 10:20:00 +1200 | [diff] [blame] | 2414 | TEST_F(VkLayerTest, FenceCreateSignaledWaitHandling) |
| 2415 | { |
| 2416 | m_errorMonitor->ExpectSuccess(); |
| 2417 | |
| 2418 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2419 | VkResult err; |
| 2420 | |
| 2421 | // A fence created signaled |
| 2422 | VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT }; |
| 2423 | VkFence f1; |
| 2424 | err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1); |
| 2425 | ASSERT_VK_SUCCESS(err); |
| 2426 | |
| 2427 | // A fence created not |
| 2428 | VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 }; |
| 2429 | VkFence f2; |
| 2430 | err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2); |
| 2431 | ASSERT_VK_SUCCESS(err); |
| 2432 | |
| 2433 | // Submit the unsignaled fence |
| 2434 | VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, |
| 2435 | 0, nullptr, 0, nullptr }; |
| 2436 | err = vkQueueSubmit(m_device->m_queue, 1, &si, f2); |
| 2437 | |
| 2438 | // Wait on both fences, with signaled first. |
| 2439 | VkFence fences[] = { f1, f2 }; |
| 2440 | vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX); |
| 2441 | |
| 2442 | // Should have both retired! |
| 2443 | vkDestroyFence(m_device->device(), f1, nullptr); |
| 2444 | vkDestroyFence(m_device->device(), f2, nullptr); |
| 2445 | |
| 2446 | m_errorMonitor->VerifyNotFound(); |
| 2447 | } |
| 2448 | |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2449 | TEST_F(VkLayerTest, InvalidUsageBits) |
| 2450 | { |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2451 | TEST_DESCRIPTION( |
Karl Schultz | b5bc11e | 2016-05-04 08:36:08 -0600 | [diff] [blame] | 2452 | "Specify wrong usage for image then create conflicting view of image " |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2453 | "Initialize buffer with wrong usage then perform copy expecting errors " |
| 2454 | "from both the image and the buffer (2 calls)"); |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2455 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2456 | "Invalid usage flag for image "); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2457 | |
| 2458 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2459 | VkImageObj image(m_device); |
| 2460 | // Initialize image with USAGE_INPUT_ATTACHMENT |
Tobin Ehlis | 8b313c0 | 2016-05-25 15:01:52 -0600 | [diff] [blame] | 2461 | image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, |
Karl Schultz | b5bc11e | 2016-05-04 08:36:08 -0600 | [diff] [blame] | 2462 | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 2463 | ASSERT_TRUE(image.initialized()); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2464 | |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2465 | VkImageView dsv; |
| 2466 | VkImageViewCreateInfo dsvci = {}; |
| 2467 | dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 2468 | dsvci.image = image.handle(); |
| 2469 | dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 2470 | dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT; |
| 2471 | dsvci.subresourceRange.layerCount = 1; |
| 2472 | dsvci.subresourceRange.baseMipLevel = 0; |
| 2473 | dsvci.subresourceRange.levelCount = 1; |
| 2474 | dsvci.subresourceRange.aspectMask = |
| 2475 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2476 | |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2477 | // Create a view with depth / stencil aspect for image with different usage |
| 2478 | vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2479 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2480 | m_errorMonitor->VerifyFound(); |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2481 | |
| 2482 | // Initialize buffer with TRANSFER_DST usage |
| 2483 | vk_testing::Buffer buffer; |
| 2484 | VkMemoryPropertyFlags reqs = 0; |
| 2485 | buffer.init_as_dst(*m_device, 128 * 128, reqs); |
| 2486 | VkBufferImageCopy region = {}; |
| 2487 | region.bufferRowLength = 128; |
| 2488 | region.bufferImageHeight = 128; |
| 2489 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 2490 | region.imageSubresource.layerCount = 1; |
| 2491 | region.imageExtent.height = 16; |
| 2492 | region.imageExtent.width = 16; |
| 2493 | region.imageExtent.depth = 1; |
| 2494 | |
| 2495 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2496 | "Invalid usage flag for buffer "); |
| 2497 | // Buffer usage not set to TRANSFER_SRC and image usage not set to |
| 2498 | // TRANSFER_DST |
| 2499 | BeginCommandBuffer(); |
| 2500 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 2501 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 2502 | 1, ®ion); |
| 2503 | m_errorMonitor->VerifyFound(); |
| 2504 | |
| 2505 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2506 | "Invalid usage flag for image "); |
| 2507 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 2508 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 2509 | 1, ®ion); |
| 2510 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2511 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 2512 | #endif // MEM_TRACKER_TESTS |
| 2513 | |
Tobin Ehlis | 4bf96d1 | 2015-06-25 11:58:41 -0600 | [diff] [blame] | 2514 | #if OBJ_TRACKER_TESTS |
Mark Lobodzinski | fc5cc66 | 2016-05-02 17:17:41 -0600 | [diff] [blame] | 2515 | |
| 2516 | TEST_F(VkLayerTest, LeakAnObject) { |
| 2517 | VkResult err; |
| 2518 | |
| 2519 | TEST_DESCRIPTION( |
| 2520 | "Create a fence and destroy its device without first destroying the fence."); |
| 2521 | |
| 2522 | // Note that we have to create a new device since destroying the |
| 2523 | // framework's device causes Teardown() to fail and just calling Teardown |
| 2524 | // will destroy the errorMonitor. |
| 2525 | |
| 2526 | m_errorMonitor->SetDesiredFailureMsg( |
| 2527 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2528 | "OBJ ERROR : VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT object"); |
| 2529 | |
| 2530 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2531 | |
| 2532 | const std::vector<VkQueueFamilyProperties> queue_props = |
| 2533 | m_device->queue_props; |
| 2534 | std::vector<VkDeviceQueueCreateInfo> queue_info; |
| 2535 | queue_info.reserve(queue_props.size()); |
| 2536 | std::vector<std::vector<float>> queue_priorities; |
| 2537 | for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) { |
| 2538 | VkDeviceQueueCreateInfo qi = {}; |
| 2539 | qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; |
| 2540 | qi.pNext = NULL; |
| 2541 | qi.queueFamilyIndex = i; |
| 2542 | qi.queueCount = queue_props[i].queueCount; |
| 2543 | queue_priorities.emplace_back(qi.queueCount, 0.0f); |
| 2544 | qi.pQueuePriorities = queue_priorities[i].data(); |
| 2545 | queue_info.push_back(qi); |
| 2546 | } |
| 2547 | |
| 2548 | std::vector<const char *> device_layer_names; |
| 2549 | std::vector<const char *> device_extension_names; |
| 2550 | device_layer_names.push_back("VK_LAYER_GOOGLE_threading"); |
| 2551 | device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation"); |
| 2552 | device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker"); |
| 2553 | device_layer_names.push_back("VK_LAYER_LUNARG_core_validation"); |
| 2554 | device_layer_names.push_back("VK_LAYER_LUNARG_device_limits"); |
| 2555 | device_layer_names.push_back("VK_LAYER_LUNARG_image"); |
| 2556 | device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects"); |
| 2557 | |
| 2558 | // The sacrificial device object |
| 2559 | VkDevice testDevice; |
| 2560 | VkDeviceCreateInfo device_create_info = {}; |
| 2561 | auto features = m_device->phy().features(); |
| 2562 | device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; |
| 2563 | device_create_info.pNext = NULL; |
| 2564 | device_create_info.queueCreateInfoCount = queue_info.size(); |
| 2565 | device_create_info.pQueueCreateInfos = queue_info.data(); |
| 2566 | device_create_info.enabledLayerCount = device_layer_names.size(); |
| 2567 | device_create_info.ppEnabledLayerNames = device_layer_names.data(); |
| 2568 | device_create_info.pEnabledFeatures = &features; |
| 2569 | err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice); |
| 2570 | ASSERT_VK_SUCCESS(err); |
| 2571 | |
| 2572 | VkFence fence; |
| 2573 | VkFenceCreateInfo fence_create_info = {}; |
| 2574 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 2575 | fence_create_info.pNext = NULL; |
| 2576 | fence_create_info.flags = 0; |
| 2577 | err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence); |
| 2578 | ASSERT_VK_SUCCESS(err); |
| 2579 | |
| 2580 | // Induce failure by not calling vkDestroyFence |
| 2581 | vkDestroyDevice(testDevice, NULL); |
| 2582 | m_errorMonitor->VerifyFound(); |
| 2583 | } |
| 2584 | |
| 2585 | TEST_F(VkLayerTest, InvalidCommandPoolConsistency) { |
| 2586 | |
| 2587 | TEST_DESCRIPTION("Allocate command buffers from one command pool and " |
| 2588 | "attempt to delete them from another."); |
| 2589 | |
| 2590 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2591 | "FreeCommandBuffers is attempting to free Command Buffer"); |
| 2592 | |
| 2593 | VkCommandPool command_pool_one; |
| 2594 | VkCommandPool command_pool_two; |
| 2595 | |
| 2596 | VkCommandPoolCreateInfo pool_create_info{}; |
| 2597 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 2598 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 2599 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 2600 | |
| 2601 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 2602 | &command_pool_one); |
| 2603 | |
| 2604 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 2605 | &command_pool_two); |
| 2606 | |
| 2607 | VkCommandBuffer command_buffer[9]; |
| 2608 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 2609 | command_buffer_allocate_info.sType = |
| 2610 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 2611 | command_buffer_allocate_info.commandPool = command_pool_one; |
| 2612 | command_buffer_allocate_info.commandBufferCount = 9; |
| 2613 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 2614 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 2615 | command_buffer); |
| 2616 | |
| 2617 | vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, |
| 2618 | &command_buffer[3]); |
| 2619 | |
| 2620 | m_errorMonitor->VerifyFound(); |
| 2621 | |
| 2622 | vkDestroyCommandPool(m_device->device(), command_pool_one, NULL); |
| 2623 | vkDestroyCommandPool(m_device->device(), command_pool_two, NULL); |
| 2624 | } |
| 2625 | |
| 2626 | TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) { |
| 2627 | VkResult err; |
| 2628 | |
| 2629 | TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and " |
| 2630 | "attempt to delete them from another."); |
| 2631 | |
| 2632 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2633 | "FreeDescriptorSets is attempting to free descriptorSet"); |
| 2634 | |
| 2635 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2636 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 2637 | |
| 2638 | VkDescriptorPoolSize ds_type_count = {}; |
| 2639 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 2640 | ds_type_count.descriptorCount = 1; |
| 2641 | |
| 2642 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 2643 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 2644 | ds_pool_ci.pNext = NULL; |
| 2645 | ds_pool_ci.flags = 0; |
| 2646 | ds_pool_ci.maxSets = 1; |
| 2647 | ds_pool_ci.poolSizeCount = 1; |
| 2648 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 2649 | |
| 2650 | VkDescriptorPool ds_pool_one; |
| 2651 | err = |
| 2652 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one); |
| 2653 | ASSERT_VK_SUCCESS(err); |
| 2654 | |
| 2655 | // Create a second descriptor pool |
| 2656 | VkDescriptorPool ds_pool_two; |
| 2657 | err = |
| 2658 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two); |
| 2659 | ASSERT_VK_SUCCESS(err); |
| 2660 | |
| 2661 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 2662 | dsl_binding.binding = 0; |
| 2663 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 2664 | dsl_binding.descriptorCount = 1; |
| 2665 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 2666 | dsl_binding.pImmutableSamplers = NULL; |
| 2667 | |
| 2668 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 2669 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 2670 | ds_layout_ci.pNext = NULL; |
| 2671 | ds_layout_ci.bindingCount = 1; |
| 2672 | ds_layout_ci.pBindings = &dsl_binding; |
| 2673 | |
| 2674 | VkDescriptorSetLayout ds_layout; |
| 2675 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 2676 | &ds_layout); |
| 2677 | ASSERT_VK_SUCCESS(err); |
| 2678 | |
| 2679 | VkDescriptorSet descriptorSet; |
| 2680 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 2681 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 2682 | alloc_info.descriptorSetCount = 1; |
| 2683 | alloc_info.descriptorPool = ds_pool_one; |
| 2684 | alloc_info.pSetLayouts = &ds_layout; |
| 2685 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 2686 | &descriptorSet); |
| 2687 | ASSERT_VK_SUCCESS(err); |
| 2688 | |
| 2689 | err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet); |
| 2690 | |
| 2691 | m_errorMonitor->VerifyFound(); |
| 2692 | |
| 2693 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 2694 | vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL); |
| 2695 | vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL); |
| 2696 | } |
| 2697 | |
| 2698 | TEST_F(VkLayerTest, CreateUnknownObject) { |
| 2699 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2700 | "Invalid VkImage Object "); |
| 2701 | |
| 2702 | TEST_DESCRIPTION( |
| 2703 | "Pass an invalid image object handle into a Vulkan API call."); |
| 2704 | |
| 2705 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2706 | |
| 2707 | // Pass bogus handle into GetImageMemoryRequirements |
| 2708 | VkMemoryRequirements mem_reqs; |
| 2709 | uint64_t fakeImageHandle = 0xCADECADE; |
| 2710 | VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle); |
| 2711 | |
| 2712 | vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs); |
| 2713 | |
| 2714 | m_errorMonitor->VerifyFound(); |
| 2715 | } |
| 2716 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2717 | TEST_F(VkLayerTest, PipelineNotBound) { |
| 2718 | VkResult err; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2719 | |
Mark Lobodzinski | fc5cc66 | 2016-05-02 17:17:41 -0600 | [diff] [blame] | 2720 | TEST_DESCRIPTION( |
| 2721 | "Pass in an invalid pipeline object handle into a Vulkan API call."); |
| 2722 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2723 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2724 | "Invalid VkPipeline Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2725 | |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2726 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2727 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2728 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 2729 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2730 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 2731 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2732 | |
| 2733 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2734 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 2735 | ds_pool_ci.pNext = NULL; |
| 2736 | ds_pool_ci.maxSets = 1; |
| 2737 | ds_pool_ci.poolSizeCount = 1; |
| 2738 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2739 | |
| 2740 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2741 | err = |
| 2742 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2743 | ASSERT_VK_SUCCESS(err); |
| 2744 | |
| 2745 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2746 | dsl_binding.binding = 0; |
| 2747 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 2748 | dsl_binding.descriptorCount = 1; |
| 2749 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 2750 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2751 | |
| 2752 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2753 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 2754 | ds_layout_ci.pNext = NULL; |
| 2755 | ds_layout_ci.bindingCount = 1; |
| 2756 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2757 | |
| 2758 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2759 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 2760 | &ds_layout); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2761 | ASSERT_VK_SUCCESS(err); |
| 2762 | |
| 2763 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2764 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 2765 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 2766 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 2767 | alloc_info.descriptorPool = ds_pool; |
| 2768 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2769 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 2770 | &descriptorSet); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2771 | ASSERT_VK_SUCCESS(err); |
| 2772 | |
| 2773 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2774 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 2775 | pipeline_layout_ci.pNext = NULL; |
| 2776 | pipeline_layout_ci.setLayoutCount = 1; |
| 2777 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2778 | |
| 2779 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2780 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 2781 | &pipeline_layout); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2782 | ASSERT_VK_SUCCESS(err); |
| 2783 | |
Mark Young | ad77905 | 2016-01-06 14:26:04 -0700 | [diff] [blame] | 2784 | VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2785 | |
| 2786 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2787 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 2788 | VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2789 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2790 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2791 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2792 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 2793 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 2794 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2795 | } |
Tobin Ehlis | 93d57e1 | 2016-06-20 11:32:13 -0600 | [diff] [blame] | 2796 | #if 0 // Disabling this test for now, needs to be updated |
Mark Lobodzinski | bc18576 | 2016-06-15 16:28:53 -0600 | [diff] [blame] | 2797 | TEST_F(VkLayerTest, BindImageInvalidMemoryType) { |
| 2798 | VkResult err; |
| 2799 | |
| 2800 | TEST_DESCRIPTION("Test validation check for an invalid memory type index " |
| 2801 | "during bind[Buffer|Image]Memory time"); |
| 2802 | |
| 2803 | m_errorMonitor->SetDesiredFailureMsg( |
| 2804 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2805 | "for this object type are not compatible with the memory"); |
| 2806 | |
| 2807 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2808 | |
| 2809 | // Create an image, allocate memory, set a bad typeIndex and then try to |
| 2810 | // bind it |
| 2811 | VkImage image; |
| 2812 | VkDeviceMemory mem; |
| 2813 | VkMemoryRequirements mem_reqs; |
| 2814 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2815 | const int32_t tex_width = 32; |
| 2816 | const int32_t tex_height = 32; |
| 2817 | |
| 2818 | VkImageCreateInfo image_create_info = {}; |
| 2819 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2820 | image_create_info.pNext = NULL; |
| 2821 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2822 | image_create_info.format = tex_format; |
| 2823 | image_create_info.extent.width = tex_width; |
| 2824 | image_create_info.extent.height = tex_height; |
| 2825 | image_create_info.extent.depth = 1; |
| 2826 | image_create_info.mipLevels = 1; |
| 2827 | image_create_info.arrayLayers = 1; |
| 2828 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2829 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 2830 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2831 | image_create_info.flags = 0; |
| 2832 | |
| 2833 | VkMemoryAllocateInfo mem_alloc = {}; |
| 2834 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2835 | mem_alloc.pNext = NULL; |
| 2836 | mem_alloc.allocationSize = 0; |
| 2837 | mem_alloc.memoryTypeIndex = 0; |
| 2838 | |
| 2839 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 2840 | ASSERT_VK_SUCCESS(err); |
| 2841 | |
| 2842 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 2843 | mem_alloc.allocationSize = mem_reqs.size; |
Tobin Ehlis | 93d57e1 | 2016-06-20 11:32:13 -0600 | [diff] [blame] | 2844 | // TODO : This is not an ideal way to cause the error and triggers a segF |
| 2845 | // on at least one android driver when attempting to Allocate the memory. |
| 2846 | // That segF may or may not be a driver bug, but really what we want to do |
| 2847 | // here is find a device-supported memory type that is also not supported |
| 2848 | // for the particular image we're binding the memory too. If no such |
| 2849 | // type exists, then we can print a message and skip the test. |
Mark Lobodzinski | bc18576 | 2016-06-15 16:28:53 -0600 | [diff] [blame] | 2850 | // Introduce Failure, select likely invalid TypeIndex |
| 2851 | mem_alloc.memoryTypeIndex = 31; |
| 2852 | |
| 2853 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 2854 | ASSERT_VK_SUCCESS(err); |
| 2855 | |
| 2856 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 2857 | (void)err; |
| 2858 | |
| 2859 | m_errorMonitor->VerifyFound(); |
| 2860 | |
| 2861 | vkDestroyImage(m_device->device(), image, NULL); |
| 2862 | vkFreeMemory(m_device->device(), mem, NULL); |
| 2863 | } |
Tobin Ehlis | 93d57e1 | 2016-06-20 11:32:13 -0600 | [diff] [blame] | 2864 | #endif |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2865 | TEST_F(VkLayerTest, BindInvalidMemory) { |
| 2866 | VkResult err; |
| 2867 | bool pass; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2868 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2869 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2870 | "Invalid VkDeviceMemory Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2871 | |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2872 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2873 | |
| 2874 | // Create an image, allocate memory, free it, and then try to bind it |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2875 | VkImage image; |
| 2876 | VkDeviceMemory mem; |
| 2877 | VkMemoryRequirements mem_reqs; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2878 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2879 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2880 | const int32_t tex_width = 32; |
| 2881 | const int32_t tex_height = 32; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2882 | |
| 2883 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2884 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2885 | image_create_info.pNext = NULL; |
| 2886 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2887 | image_create_info.format = tex_format; |
| 2888 | image_create_info.extent.width = tex_width; |
| 2889 | image_create_info.extent.height = tex_height; |
| 2890 | image_create_info.extent.depth = 1; |
| 2891 | image_create_info.mipLevels = 1; |
| 2892 | image_create_info.arrayLayers = 1; |
| 2893 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2894 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2895 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2896 | image_create_info.flags = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2897 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2898 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2899 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2900 | mem_alloc.pNext = NULL; |
| 2901 | mem_alloc.allocationSize = 0; |
| 2902 | mem_alloc.memoryTypeIndex = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2903 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2904 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2905 | ASSERT_VK_SUCCESS(err); |
| 2906 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2907 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2908 | |
| 2909 | mem_alloc.allocationSize = mem_reqs.size; |
| 2910 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2911 | pass = |
| 2912 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 2913 | ASSERT_TRUE(pass); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2914 | |
| 2915 | // allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2916 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2917 | ASSERT_VK_SUCCESS(err); |
| 2918 | |
| 2919 | // Introduce validation failure, free memory before binding |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2920 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2921 | |
| 2922 | // Try to bind free memory that has been freed |
| 2923 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 2924 | // This may very well return an error. |
| 2925 | (void)err; |
| 2926 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2927 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2928 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2929 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2930 | } |
| 2931 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2932 | TEST_F(VkLayerTest, BindMemoryToDestroyedObject) { |
| 2933 | VkResult err; |
| 2934 | bool pass; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2935 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2936 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2937 | "Invalid VkImage Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2938 | |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2939 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2940 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2941 | // Create an image object, allocate memory, destroy the object and then try |
| 2942 | // to bind it |
| 2943 | VkImage image; |
| 2944 | VkDeviceMemory mem; |
| 2945 | VkMemoryRequirements mem_reqs; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2946 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2947 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2948 | const int32_t tex_width = 32; |
| 2949 | const int32_t tex_height = 32; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2950 | |
| 2951 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2952 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2953 | image_create_info.pNext = NULL; |
| 2954 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2955 | image_create_info.format = tex_format; |
| 2956 | image_create_info.extent.width = tex_width; |
| 2957 | image_create_info.extent.height = tex_height; |
| 2958 | image_create_info.extent.depth = 1; |
| 2959 | image_create_info.mipLevels = 1; |
| 2960 | image_create_info.arrayLayers = 1; |
| 2961 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2962 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2963 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2964 | image_create_info.flags = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2965 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2966 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2967 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2968 | mem_alloc.pNext = NULL; |
| 2969 | mem_alloc.allocationSize = 0; |
| 2970 | mem_alloc.memoryTypeIndex = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2971 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2972 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2973 | ASSERT_VK_SUCCESS(err); |
| 2974 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2975 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2976 | |
| 2977 | mem_alloc.allocationSize = mem_reqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2978 | pass = |
| 2979 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 2980 | ASSERT_TRUE(pass); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2981 | |
| 2982 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2983 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2984 | ASSERT_VK_SUCCESS(err); |
| 2985 | |
| 2986 | // Introduce validation failure, destroy Image object before binding |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2987 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2988 | ASSERT_VK_SUCCESS(err); |
| 2989 | |
| 2990 | // Now Try to bind memory to this destroyed object |
| 2991 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 2992 | // This may very well return an error. |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2993 | (void)err; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2994 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2995 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2996 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2997 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2998 | } |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 2999 | |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 3000 | #endif // OBJ_TRACKER_TESTS |
| 3001 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 3002 | #if DRAW_STATE_TESTS |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3003 | |
Mark Lobodzinski | ce7eee7 | 2016-06-14 16:33:29 -0600 | [diff] [blame] | 3004 | // This is a positive test. No errors are expected. |
| 3005 | TEST_F(VkLayerTest, StencilLoadOp) { |
| 3006 | TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to " |
| 3007 | "CLEAR. stencil[Load|Store]Op used to be ignored."); |
| 3008 | VkResult result = VK_SUCCESS; |
| 3009 | VkImageFormatProperties formatProps; |
| 3010 | vkGetPhysicalDeviceImageFormatProperties( |
| 3011 | gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, |
| 3012 | VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 3013 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, |
| 3014 | 0, &formatProps); |
| 3015 | if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) { |
| 3016 | return; |
| 3017 | } |
| 3018 | |
| 3019 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3020 | VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT; |
| 3021 | m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt, |
| 3022 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 3023 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT); |
| 3024 | VkAttachmentDescription att = {}; |
| 3025 | VkAttachmentReference ref = {}; |
| 3026 | att.format = depth_stencil_fmt; |
| 3027 | att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 3028 | att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 3029 | att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 3030 | att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE; |
| 3031 | att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3032 | att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3033 | |
| 3034 | VkClearValue clear; |
| 3035 | clear.depthStencil.depth = 1.0; |
| 3036 | clear.depthStencil.stencil = 0; |
| 3037 | ref.attachment = 0; |
| 3038 | ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3039 | |
| 3040 | VkSubpassDescription subpass = {}; |
| 3041 | subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; |
| 3042 | subpass.flags = 0; |
| 3043 | subpass.inputAttachmentCount = 0; |
| 3044 | subpass.pInputAttachments = NULL; |
| 3045 | subpass.colorAttachmentCount = 0; |
| 3046 | subpass.pColorAttachments = NULL; |
| 3047 | subpass.pResolveAttachments = NULL; |
| 3048 | subpass.pDepthStencilAttachment = &ref; |
| 3049 | subpass.preserveAttachmentCount = 0; |
| 3050 | subpass.pPreserveAttachments = NULL; |
| 3051 | |
| 3052 | VkRenderPass rp; |
| 3053 | VkRenderPassCreateInfo rp_info = {}; |
| 3054 | rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 3055 | rp_info.attachmentCount = 1; |
| 3056 | rp_info.pAttachments = &att; |
| 3057 | rp_info.subpassCount = 1; |
| 3058 | rp_info.pSubpasses = &subpass; |
| 3059 | result = vkCreateRenderPass(device(), &rp_info, NULL, &rp); |
| 3060 | ASSERT_VK_SUCCESS(result); |
| 3061 | |
| 3062 | VkImageView *depthView = m_depthStencil->BindInfo(); |
| 3063 | VkFramebufferCreateInfo fb_info = {}; |
| 3064 | fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
| 3065 | fb_info.pNext = NULL; |
| 3066 | fb_info.renderPass = rp; |
| 3067 | fb_info.attachmentCount = 1; |
| 3068 | fb_info.pAttachments = depthView; |
| 3069 | fb_info.width = 100; |
| 3070 | fb_info.height = 100; |
| 3071 | fb_info.layers = 1; |
| 3072 | VkFramebuffer fb; |
| 3073 | result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3074 | ASSERT_VK_SUCCESS(result); |
| 3075 | |
| 3076 | |
| 3077 | VkRenderPassBeginInfo rpbinfo = {}; |
| 3078 | rpbinfo.clearValueCount = 1; |
| 3079 | rpbinfo.pClearValues = &clear; |
| 3080 | rpbinfo.pNext = NULL; |
| 3081 | rpbinfo.renderPass = rp; |
| 3082 | rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 3083 | rpbinfo.renderArea.extent.width = 100; |
| 3084 | rpbinfo.renderArea.extent.height = 100; |
| 3085 | rpbinfo.renderArea.offset.x = 0; |
| 3086 | rpbinfo.renderArea.offset.y = 0; |
| 3087 | rpbinfo.framebuffer = fb; |
| 3088 | |
| 3089 | VkFence fence = {}; |
| 3090 | VkFenceCreateInfo fence_ci = {}; |
| 3091 | fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3092 | fence_ci.pNext = nullptr; |
| 3093 | fence_ci.flags = 0; |
| 3094 | result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence); |
| 3095 | ASSERT_VK_SUCCESS(result); |
| 3096 | |
| 3097 | |
| 3098 | m_commandBuffer->BeginCommandBuffer(); |
| 3099 | m_commandBuffer->BeginRenderPass(rpbinfo); |
| 3100 | m_commandBuffer->EndRenderPass(); |
| 3101 | m_commandBuffer->EndCommandBuffer(); |
| 3102 | m_commandBuffer->QueueCommandBuffer(fence); |
| 3103 | |
| 3104 | VkImageObj destImage(m_device); |
| 3105 | destImage.init(100, 100, depth_stencil_fmt, |
| 3106 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 3107 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 3108 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 3109 | VkImageMemoryBarrier barrier = {}; |
| 3110 | VkImageSubresourceRange range; |
| 3111 | barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 3112 | barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | |
| 3113 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; |
| 3114 | barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | |
| 3115 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT; |
| 3116 | barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3117 | barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 3118 | barrier.image = m_depthStencil->handle(); |
| 3119 | range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3120 | range.baseMipLevel = 0; |
| 3121 | range.levelCount = 1; |
| 3122 | range.baseArrayLayer = 0; |
| 3123 | range.layerCount = 1; |
| 3124 | barrier.subresourceRange = range; |
| 3125 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 3126 | VkCommandBufferObj cmdbuf(m_device, m_commandPool); |
| 3127 | cmdbuf.BeginCommandBuffer(); |
| 3128 | cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3129 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, |
| 3130 | nullptr, 1, &barrier); |
| 3131 | barrier.srcAccessMask = 0; |
| 3132 | barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 3133 | barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; |
| 3134 | barrier.image = destImage.handle(); |
| 3135 | barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | |
| 3136 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; |
| 3137 | cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3138 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, |
| 3139 | nullptr, 1, &barrier); |
| 3140 | VkImageCopy cregion; |
| 3141 | cregion.srcSubresource.aspectMask = |
| 3142 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3143 | cregion.srcSubresource.mipLevel = 0; |
| 3144 | cregion.srcSubresource.baseArrayLayer = 0; |
| 3145 | cregion.srcSubresource.layerCount = 1; |
| 3146 | cregion.srcOffset.x = 0; |
| 3147 | cregion.srcOffset.y = 0; |
| 3148 | cregion.srcOffset.z = 0; |
| 3149 | cregion.dstSubresource.aspectMask = |
| 3150 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3151 | cregion.dstSubresource.mipLevel = 0; |
| 3152 | cregion.dstSubresource.baseArrayLayer = 0; |
| 3153 | cregion.dstSubresource.layerCount = 1; |
| 3154 | cregion.dstOffset.x = 0; |
| 3155 | cregion.dstOffset.y = 0; |
| 3156 | cregion.dstOffset.z = 0; |
| 3157 | cregion.extent.width = 100; |
| 3158 | cregion.extent.height = 100; |
| 3159 | cregion.extent.depth = 1; |
| 3160 | cmdbuf.CopyImage(m_depthStencil->handle(), |
| 3161 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(), |
| 3162 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion); |
| 3163 | cmdbuf.EndCommandBuffer(); |
| 3164 | |
| 3165 | VkSubmitInfo submit_info; |
| 3166 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3167 | submit_info.pNext = NULL; |
| 3168 | submit_info.waitSemaphoreCount = 0; |
| 3169 | submit_info.pWaitSemaphores = NULL; |
| 3170 | submit_info.pWaitDstStageMask = NULL; |
| 3171 | submit_info.commandBufferCount = 1; |
| 3172 | submit_info.pCommandBuffers = &cmdbuf.handle(); |
| 3173 | submit_info.signalSemaphoreCount = 0; |
| 3174 | submit_info.pSignalSemaphores = NULL; |
| 3175 | |
| 3176 | m_errorMonitor->ExpectSuccess(); |
| 3177 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3178 | m_errorMonitor->VerifyNotFound(); |
| 3179 | |
Mark Lobodzinski | d0440da | 2016-06-17 15:10:03 -0600 | [diff] [blame] | 3180 | vkQueueWaitIdle(m_device->m_queue); |
Mark Lobodzinski | ce7eee7 | 2016-06-14 16:33:29 -0600 | [diff] [blame] | 3181 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 3182 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3183 | vkDestroyFramebuffer(m_device->device(), fb, nullptr); |
| 3184 | } |
| 3185 | |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3186 | TEST_F(VkLayerTest, UnusedPreserveAttachment) { |
| 3187 | TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve " |
| 3188 | "attachment reference of VK_ATTACHMENT_UNUSED"); |
| 3189 | |
| 3190 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3191 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 3192 | |
| 3193 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3194 | "must not be VK_ATTACHMENT_UNUSED"); |
| 3195 | |
| 3196 | VkAttachmentReference color_attach = {}; |
| 3197 | color_attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 3198 | color_attach.attachment = 0; |
| 3199 | uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED; |
| 3200 | VkSubpassDescription subpass = {}; |
| 3201 | subpass.colorAttachmentCount = 1; |
| 3202 | subpass.pColorAttachments = &color_attach; |
| 3203 | subpass.preserveAttachmentCount = 1; |
| 3204 | subpass.pPreserveAttachments = &preserve_attachment; |
| 3205 | |
| 3206 | VkRenderPassCreateInfo rpci = {}; |
| 3207 | rpci.subpassCount = 1; |
| 3208 | rpci.pSubpasses = &subpass; |
| 3209 | rpci.attachmentCount = 1; |
| 3210 | VkAttachmentDescription attach_desc = {}; |
| 3211 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 3212 | rpci.pAttachments = &attach_desc; |
| 3213 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 3214 | VkRenderPass rp; |
Mark Lobodzinski | a4feeeb | 2016-06-17 12:00:46 -0600 | [diff] [blame] | 3215 | VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3216 | |
| 3217 | m_errorMonitor->VerifyFound(); |
| 3218 | |
Mark Lobodzinski | a4feeeb | 2016-06-17 12:00:46 -0600 | [diff] [blame] | 3219 | if (result == VK_SUCCESS) { |
| 3220 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 3221 | } |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3222 | } |
| 3223 | |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3224 | TEST_F(VkLayerTest, FramebufferCreateErrors) { |
| 3225 | TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n" |
| 3226 | " 1. Mismatch between fb & renderPass attachmentCount\n" |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 3227 | " 2. Use a color image as depthStencil attachment\n" |
Tobin Ehlis | 77d717c | 2016-06-22 14:19:19 -0600 | [diff] [blame] | 3228 | " 3. Mismatch fb & renderPass attachment formats\n" |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 3229 | " 4. Mismatch fb & renderPass attachment #samples\n" |
Tobin Ehlis | 27f2ae8 | 2016-06-23 07:36:57 -0600 | [diff] [blame] | 3230 | " 5. FB attachment w/ non-1 mip-levels\n" |
Tobin Ehlis | b1f303b | 2016-06-23 08:19:55 -0600 | [diff] [blame] | 3231 | " 6. FB attachment where dimensions don't match\n" |
| 3232 | " 7. FB attachment w/o identity swizzle\n"); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3233 | |
| 3234 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3235 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 3236 | |
| 3237 | m_errorMonitor->SetDesiredFailureMsg( |
| 3238 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3239 | "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 " |
| 3240 | "does not match attachmentCount of 1 of "); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3241 | |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3242 | // Create a renderPass with a single color attachment |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3243 | VkAttachmentReference attach = {}; |
| 3244 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 3245 | VkSubpassDescription subpass = {}; |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3246 | subpass.pColorAttachments = &attach; |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3247 | VkRenderPassCreateInfo rpci = {}; |
| 3248 | rpci.subpassCount = 1; |
| 3249 | rpci.pSubpasses = &subpass; |
| 3250 | rpci.attachmentCount = 1; |
| 3251 | VkAttachmentDescription attach_desc = {}; |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 3252 | attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM; |
Tobin Ehlis | 77d717c | 2016-06-22 14:19:19 -0600 | [diff] [blame] | 3253 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3254 | rpci.pAttachments = &attach_desc; |
| 3255 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 3256 | VkRenderPass rp; |
| 3257 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3258 | ASSERT_VK_SUCCESS(err); |
| 3259 | |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3260 | VkImageView ivs[2]; |
| 3261 | ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM); |
| 3262 | ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3263 | VkFramebufferCreateInfo fb_info = {}; |
| 3264 | fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
| 3265 | fb_info.pNext = NULL; |
| 3266 | fb_info.renderPass = rp; |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3267 | // Set mis-matching attachmentCount |
| 3268 | fb_info.attachmentCount = 2; |
| 3269 | fb_info.pAttachments = ivs; |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3270 | fb_info.width = 100; |
| 3271 | fb_info.height = 100; |
| 3272 | fb_info.layers = 1; |
| 3273 | |
| 3274 | VkFramebuffer fb; |
| 3275 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3276 | |
| 3277 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3278 | if (err == VK_SUCCESS) { |
| 3279 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3280 | } |
| 3281 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 2545e6f | 2016-06-22 10:42:19 -0600 | [diff] [blame] | 3282 | |
| 3283 | // Create a renderPass with a depth-stencil attachment created with |
| 3284 | // IMAGE_USAGE_COLOR_ATTACHMENT |
| 3285 | // Add our color attachment to pDepthStencilAttachment |
| 3286 | subpass.pDepthStencilAttachment = &attach; |
| 3287 | subpass.pColorAttachments = NULL; |
| 3288 | VkRenderPass rp_ds; |
| 3289 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds); |
| 3290 | ASSERT_VK_SUCCESS(err); |
| 3291 | // Set correct attachment count, but attachment has COLOR usage bit set |
| 3292 | fb_info.attachmentCount = 1; |
| 3293 | fb_info.renderPass = rp_ds; |
| 3294 | |
| 3295 | m_errorMonitor->SetDesiredFailureMsg( |
| 3296 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3297 | " conflicts with the image's IMAGE_USAGE flags "); |
| 3298 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3299 | |
| 3300 | m_errorMonitor->VerifyFound(); |
| 3301 | if (err == VK_SUCCESS) { |
| 3302 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3303 | } |
| 3304 | vkDestroyRenderPass(m_device->device(), rp_ds, NULL); |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 3305 | |
| 3306 | // Create new renderpass with alternate attachment format from fb |
| 3307 | attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 3308 | subpass.pDepthStencilAttachment = NULL; |
| 3309 | subpass.pColorAttachments = &attach; |
| 3310 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3311 | ASSERT_VK_SUCCESS(err); |
| 3312 | |
| 3313 | // Cause error due to mis-matched formats between rp & fb |
| 3314 | // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8 |
| 3315 | fb_info.renderPass = rp; |
| 3316 | m_errorMonitor->SetDesiredFailureMsg( |
| 3317 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3318 | " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match "); |
| 3319 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3320 | |
| 3321 | m_errorMonitor->VerifyFound(); |
| 3322 | if (err == VK_SUCCESS) { |
| 3323 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3324 | } |
Tobin Ehlis | 77d717c | 2016-06-22 14:19:19 -0600 | [diff] [blame] | 3325 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 3326 | |
| 3327 | // Create new renderpass with alternate sample count from fb |
| 3328 | attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 3329 | attach_desc.samples = VK_SAMPLE_COUNT_4_BIT; |
| 3330 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3331 | ASSERT_VK_SUCCESS(err); |
| 3332 | |
| 3333 | // Cause error due to mis-matched sample count between rp & fb |
| 3334 | fb_info.renderPass = rp; |
| 3335 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3336 | " has VK_SAMPLE_COUNT_1_BIT samples " |
| 3337 | "that do not match the " |
| 3338 | "VK_SAMPLE_COUNT_4_BIT "); |
| 3339 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3340 | |
| 3341 | m_errorMonitor->VerifyFound(); |
| 3342 | if (err == VK_SUCCESS) { |
| 3343 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3344 | } |
Tobin Ehlis | d3bb23a | 2016-06-22 13:34:46 -0600 | [diff] [blame] | 3345 | |
| 3346 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 3347 | |
| 3348 | // Create a custom imageView with non-1 mip levels |
| 3349 | VkImageObj image(m_device); |
| 3350 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 3351 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 3352 | ASSERT_TRUE(image.initialized()); |
| 3353 | |
| 3354 | VkImageView view; |
| 3355 | VkImageViewCreateInfo ivci = {}; |
| 3356 | ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 3357 | ivci.image = image.handle(); |
| 3358 | ivci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 3359 | ivci.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 3360 | ivci.subresourceRange.layerCount = 1; |
| 3361 | ivci.subresourceRange.baseMipLevel = 0; |
| 3362 | // Set level count 2 (only 1 is allowed for FB attachment) |
| 3363 | ivci.subresourceRange.levelCount = 2; |
| 3364 | ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 3365 | err = vkCreateImageView(m_device->device(), &ivci, NULL, &view); |
| 3366 | ASSERT_VK_SUCCESS(err); |
| 3367 | // Re-create renderpass to have matching sample count |
| 3368 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
| 3369 | err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3370 | ASSERT_VK_SUCCESS(err); |
| 3371 | |
| 3372 | fb_info.renderPass = rp; |
| 3373 | fb_info.pAttachments = &view; |
| 3374 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3375 | " has mip levelCount of 2 but only "); |
| 3376 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3377 | |
| 3378 | m_errorMonitor->VerifyFound(); |
| 3379 | if (err == VK_SUCCESS) { |
| 3380 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3381 | } |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 3382 | vkDestroyImageView(m_device->device(), view, NULL); |
Tobin Ehlis | 27f2ae8 | 2016-06-23 07:36:57 -0600 | [diff] [blame] | 3383 | // Update view to original color buffer and grow FB dimensions too big |
| 3384 | fb_info.pAttachments = ivs; |
| 3385 | fb_info.height = 1024; |
| 3386 | fb_info.width = 1024; |
| 3387 | fb_info.layers = 2; |
| 3388 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3389 | " Attachment dimensions must be at " |
| 3390 | "least as large. "); |
| 3391 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3392 | |
| 3393 | m_errorMonitor->VerifyFound(); |
| 3394 | if (err == VK_SUCCESS) { |
| 3395 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3396 | } |
Tobin Ehlis | b1f303b | 2016-06-23 08:19:55 -0600 | [diff] [blame] | 3397 | // Create view attachment with non-identity swizzle |
| 3398 | ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 3399 | ivci.image = image.handle(); |
| 3400 | ivci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 3401 | ivci.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 3402 | ivci.subresourceRange.layerCount = 1; |
| 3403 | ivci.subresourceRange.baseMipLevel = 0; |
| 3404 | ivci.subresourceRange.levelCount = 1; |
| 3405 | ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 3406 | ivci.components.r = VK_COMPONENT_SWIZZLE_G; |
| 3407 | ivci.components.g = VK_COMPONENT_SWIZZLE_R; |
| 3408 | ivci.components.b = VK_COMPONENT_SWIZZLE_A; |
| 3409 | ivci.components.a = VK_COMPONENT_SWIZZLE_B; |
| 3410 | err = vkCreateImageView(m_device->device(), &ivci, NULL, &view); |
| 3411 | ASSERT_VK_SUCCESS(err); |
| 3412 | |
| 3413 | fb_info.pAttachments = &view; |
| 3414 | fb_info.height = 100; |
| 3415 | fb_info.width = 100; |
| 3416 | fb_info.layers = 1; |
| 3417 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3418 | " has non-identy swizzle. All " |
| 3419 | "framebuffer attachments must have " |
| 3420 | "been created with the identity " |
| 3421 | "swizzle. "); |
| 3422 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3423 | |
| 3424 | m_errorMonitor->VerifyFound(); |
| 3425 | if (err == VK_SUCCESS) { |
| 3426 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3427 | } |
| 3428 | vkDestroyImageView(m_device->device(), view, NULL); |
Tobin Ehlis | 27f2ae8 | 2016-06-23 07:36:57 -0600 | [diff] [blame] | 3429 | |
Tobin Ehlis | 6cfda64 | 2016-06-22 16:12:58 -0600 | [diff] [blame] | 3430 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3431 | } |
| 3432 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3433 | // This is a positive test. No errors should be generated. |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3434 | TEST_F(VkLayerTest, WaitEventThenSet) { |
| 3435 | TEST_DESCRIPTION( |
| 3436 | "Wait on a event then set it after the wait has been submitted."); |
| 3437 | |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3438 | m_errorMonitor->ExpectSuccess(); |
| 3439 | |
| 3440 | VkEvent event; |
| 3441 | VkEventCreateInfo event_create_info{}; |
| 3442 | event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 3443 | vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event); |
| 3444 | |
| 3445 | VkCommandPool command_pool; |
| 3446 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3447 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3448 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3449 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3450 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3451 | &command_pool); |
| 3452 | |
| 3453 | VkCommandBuffer command_buffer; |
| 3454 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3455 | command_buffer_allocate_info.sType = |
| 3456 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3457 | command_buffer_allocate_info.commandPool = command_pool; |
| 3458 | command_buffer_allocate_info.commandBufferCount = 1; |
| 3459 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3460 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3461 | &command_buffer); |
| 3462 | |
| 3463 | VkQueue queue = VK_NULL_HANDLE; |
| 3464 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
Tony Barbour | fe302c0 | 2016-06-06 13:05:19 -0600 | [diff] [blame] | 3465 | 0, &queue); |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3466 | |
| 3467 | { |
| 3468 | VkCommandBufferBeginInfo begin_info{}; |
| 3469 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3470 | vkBeginCommandBuffer(command_buffer, &begin_info); |
| 3471 | |
| 3472 | vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, |
| 3473 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, |
| 3474 | nullptr, 0, nullptr); |
| 3475 | vkCmdResetEvent(command_buffer, event, |
| 3476 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 3477 | vkEndCommandBuffer(command_buffer); |
| 3478 | } |
| 3479 | { |
| 3480 | VkSubmitInfo submit_info{}; |
| 3481 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3482 | submit_info.commandBufferCount = 1; |
| 3483 | submit_info.pCommandBuffers = &command_buffer; |
| 3484 | submit_info.signalSemaphoreCount = 0; |
| 3485 | submit_info.pSignalSemaphores = nullptr; |
| 3486 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3487 | } |
| 3488 | { vkSetEvent(m_device->device(), event); } |
| 3489 | |
| 3490 | vkQueueWaitIdle(queue); |
| 3491 | |
| 3492 | vkDestroyEvent(m_device->device(), event, nullptr); |
| 3493 | vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer); |
| 3494 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3495 | |
| 3496 | m_errorMonitor->VerifyNotFound(); |
| 3497 | } |
Michael Lentine | 5627e69 | 2016-05-20 17:45:02 -0500 | [diff] [blame] | 3498 | // This is a positive test. No errors should be generated. |
| 3499 | TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) { |
| 3500 | TEST_DESCRIPTION( |
| 3501 | "Issue a query and copy from it on a second command buffer."); |
| 3502 | |
| 3503 | if ((m_device->queue_props.empty()) || |
| 3504 | (m_device->queue_props[0].queueCount < 2)) |
| 3505 | return; |
| 3506 | |
| 3507 | m_errorMonitor->ExpectSuccess(); |
| 3508 | |
| 3509 | VkQueryPool query_pool; |
| 3510 | VkQueryPoolCreateInfo query_pool_create_info{}; |
| 3511 | query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; |
| 3512 | query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP; |
| 3513 | query_pool_create_info.queryCount = 1; |
| 3514 | vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, |
| 3515 | &query_pool); |
| 3516 | |
| 3517 | VkCommandPool command_pool; |
| 3518 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3519 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3520 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3521 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3522 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3523 | &command_pool); |
| 3524 | |
| 3525 | VkCommandBuffer command_buffer[2]; |
| 3526 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3527 | command_buffer_allocate_info.sType = |
| 3528 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3529 | command_buffer_allocate_info.commandPool = command_pool; |
| 3530 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3531 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3532 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3533 | command_buffer); |
| 3534 | |
| 3535 | VkQueue queue = VK_NULL_HANDLE; |
| 3536 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3537 | 1, &queue); |
| 3538 | |
| 3539 | uint32_t qfi = 0; |
| 3540 | VkBufferCreateInfo buff_create_info = {}; |
| 3541 | buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 3542 | buff_create_info.size = 1024; |
| 3543 | buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT; |
| 3544 | buff_create_info.queueFamilyIndexCount = 1; |
| 3545 | buff_create_info.pQueueFamilyIndices = &qfi; |
| 3546 | |
| 3547 | VkResult err; |
| 3548 | VkBuffer buffer; |
| 3549 | err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer); |
| 3550 | ASSERT_VK_SUCCESS(err); |
| 3551 | VkMemoryAllocateInfo mem_alloc = {}; |
| 3552 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 3553 | mem_alloc.pNext = NULL; |
| 3554 | mem_alloc.allocationSize = 1024; |
| 3555 | mem_alloc.memoryTypeIndex = 0; |
| 3556 | |
| 3557 | VkMemoryRequirements memReqs; |
| 3558 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs); |
| 3559 | bool pass = |
| 3560 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0); |
| 3561 | if (!pass) { |
| 3562 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 3563 | return; |
| 3564 | } |
| 3565 | |
| 3566 | VkDeviceMemory mem; |
| 3567 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 3568 | ASSERT_VK_SUCCESS(err); |
| 3569 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 3570 | ASSERT_VK_SUCCESS(err); |
| 3571 | |
| 3572 | { |
| 3573 | VkCommandBufferBeginInfo begin_info{}; |
| 3574 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3575 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3576 | |
| 3577 | vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1); |
| 3578 | vkCmdWriteTimestamp(command_buffer[0], |
| 3579 | VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0); |
| 3580 | |
| 3581 | vkEndCommandBuffer(command_buffer[0]); |
| 3582 | |
| 3583 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3584 | |
| 3585 | vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, |
| 3586 | 0, 0, 0); |
| 3587 | |
| 3588 | vkEndCommandBuffer(command_buffer[1]); |
| 3589 | } |
| 3590 | { |
| 3591 | VkSubmitInfo submit_info{}; |
| 3592 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3593 | submit_info.commandBufferCount = 2; |
| 3594 | submit_info.pCommandBuffers = command_buffer; |
| 3595 | submit_info.signalSemaphoreCount = 0; |
| 3596 | submit_info.pSignalSemaphores = nullptr; |
| 3597 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3598 | } |
| 3599 | |
| 3600 | vkQueueWaitIdle(queue); |
| 3601 | |
| 3602 | vkDestroyQueryPool(m_device->device(), query_pool, nullptr); |
| 3603 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer); |
| 3604 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 3605 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 3606 | vkFreeMemory(m_device->device(), mem, NULL); |
Michael Lentine | 5627e69 | 2016-05-20 17:45:02 -0500 | [diff] [blame] | 3607 | |
| 3608 | m_errorMonitor->VerifyNotFound(); |
| 3609 | } |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3610 | |
| 3611 | TEST_F(VkLayerTest, ResetEventThenSet) { |
| 3612 | TEST_DESCRIPTION( |
| 3613 | "Reset an event then set it after the reset has been submitted."); |
| 3614 | |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3615 | m_errorMonitor->ExpectSuccess(); |
| 3616 | |
| 3617 | VkEvent event; |
| 3618 | VkEventCreateInfo event_create_info{}; |
| 3619 | event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 3620 | vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event); |
| 3621 | |
| 3622 | VkCommandPool command_pool; |
| 3623 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3624 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3625 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3626 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3627 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3628 | &command_pool); |
| 3629 | |
| 3630 | VkCommandBuffer command_buffer; |
| 3631 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3632 | command_buffer_allocate_info.sType = |
| 3633 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3634 | command_buffer_allocate_info.commandPool = command_pool; |
| 3635 | command_buffer_allocate_info.commandBufferCount = 1; |
| 3636 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3637 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3638 | &command_buffer); |
| 3639 | |
| 3640 | VkQueue queue = VK_NULL_HANDLE; |
| 3641 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
Tony Barbour | fe302c0 | 2016-06-06 13:05:19 -0600 | [diff] [blame] | 3642 | 0, &queue); |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3643 | |
| 3644 | { |
| 3645 | VkCommandBufferBeginInfo begin_info{}; |
| 3646 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3647 | vkBeginCommandBuffer(command_buffer, &begin_info); |
| 3648 | |
| 3649 | vkCmdResetEvent(command_buffer, event, |
| 3650 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 3651 | vkCmdWaitEvents(command_buffer, 1, &event, |
| 3652 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3653 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, |
| 3654 | nullptr, 0, nullptr); |
| 3655 | vkEndCommandBuffer(command_buffer); |
| 3656 | } |
| 3657 | { |
| 3658 | VkSubmitInfo submit_info{}; |
| 3659 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3660 | submit_info.commandBufferCount = 1; |
| 3661 | submit_info.pCommandBuffers = &command_buffer; |
| 3662 | submit_info.signalSemaphoreCount = 0; |
| 3663 | submit_info.pSignalSemaphores = nullptr; |
| 3664 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3665 | } |
| 3666 | { |
| 3667 | m_errorMonitor->SetDesiredFailureMsg( |
| 3668 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkSetEvent() on event " |
| 3669 | "0x1 that is already in use by a " |
| 3670 | "command buffer."); |
| 3671 | vkSetEvent(m_device->device(), event); |
| 3672 | m_errorMonitor->VerifyFound(); |
| 3673 | } |
| 3674 | |
| 3675 | vkQueueWaitIdle(queue); |
| 3676 | |
| 3677 | vkDestroyEvent(m_device->device(), event, nullptr); |
| 3678 | vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer); |
| 3679 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3680 | } |
| 3681 | |
| 3682 | // This is a positive test. No errors should be generated. |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3683 | TEST_F(VkLayerTest, TwoFencesThreeFrames) { |
| 3684 | TEST_DESCRIPTION("Two command buffers with two separate fences are each " |
| 3685 | "run through a Submit & WaitForFences cycle 3 times. This " |
| 3686 | "previously revealed a bug so running this positive test " |
| 3687 | "to prevent a regression."); |
| 3688 | m_errorMonitor->ExpectSuccess(); |
| 3689 | |
| 3690 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3691 | VkQueue queue = VK_NULL_HANDLE; |
| 3692 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3693 | 0, &queue); |
| 3694 | |
| 3695 | static const uint32_t NUM_OBJECTS = 2; |
| 3696 | static const uint32_t NUM_FRAMES = 3; |
| 3697 | VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {}; |
| 3698 | VkFence fences[NUM_OBJECTS] = {}; |
| 3699 | |
| 3700 | VkCommandPool cmd_pool; |
| 3701 | VkCommandPoolCreateInfo cmd_pool_ci = {}; |
| 3702 | cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3703 | cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3704 | cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3705 | VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, |
| 3706 | nullptr, &cmd_pool); |
| 3707 | ASSERT_VK_SUCCESS(err); |
| 3708 | |
| 3709 | VkCommandBufferAllocateInfo cmd_buf_info = {}; |
| 3710 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3711 | cmd_buf_info.commandPool = cmd_pool; |
| 3712 | cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3713 | cmd_buf_info.commandBufferCount = 1; |
| 3714 | |
| 3715 | VkFenceCreateInfo fence_ci = {}; |
| 3716 | fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3717 | fence_ci.pNext = nullptr; |
| 3718 | fence_ci.flags = 0; |
| 3719 | |
| 3720 | for (uint32_t i = 0; i < NUM_OBJECTS; ++i) { |
| 3721 | err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, |
| 3722 | &cmd_buffers[i]); |
| 3723 | ASSERT_VK_SUCCESS(err); |
| 3724 | err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]); |
| 3725 | ASSERT_VK_SUCCESS(err); |
| 3726 | } |
| 3727 | |
| 3728 | for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) { |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 3729 | for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) { |
| 3730 | // Create empty cmd buffer |
| 3731 | VkCommandBufferBeginInfo cmdBufBeginDesc = {}; |
| 3732 | cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3733 | |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 3734 | err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc); |
| 3735 | ASSERT_VK_SUCCESS(err); |
| 3736 | err = vkEndCommandBuffer(cmd_buffers[obj]); |
| 3737 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3738 | |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 3739 | VkSubmitInfo submit_info = {}; |
| 3740 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3741 | submit_info.commandBufferCount = 1; |
| 3742 | submit_info.pCommandBuffers = &cmd_buffers[obj]; |
| 3743 | // Submit cmd buffer and wait for fence |
| 3744 | err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]); |
| 3745 | ASSERT_VK_SUCCESS(err); |
| 3746 | err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, |
| 3747 | UINT64_MAX); |
| 3748 | ASSERT_VK_SUCCESS(err); |
| 3749 | err = vkResetFences(m_device->device(), 1, &fences[obj]); |
| 3750 | ASSERT_VK_SUCCESS(err); |
| 3751 | } |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3752 | } |
| 3753 | m_errorMonitor->VerifyNotFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 3754 | vkDestroyCommandPool(m_device->device(), cmd_pool, NULL); |
| 3755 | for (uint32_t i = 0; i < NUM_OBJECTS; ++i) { |
| 3756 | vkDestroyFence(m_device->device(), fences[i], nullptr); |
| 3757 | } |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3758 | } |
| 3759 | // This is a positive test. No errors should be generated. |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3760 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) { |
| 3761 | |
| 3762 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 3763 | "submitted on separate queues followed by a QueueWaitIdle."); |
| 3764 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 3765 | if ((m_device->queue_props.empty()) || |
| 3766 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 3767 | return; |
| 3768 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3769 | m_errorMonitor->ExpectSuccess(); |
| 3770 | |
| 3771 | VkSemaphore semaphore; |
| 3772 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 3773 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 3774 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 3775 | &semaphore); |
| 3776 | |
| 3777 | VkCommandPool command_pool; |
| 3778 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3779 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3780 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3781 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3782 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3783 | &command_pool); |
| 3784 | |
| 3785 | VkCommandBuffer command_buffer[2]; |
| 3786 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3787 | command_buffer_allocate_info.sType = |
| 3788 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3789 | command_buffer_allocate_info.commandPool = command_pool; |
| 3790 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3791 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3792 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3793 | command_buffer); |
| 3794 | |
| 3795 | VkQueue queue = VK_NULL_HANDLE; |
| 3796 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3797 | 1, &queue); |
| 3798 | |
| 3799 | { |
| 3800 | VkCommandBufferBeginInfo begin_info{}; |
| 3801 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3802 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3803 | |
| 3804 | vkCmdPipelineBarrier(command_buffer[0], |
| 3805 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3806 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 3807 | 0, nullptr, 0, nullptr); |
| 3808 | |
| 3809 | VkViewport viewport{}; |
| 3810 | viewport.maxDepth = 1.0f; |
| 3811 | viewport.minDepth = 0.0f; |
| 3812 | viewport.width = 512; |
| 3813 | viewport.height = 512; |
| 3814 | viewport.x = 0; |
| 3815 | viewport.y = 0; |
| 3816 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 3817 | vkEndCommandBuffer(command_buffer[0]); |
| 3818 | } |
| 3819 | { |
| 3820 | VkCommandBufferBeginInfo begin_info{}; |
| 3821 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3822 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3823 | |
| 3824 | VkViewport viewport{}; |
| 3825 | viewport.maxDepth = 1.0f; |
| 3826 | viewport.minDepth = 0.0f; |
| 3827 | viewport.width = 512; |
| 3828 | viewport.height = 512; |
| 3829 | viewport.x = 0; |
| 3830 | viewport.y = 0; |
| 3831 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 3832 | vkEndCommandBuffer(command_buffer[1]); |
| 3833 | } |
| 3834 | { |
| 3835 | VkSubmitInfo submit_info{}; |
| 3836 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3837 | submit_info.commandBufferCount = 1; |
| 3838 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 3839 | submit_info.signalSemaphoreCount = 1; |
| 3840 | submit_info.pSignalSemaphores = &semaphore; |
| 3841 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3842 | } |
| 3843 | { |
| 3844 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 3845 | VkSubmitInfo submit_info{}; |
| 3846 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3847 | submit_info.commandBufferCount = 1; |
| 3848 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 3849 | submit_info.waitSemaphoreCount = 1; |
| 3850 | submit_info.pWaitSemaphores = &semaphore; |
| 3851 | submit_info.pWaitDstStageMask = flags; |
| 3852 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3853 | } |
| 3854 | |
| 3855 | vkQueueWaitIdle(m_device->m_queue); |
| 3856 | |
| 3857 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 3858 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 3859 | &command_buffer[0]); |
| 3860 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3861 | |
| 3862 | m_errorMonitor->VerifyNotFound(); |
| 3863 | } |
| 3864 | |
| 3865 | // This is a positive test. No errors should be generated. |
| 3866 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) { |
| 3867 | |
| 3868 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 3869 | "submitted on separate queues, the second having a fence" |
| 3870 | "followed by a QueueWaitIdle."); |
| 3871 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 3872 | if ((m_device->queue_props.empty()) || |
| 3873 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 3874 | return; |
| 3875 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3876 | m_errorMonitor->ExpectSuccess(); |
| 3877 | |
| 3878 | VkFence fence; |
| 3879 | VkFenceCreateInfo fence_create_info{}; |
| 3880 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3881 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 3882 | |
| 3883 | VkSemaphore semaphore; |
| 3884 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 3885 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 3886 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 3887 | &semaphore); |
| 3888 | |
| 3889 | VkCommandPool command_pool; |
| 3890 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3891 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3892 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3893 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3894 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3895 | &command_pool); |
| 3896 | |
| 3897 | VkCommandBuffer command_buffer[2]; |
| 3898 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3899 | command_buffer_allocate_info.sType = |
| 3900 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3901 | command_buffer_allocate_info.commandPool = command_pool; |
| 3902 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3903 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3904 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3905 | command_buffer); |
| 3906 | |
| 3907 | VkQueue queue = VK_NULL_HANDLE; |
| 3908 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3909 | 1, &queue); |
| 3910 | |
| 3911 | { |
| 3912 | VkCommandBufferBeginInfo begin_info{}; |
| 3913 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3914 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3915 | |
| 3916 | vkCmdPipelineBarrier(command_buffer[0], |
| 3917 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3918 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 3919 | 0, nullptr, 0, nullptr); |
| 3920 | |
| 3921 | VkViewport viewport{}; |
| 3922 | viewport.maxDepth = 1.0f; |
| 3923 | viewport.minDepth = 0.0f; |
| 3924 | viewport.width = 512; |
| 3925 | viewport.height = 512; |
| 3926 | viewport.x = 0; |
| 3927 | viewport.y = 0; |
| 3928 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 3929 | vkEndCommandBuffer(command_buffer[0]); |
| 3930 | } |
| 3931 | { |
| 3932 | VkCommandBufferBeginInfo begin_info{}; |
| 3933 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3934 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3935 | |
| 3936 | VkViewport viewport{}; |
| 3937 | viewport.maxDepth = 1.0f; |
| 3938 | viewport.minDepth = 0.0f; |
| 3939 | viewport.width = 512; |
| 3940 | viewport.height = 512; |
| 3941 | viewport.x = 0; |
| 3942 | viewport.y = 0; |
| 3943 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 3944 | vkEndCommandBuffer(command_buffer[1]); |
| 3945 | } |
| 3946 | { |
| 3947 | VkSubmitInfo submit_info{}; |
| 3948 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3949 | submit_info.commandBufferCount = 1; |
| 3950 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 3951 | submit_info.signalSemaphoreCount = 1; |
| 3952 | submit_info.pSignalSemaphores = &semaphore; |
| 3953 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3954 | } |
| 3955 | { |
| 3956 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 3957 | VkSubmitInfo submit_info{}; |
| 3958 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3959 | submit_info.commandBufferCount = 1; |
| 3960 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 3961 | submit_info.waitSemaphoreCount = 1; |
| 3962 | submit_info.pWaitSemaphores = &semaphore; |
| 3963 | submit_info.pWaitDstStageMask = flags; |
| 3964 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 3965 | } |
| 3966 | |
| 3967 | vkQueueWaitIdle(m_device->m_queue); |
| 3968 | |
| 3969 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 3970 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 3971 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 3972 | &command_buffer[0]); |
| 3973 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3974 | |
| 3975 | m_errorMonitor->VerifyNotFound(); |
| 3976 | } |
| 3977 | |
| 3978 | // This is a positive test. No errors should be generated. |
| 3979 | TEST_F(VkLayerTest, |
| 3980 | TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) { |
| 3981 | |
| 3982 | TEST_DESCRIPTION( |
| 3983 | "Two command buffers, each in a separate QueueSubmit call " |
| 3984 | "submitted on separate queues, the second having a fence" |
| 3985 | "followed by two consecutive WaitForFences calls on the same fence."); |
| 3986 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 3987 | if ((m_device->queue_props.empty()) || |
| 3988 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 3989 | return; |
| 3990 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3991 | m_errorMonitor->ExpectSuccess(); |
| 3992 | |
| 3993 | VkFence fence; |
| 3994 | VkFenceCreateInfo fence_create_info{}; |
| 3995 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3996 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 3997 | |
| 3998 | VkSemaphore semaphore; |
| 3999 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4000 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4001 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4002 | &semaphore); |
| 4003 | |
| 4004 | VkCommandPool command_pool; |
| 4005 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4006 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4007 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4008 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4009 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4010 | &command_pool); |
| 4011 | |
| 4012 | VkCommandBuffer command_buffer[2]; |
| 4013 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4014 | command_buffer_allocate_info.sType = |
| 4015 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4016 | command_buffer_allocate_info.commandPool = command_pool; |
| 4017 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4018 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4019 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4020 | command_buffer); |
| 4021 | |
| 4022 | VkQueue queue = VK_NULL_HANDLE; |
| 4023 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4024 | 1, &queue); |
| 4025 | |
| 4026 | { |
| 4027 | VkCommandBufferBeginInfo begin_info{}; |
| 4028 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4029 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4030 | |
| 4031 | vkCmdPipelineBarrier(command_buffer[0], |
| 4032 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4033 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4034 | 0, nullptr, 0, nullptr); |
| 4035 | |
| 4036 | VkViewport viewport{}; |
| 4037 | viewport.maxDepth = 1.0f; |
| 4038 | viewport.minDepth = 0.0f; |
| 4039 | viewport.width = 512; |
| 4040 | viewport.height = 512; |
| 4041 | viewport.x = 0; |
| 4042 | viewport.y = 0; |
| 4043 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4044 | vkEndCommandBuffer(command_buffer[0]); |
| 4045 | } |
| 4046 | { |
| 4047 | VkCommandBufferBeginInfo begin_info{}; |
| 4048 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4049 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4050 | |
| 4051 | VkViewport viewport{}; |
| 4052 | viewport.maxDepth = 1.0f; |
| 4053 | viewport.minDepth = 0.0f; |
| 4054 | viewport.width = 512; |
| 4055 | viewport.height = 512; |
| 4056 | viewport.x = 0; |
| 4057 | viewport.y = 0; |
| 4058 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4059 | vkEndCommandBuffer(command_buffer[1]); |
| 4060 | } |
| 4061 | { |
| 4062 | VkSubmitInfo submit_info{}; |
| 4063 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4064 | submit_info.commandBufferCount = 1; |
| 4065 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4066 | submit_info.signalSemaphoreCount = 1; |
| 4067 | submit_info.pSignalSemaphores = &semaphore; |
| 4068 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4069 | } |
| 4070 | { |
| 4071 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4072 | VkSubmitInfo submit_info{}; |
| 4073 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4074 | submit_info.commandBufferCount = 1; |
| 4075 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4076 | submit_info.waitSemaphoreCount = 1; |
| 4077 | submit_info.pWaitSemaphores = &semaphore; |
| 4078 | submit_info.pWaitDstStageMask = flags; |
| 4079 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4080 | } |
| 4081 | |
| 4082 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4083 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4084 | |
| 4085 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4086 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4087 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4088 | &command_buffer[0]); |
| 4089 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4090 | |
| 4091 | m_errorMonitor->VerifyNotFound(); |
| 4092 | } |
| 4093 | |
| 4094 | // This is a positive test. No errors should be generated. |
| 4095 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) { |
| 4096 | |
| 4097 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4098 | "submitted on separate queues, the second having a fence, " |
| 4099 | "followed by a WaitForFences call."); |
| 4100 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 4101 | if ((m_device->queue_props.empty()) || |
| 4102 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 4103 | return; |
| 4104 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4105 | m_errorMonitor->ExpectSuccess(); |
| 4106 | |
| 4107 | VkFence fence; |
| 4108 | VkFenceCreateInfo fence_create_info{}; |
| 4109 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4110 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4111 | |
| 4112 | VkSemaphore semaphore; |
| 4113 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4114 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4115 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4116 | &semaphore); |
| 4117 | |
| 4118 | VkCommandPool command_pool; |
| 4119 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4120 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4121 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4122 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4123 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4124 | &command_pool); |
| 4125 | |
| 4126 | VkCommandBuffer command_buffer[2]; |
| 4127 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4128 | command_buffer_allocate_info.sType = |
| 4129 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4130 | command_buffer_allocate_info.commandPool = command_pool; |
| 4131 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4132 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4133 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4134 | command_buffer); |
| 4135 | |
| 4136 | VkQueue queue = VK_NULL_HANDLE; |
| 4137 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 4138 | 1, &queue); |
| 4139 | |
| 4140 | |
| 4141 | { |
| 4142 | VkCommandBufferBeginInfo begin_info{}; |
| 4143 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4144 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4145 | |
| 4146 | vkCmdPipelineBarrier(command_buffer[0], |
| 4147 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4148 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4149 | 0, nullptr, 0, nullptr); |
| 4150 | |
| 4151 | VkViewport viewport{}; |
| 4152 | viewport.maxDepth = 1.0f; |
| 4153 | viewport.minDepth = 0.0f; |
| 4154 | viewport.width = 512; |
| 4155 | viewport.height = 512; |
| 4156 | viewport.x = 0; |
| 4157 | viewport.y = 0; |
| 4158 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4159 | vkEndCommandBuffer(command_buffer[0]); |
| 4160 | } |
| 4161 | { |
| 4162 | VkCommandBufferBeginInfo begin_info{}; |
| 4163 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4164 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4165 | |
| 4166 | VkViewport viewport{}; |
| 4167 | viewport.maxDepth = 1.0f; |
| 4168 | viewport.minDepth = 0.0f; |
| 4169 | viewport.width = 512; |
| 4170 | viewport.height = 512; |
| 4171 | viewport.x = 0; |
| 4172 | viewport.y = 0; |
| 4173 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4174 | vkEndCommandBuffer(command_buffer[1]); |
| 4175 | } |
| 4176 | { |
| 4177 | VkSubmitInfo submit_info{}; |
| 4178 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4179 | submit_info.commandBufferCount = 1; |
| 4180 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4181 | submit_info.signalSemaphoreCount = 1; |
| 4182 | submit_info.pSignalSemaphores = &semaphore; |
| 4183 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4184 | } |
| 4185 | { |
| 4186 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4187 | VkSubmitInfo submit_info{}; |
| 4188 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4189 | submit_info.commandBufferCount = 1; |
| 4190 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4191 | submit_info.waitSemaphoreCount = 1; |
| 4192 | submit_info.pWaitSemaphores = &semaphore; |
| 4193 | submit_info.pWaitDstStageMask = flags; |
| 4194 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4195 | } |
| 4196 | |
| 4197 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4198 | |
| 4199 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4200 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4201 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4202 | &command_buffer[0]); |
| 4203 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4204 | |
| 4205 | m_errorMonitor->VerifyNotFound(); |
| 4206 | } |
| 4207 | |
| 4208 | // This is a positive test. No errors should be generated. |
| 4209 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) { |
| 4210 | |
| 4211 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4212 | "on the same queue, sharing a signal/wait semaphore, the " |
| 4213 | "second having a fence, " |
| 4214 | "followed by a WaitForFences call."); |
| 4215 | |
| 4216 | m_errorMonitor->ExpectSuccess(); |
| 4217 | |
| 4218 | VkFence fence; |
| 4219 | VkFenceCreateInfo fence_create_info{}; |
| 4220 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4221 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4222 | |
| 4223 | VkSemaphore semaphore; |
| 4224 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4225 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4226 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4227 | &semaphore); |
| 4228 | |
| 4229 | VkCommandPool command_pool; |
| 4230 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4231 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4232 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4233 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4234 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4235 | &command_pool); |
| 4236 | |
| 4237 | VkCommandBuffer command_buffer[2]; |
| 4238 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4239 | command_buffer_allocate_info.sType = |
| 4240 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4241 | command_buffer_allocate_info.commandPool = command_pool; |
| 4242 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4243 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4244 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4245 | command_buffer); |
| 4246 | |
| 4247 | { |
| 4248 | VkCommandBufferBeginInfo begin_info{}; |
| 4249 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4250 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4251 | |
| 4252 | vkCmdPipelineBarrier(command_buffer[0], |
| 4253 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4254 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4255 | 0, nullptr, 0, nullptr); |
| 4256 | |
| 4257 | VkViewport viewport{}; |
| 4258 | viewport.maxDepth = 1.0f; |
| 4259 | viewport.minDepth = 0.0f; |
| 4260 | viewport.width = 512; |
| 4261 | viewport.height = 512; |
| 4262 | viewport.x = 0; |
| 4263 | viewport.y = 0; |
| 4264 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4265 | vkEndCommandBuffer(command_buffer[0]); |
| 4266 | } |
| 4267 | { |
| 4268 | VkCommandBufferBeginInfo begin_info{}; |
| 4269 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4270 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4271 | |
| 4272 | VkViewport viewport{}; |
| 4273 | viewport.maxDepth = 1.0f; |
| 4274 | viewport.minDepth = 0.0f; |
| 4275 | viewport.width = 512; |
| 4276 | viewport.height = 512; |
| 4277 | viewport.x = 0; |
| 4278 | viewport.y = 0; |
| 4279 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4280 | vkEndCommandBuffer(command_buffer[1]); |
| 4281 | } |
| 4282 | { |
| 4283 | VkSubmitInfo submit_info{}; |
| 4284 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4285 | submit_info.commandBufferCount = 1; |
| 4286 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4287 | submit_info.signalSemaphoreCount = 1; |
| 4288 | submit_info.pSignalSemaphores = &semaphore; |
| 4289 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4290 | } |
| 4291 | { |
| 4292 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4293 | VkSubmitInfo submit_info{}; |
| 4294 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4295 | submit_info.commandBufferCount = 1; |
| 4296 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4297 | submit_info.waitSemaphoreCount = 1; |
| 4298 | submit_info.pWaitSemaphores = &semaphore; |
| 4299 | submit_info.pWaitDstStageMask = flags; |
| 4300 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4301 | } |
| 4302 | |
| 4303 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4304 | |
| 4305 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4306 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4307 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4308 | &command_buffer[0]); |
| 4309 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4310 | |
| 4311 | m_errorMonitor->VerifyNotFound(); |
| 4312 | } |
| 4313 | |
| 4314 | // This is a positive test. No errors should be generated. |
| 4315 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) { |
| 4316 | |
| 4317 | TEST_DESCRIPTION( |
| 4318 | "Two command buffers, each in a separate QueueSubmit call " |
| 4319 | "on the same queue, no fences, followed by a third QueueSubmit with NO " |
| 4320 | "SubmitInfos but with a fence, followed by a WaitForFences call."); |
| 4321 | |
| 4322 | m_errorMonitor->ExpectSuccess(); |
| 4323 | |
| 4324 | VkFence fence; |
| 4325 | VkFenceCreateInfo fence_create_info{}; |
| 4326 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4327 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4328 | |
| 4329 | VkCommandPool command_pool; |
| 4330 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4331 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4332 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4333 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4334 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4335 | &command_pool); |
| 4336 | |
| 4337 | VkCommandBuffer command_buffer[2]; |
| 4338 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4339 | command_buffer_allocate_info.sType = |
| 4340 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4341 | command_buffer_allocate_info.commandPool = command_pool; |
| 4342 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4343 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4344 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4345 | command_buffer); |
| 4346 | |
| 4347 | { |
| 4348 | VkCommandBufferBeginInfo begin_info{}; |
| 4349 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4350 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4351 | |
| 4352 | vkCmdPipelineBarrier(command_buffer[0], |
| 4353 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4354 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4355 | 0, nullptr, 0, nullptr); |
| 4356 | |
| 4357 | VkViewport viewport{}; |
| 4358 | viewport.maxDepth = 1.0f; |
| 4359 | viewport.minDepth = 0.0f; |
| 4360 | viewport.width = 512; |
| 4361 | viewport.height = 512; |
| 4362 | viewport.x = 0; |
| 4363 | viewport.y = 0; |
| 4364 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4365 | vkEndCommandBuffer(command_buffer[0]); |
| 4366 | } |
| 4367 | { |
| 4368 | VkCommandBufferBeginInfo begin_info{}; |
| 4369 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4370 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4371 | |
| 4372 | VkViewport viewport{}; |
| 4373 | viewport.maxDepth = 1.0f; |
| 4374 | viewport.minDepth = 0.0f; |
| 4375 | viewport.width = 512; |
| 4376 | viewport.height = 512; |
| 4377 | viewport.x = 0; |
| 4378 | viewport.y = 0; |
| 4379 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4380 | vkEndCommandBuffer(command_buffer[1]); |
| 4381 | } |
| 4382 | { |
| 4383 | VkSubmitInfo submit_info{}; |
| 4384 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4385 | submit_info.commandBufferCount = 1; |
| 4386 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4387 | submit_info.signalSemaphoreCount = 0; |
| 4388 | submit_info.pSignalSemaphores = VK_NULL_HANDLE; |
| 4389 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4390 | } |
| 4391 | { |
| 4392 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4393 | VkSubmitInfo submit_info{}; |
| 4394 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4395 | submit_info.commandBufferCount = 1; |
| 4396 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4397 | submit_info.waitSemaphoreCount = 0; |
| 4398 | submit_info.pWaitSemaphores = VK_NULL_HANDLE; |
| 4399 | submit_info.pWaitDstStageMask = flags; |
| 4400 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4401 | } |
| 4402 | |
| 4403 | vkQueueSubmit(m_device->m_queue, 0, NULL, fence); |
| 4404 | |
| 4405 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4406 | |
| 4407 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4408 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4409 | &command_buffer[0]); |
| 4410 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4411 | |
| 4412 | m_errorMonitor->VerifyNotFound(); |
| 4413 | } |
| 4414 | |
| 4415 | // This is a positive test. No errors should be generated. |
| 4416 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) { |
| 4417 | |
| 4418 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4419 | "on the same queue, the second having a fence, followed " |
| 4420 | "by a WaitForFences call."); |
| 4421 | |
| 4422 | m_errorMonitor->ExpectSuccess(); |
| 4423 | |
| 4424 | VkFence fence; |
| 4425 | VkFenceCreateInfo fence_create_info{}; |
| 4426 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4427 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4428 | |
| 4429 | VkCommandPool command_pool; |
| 4430 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4431 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4432 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4433 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4434 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4435 | &command_pool); |
| 4436 | |
| 4437 | VkCommandBuffer command_buffer[2]; |
| 4438 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4439 | command_buffer_allocate_info.sType = |
| 4440 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4441 | command_buffer_allocate_info.commandPool = command_pool; |
| 4442 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4443 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4444 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4445 | command_buffer); |
| 4446 | |
| 4447 | { |
| 4448 | VkCommandBufferBeginInfo begin_info{}; |
| 4449 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4450 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4451 | |
| 4452 | vkCmdPipelineBarrier(command_buffer[0], |
| 4453 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4454 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4455 | 0, nullptr, 0, nullptr); |
| 4456 | |
| 4457 | VkViewport viewport{}; |
| 4458 | viewport.maxDepth = 1.0f; |
| 4459 | viewport.minDepth = 0.0f; |
| 4460 | viewport.width = 512; |
| 4461 | viewport.height = 512; |
| 4462 | viewport.x = 0; |
| 4463 | viewport.y = 0; |
| 4464 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4465 | vkEndCommandBuffer(command_buffer[0]); |
| 4466 | } |
| 4467 | { |
| 4468 | VkCommandBufferBeginInfo begin_info{}; |
| 4469 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4470 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4471 | |
| 4472 | VkViewport viewport{}; |
| 4473 | viewport.maxDepth = 1.0f; |
| 4474 | viewport.minDepth = 0.0f; |
| 4475 | viewport.width = 512; |
| 4476 | viewport.height = 512; |
| 4477 | viewport.x = 0; |
| 4478 | viewport.y = 0; |
| 4479 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4480 | vkEndCommandBuffer(command_buffer[1]); |
| 4481 | } |
| 4482 | { |
| 4483 | VkSubmitInfo submit_info{}; |
| 4484 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4485 | submit_info.commandBufferCount = 1; |
| 4486 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4487 | submit_info.signalSemaphoreCount = 0; |
| 4488 | submit_info.pSignalSemaphores = VK_NULL_HANDLE; |
| 4489 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4490 | } |
| 4491 | { |
| 4492 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4493 | VkSubmitInfo submit_info{}; |
| 4494 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4495 | submit_info.commandBufferCount = 1; |
| 4496 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4497 | submit_info.waitSemaphoreCount = 0; |
| 4498 | submit_info.pWaitSemaphores = VK_NULL_HANDLE; |
| 4499 | submit_info.pWaitDstStageMask = flags; |
| 4500 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4501 | } |
| 4502 | |
| 4503 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4504 | |
| 4505 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4506 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4507 | &command_buffer[0]); |
| 4508 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4509 | |
| 4510 | m_errorMonitor->VerifyNotFound(); |
| 4511 | } |
| 4512 | |
| 4513 | // This is a positive test. No errors should be generated. |
| 4514 | TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) { |
| 4515 | |
| 4516 | TEST_DESCRIPTION( |
| 4517 | "Two command buffers each in a separate SubmitInfo sent in a single " |
| 4518 | "QueueSubmit call followed by a WaitForFences call."); |
| 4519 | |
| 4520 | m_errorMonitor->ExpectSuccess(); |
| 4521 | |
| 4522 | VkFence fence; |
| 4523 | VkFenceCreateInfo fence_create_info{}; |
| 4524 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4525 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4526 | |
| 4527 | VkSemaphore semaphore; |
| 4528 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4529 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4530 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4531 | &semaphore); |
| 4532 | |
| 4533 | VkCommandPool command_pool; |
| 4534 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4535 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4536 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4537 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4538 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4539 | &command_pool); |
| 4540 | |
| 4541 | VkCommandBuffer command_buffer[2]; |
| 4542 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4543 | command_buffer_allocate_info.sType = |
| 4544 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4545 | command_buffer_allocate_info.commandPool = command_pool; |
| 4546 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4547 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4548 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4549 | command_buffer); |
| 4550 | |
| 4551 | { |
| 4552 | VkCommandBufferBeginInfo begin_info{}; |
| 4553 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4554 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4555 | |
| 4556 | vkCmdPipelineBarrier(command_buffer[0], |
| 4557 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4558 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4559 | 0, nullptr, 0, nullptr); |
| 4560 | |
| 4561 | VkViewport viewport{}; |
| 4562 | viewport.maxDepth = 1.0f; |
| 4563 | viewport.minDepth = 0.0f; |
| 4564 | viewport.width = 512; |
| 4565 | viewport.height = 512; |
| 4566 | viewport.x = 0; |
| 4567 | viewport.y = 0; |
| 4568 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4569 | vkEndCommandBuffer(command_buffer[0]); |
| 4570 | } |
| 4571 | { |
| 4572 | VkCommandBufferBeginInfo begin_info{}; |
| 4573 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4574 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4575 | |
| 4576 | VkViewport viewport{}; |
| 4577 | viewport.maxDepth = 1.0f; |
| 4578 | viewport.minDepth = 0.0f; |
| 4579 | viewport.width = 512; |
| 4580 | viewport.height = 512; |
| 4581 | viewport.x = 0; |
| 4582 | viewport.y = 0; |
| 4583 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4584 | vkEndCommandBuffer(command_buffer[1]); |
| 4585 | } |
| 4586 | { |
| 4587 | VkSubmitInfo submit_info[2]; |
| 4588 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4589 | |
| 4590 | submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4591 | submit_info[0].pNext = NULL; |
| 4592 | submit_info[0].commandBufferCount = 1; |
| 4593 | submit_info[0].pCommandBuffers = &command_buffer[0]; |
| 4594 | submit_info[0].signalSemaphoreCount = 1; |
| 4595 | submit_info[0].pSignalSemaphores = &semaphore; |
| 4596 | submit_info[0].waitSemaphoreCount = 0; |
| 4597 | submit_info[0].pWaitSemaphores = NULL; |
| 4598 | submit_info[0].pWaitDstStageMask = 0; |
| 4599 | |
| 4600 | submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4601 | submit_info[1].pNext = NULL; |
| 4602 | submit_info[1].commandBufferCount = 1; |
| 4603 | submit_info[1].pCommandBuffers = &command_buffer[1]; |
| 4604 | submit_info[1].waitSemaphoreCount = 1; |
| 4605 | submit_info[1].pWaitSemaphores = &semaphore; |
| 4606 | submit_info[1].pWaitDstStageMask = flags; |
| 4607 | submit_info[1].signalSemaphoreCount = 0; |
| 4608 | submit_info[1].pSignalSemaphores = NULL; |
| 4609 | vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence); |
| 4610 | } |
| 4611 | |
| 4612 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4613 | |
| 4614 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4615 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4616 | &command_buffer[0]); |
| 4617 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 4618 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4619 | |
| 4620 | m_errorMonitor->VerifyNotFound(); |
| 4621 | } |
| 4622 | |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4623 | TEST_F(VkLayerTest, DynamicDepthBiasNotBound) { |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4624 | TEST_DESCRIPTION( |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4625 | "Run a simple draw calls to validate failure when Depth Bias dynamic " |
| 4626 | "state is required but not correctly bound."); |
| 4627 | |
| 4628 | // Dynamic depth bias |
| 4629 | m_errorMonitor->SetDesiredFailureMsg( |
| 4630 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4631 | "Dynamic depth bias state not set for this command buffer"); |
| 4632 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4633 | BsoFailDepthBias); |
| 4634 | m_errorMonitor->VerifyFound(); |
| 4635 | } |
| 4636 | |
| 4637 | TEST_F(VkLayerTest, DynamicLineWidthNotBound) { |
| 4638 | TEST_DESCRIPTION( |
| 4639 | "Run a simple draw calls to validate failure when Line Width dynamic " |
| 4640 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4641 | |
| 4642 | // Dynamic line width |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4643 | m_errorMonitor->SetDesiredFailureMsg( |
| 4644 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4645 | "Dynamic line width state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4646 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4647 | BsoFailLineWidth); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4648 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4649 | } |
| 4650 | |
| 4651 | TEST_F(VkLayerTest, DynamicViewportNotBound) { |
| 4652 | TEST_DESCRIPTION( |
| 4653 | "Run a simple draw calls to validate failure when Viewport dynamic " |
| 4654 | "state is required but not correctly bound."); |
| 4655 | |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4656 | // Dynamic viewport state |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4657 | m_errorMonitor->SetDesiredFailureMsg( |
| 4658 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4659 | "Dynamic viewport state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4660 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4661 | BsoFailViewport); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4662 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4663 | } |
| 4664 | |
| 4665 | TEST_F(VkLayerTest, DynamicScissorNotBound) { |
| 4666 | TEST_DESCRIPTION( |
| 4667 | "Run a simple draw calls to validate failure when Scissor dynamic " |
| 4668 | "state is required but not correctly bound."); |
| 4669 | |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4670 | // Dynamic scissor state |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4671 | m_errorMonitor->SetDesiredFailureMsg( |
| 4672 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4673 | "Dynamic scissor state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4674 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4675 | BsoFailScissor); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4676 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4677 | } |
| 4678 | |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 4679 | TEST_F(VkLayerTest, DynamiBlendConstantsNotBound) { |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4680 | TEST_DESCRIPTION( |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 4681 | "Run a simple draw calls to validate failure when Blend Constants " |
| 4682 | "dynamic state is required but not correctly bound."); |
| 4683 | // Dynamic blend constant state |
| 4684 | m_errorMonitor->SetDesiredFailureMsg( |
| 4685 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4686 | "Dynamic blend constants state not set for this command buffer"); |
| 4687 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4688 | BsoFailBlend); |
| 4689 | m_errorMonitor->VerifyFound(); |
| 4690 | } |
| 4691 | |
| 4692 | TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) { |
| 4693 | TEST_DESCRIPTION( |
| 4694 | "Run a simple draw calls to validate failure when Depth Bounds dynamic " |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4695 | "state is required but not correctly bound."); |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 4696 | if (!m_device->phy().features().depthBounds) { |
| 4697 | printf("Device does not support depthBounds test; skipped.\n"); |
| 4698 | return; |
| 4699 | } |
| 4700 | // Dynamic depth bounds |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4701 | m_errorMonitor->SetDesiredFailureMsg( |
| 4702 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4703 | "Dynamic depth bounds state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4704 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4705 | BsoFailDepthBounds); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4706 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4707 | } |
| 4708 | |
| 4709 | TEST_F(VkLayerTest, DynamicStencilReadNotBound) { |
| 4710 | TEST_DESCRIPTION( |
| 4711 | "Run a simple draw calls to validate failure when Stencil Read dynamic " |
| 4712 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4713 | // Dynamic stencil read mask |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4714 | m_errorMonitor->SetDesiredFailureMsg( |
| 4715 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4716 | "Dynamic stencil read mask state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4717 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4718 | BsoFailStencilReadMask); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4719 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4720 | } |
| 4721 | |
| 4722 | TEST_F(VkLayerTest, DynamicStencilWriteNotBound) { |
| 4723 | TEST_DESCRIPTION( |
| 4724 | "Run a simple draw calls to validate failure when Stencil Write dynamic" |
| 4725 | " state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4726 | // Dynamic stencil write mask |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4727 | m_errorMonitor->SetDesiredFailureMsg( |
| 4728 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4729 | "Dynamic stencil write mask state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4730 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4731 | BsoFailStencilWriteMask); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4732 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4733 | } |
| 4734 | |
| 4735 | TEST_F(VkLayerTest, DynamicStencilRefNotBound) { |
| 4736 | TEST_DESCRIPTION( |
| 4737 | "Run a simple draw calls to validate failure when Stencil Ref dynamic " |
| 4738 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4739 | // Dynamic stencil reference |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4740 | m_errorMonitor->SetDesiredFailureMsg( |
| 4741 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4742 | "Dynamic stencil reference state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4743 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4744 | BsoFailStencilReference); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4745 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 963a404 | 2015-09-29 08:18:34 -0600 | [diff] [blame] | 4746 | } |
| 4747 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4748 | TEST_F(VkLayerTest, CommandBufferTwoSubmits) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4749 | m_errorMonitor->SetDesiredFailureMsg( |
| 4750 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4751 | "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has " |
| 4752 | "been submitted"); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4753 | |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4754 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4755 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 4756 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 4757 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4758 | // We luck out b/c by default the framework creates CB w/ the |
| 4759 | // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4760 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4761 | m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 4762 | m_stencil_clear_color, NULL); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4763 | EndCommandBuffer(); |
| 4764 | |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4765 | // Bypass framework since it does the waits automatically |
| 4766 | VkResult err = VK_SUCCESS; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 4767 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 4768 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4769 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 4770 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 4771 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 4772 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 4773 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 4774 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 4775 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 4776 | submit_info.pSignalSemaphores = NULL; |
| 4777 | |
Chris Forbes | 40028e2 | 2016-06-13 09:59:34 +1200 | [diff] [blame] | 4778 | err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4779 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4780 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4781 | // Cause validation error by re-submitting cmd buffer that should only be |
| 4782 | // submitted once |
Chris Forbes | 40028e2 | 2016-06-13 09:59:34 +1200 | [diff] [blame] | 4783 | err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4784 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4785 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4786 | } |
| 4787 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4788 | TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) { |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4789 | // Initiate Draw w/o a PSO bound |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4790 | VkResult err; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4791 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 4792 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4793 | "Unable to allocate 1 descriptors of " |
| 4794 | "type " |
| 4795 | "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4796 | |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4797 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4798 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4799 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4800 | // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer |
| 4801 | // descriptor from it |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 4802 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4803 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 4804 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4805 | |
| 4806 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4807 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 4808 | ds_pool_ci.pNext = NULL; |
| 4809 | ds_pool_ci.flags = 0; |
| 4810 | ds_pool_ci.maxSets = 1; |
| 4811 | ds_pool_ci.poolSizeCount = 1; |
| 4812 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4813 | |
| 4814 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4815 | err = |
| 4816 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4817 | ASSERT_VK_SUCCESS(err); |
| 4818 | |
| 4819 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4820 | dsl_binding.binding = 0; |
| 4821 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4822 | dsl_binding.descriptorCount = 1; |
| 4823 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 4824 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4825 | |
| 4826 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4827 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4828 | ds_layout_ci.pNext = NULL; |
| 4829 | ds_layout_ci.bindingCount = 1; |
| 4830 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4831 | |
| 4832 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4833 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 4834 | &ds_layout); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4835 | ASSERT_VK_SUCCESS(err); |
| 4836 | |
| 4837 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 4838 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 4839 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4840 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 4841 | alloc_info.descriptorPool = ds_pool; |
| 4842 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4843 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 4844 | &descriptorSet); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4845 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4846 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4847 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 4848 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 4849 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4850 | } |
| 4851 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4852 | TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) { |
| 4853 | VkResult err; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4854 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4855 | m_errorMonitor->SetDesiredFailureMsg( |
| 4856 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4857 | "It is invalid to call vkFreeDescriptorSets() with a pool created " |
| 4858 | "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4859 | |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4860 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4861 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4862 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 4863 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4864 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4865 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4866 | |
| 4867 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4868 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 4869 | ds_pool_ci.pNext = NULL; |
| 4870 | ds_pool_ci.maxSets = 1; |
| 4871 | ds_pool_ci.poolSizeCount = 1; |
| 4872 | ds_pool_ci.flags = 0; |
| 4873 | // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means |
| 4874 | // app can only call vkResetDescriptorPool on this pool.; |
| 4875 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4876 | |
| 4877 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4878 | err = |
| 4879 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4880 | ASSERT_VK_SUCCESS(err); |
| 4881 | |
| 4882 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4883 | dsl_binding.binding = 0; |
| 4884 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4885 | dsl_binding.descriptorCount = 1; |
| 4886 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 4887 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4888 | |
| 4889 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4890 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4891 | ds_layout_ci.pNext = NULL; |
| 4892 | ds_layout_ci.bindingCount = 1; |
| 4893 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4894 | |
| 4895 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4896 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 4897 | &ds_layout); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4898 | ASSERT_VK_SUCCESS(err); |
| 4899 | |
| 4900 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 4901 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 4902 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4903 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 4904 | alloc_info.descriptorPool = ds_pool; |
| 4905 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4906 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 4907 | &descriptorSet); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4908 | ASSERT_VK_SUCCESS(err); |
| 4909 | |
| 4910 | err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4911 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4912 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 4913 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 4914 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4915 | } |
| 4916 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4917 | TEST_F(VkLayerTest, InvalidDescriptorPool) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4918 | // Attempt to clear Descriptor Pool with bad object. |
| 4919 | // ObjectTracker should catch this. |
| 4920 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4921 | "Invalid VkDescriptorPool Object 0xbaad6001"); |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4922 | uint64_t fake_pool_handle = 0xbaad6001; |
| 4923 | VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle); |
| 4924 | vkResetDescriptorPool(device(), bad_pool, 0); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4925 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4926 | } |
| 4927 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4928 | TEST_F(VkLayerTest, InvalidDescriptorSet) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4929 | // Attempt to bind an invalid Descriptor Set to a valid Command Buffer |
| 4930 | // ObjectTracker should catch this. |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4931 | // Create a valid cmd buffer |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4932 | // call vkCmdBindDescriptorSets w/ false Descriptor Set |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4933 | |
| 4934 | uint64_t fake_set_handle = 0xbaad6001; |
| 4935 | VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4936 | VkResult err; |
| 4937 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4938 | "Invalid VkDescriptorSet Object 0xbaad6001"); |
| 4939 | |
| 4940 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4941 | |
| 4942 | VkDescriptorSetLayoutBinding layout_bindings[1] = {}; |
| 4943 | layout_bindings[0].binding = 0; |
| 4944 | layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4945 | layout_bindings[0].descriptorCount = 1; |
| 4946 | layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; |
| 4947 | layout_bindings[0].pImmutableSamplers = NULL; |
| 4948 | |
| 4949 | VkDescriptorSetLayout descriptor_set_layout; |
| 4950 | VkDescriptorSetLayoutCreateInfo dslci = {}; |
| 4951 | dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4952 | dslci.pNext = NULL; |
| 4953 | dslci.bindingCount = 1; |
| 4954 | dslci.pBindings = layout_bindings; |
| 4955 | err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout); |
Karl Schultz | 5cb2111 | 2016-04-21 17:17:40 -0600 | [diff] [blame] | 4956 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4957 | |
| 4958 | VkPipelineLayout pipeline_layout; |
| 4959 | VkPipelineLayoutCreateInfo plci = {}; |
| 4960 | plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 4961 | plci.pNext = NULL; |
| 4962 | plci.setLayoutCount = 1; |
| 4963 | plci.pSetLayouts = &descriptor_set_layout; |
| 4964 | err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout); |
Karl Schultz | 5cb2111 | 2016-04-21 17:17:40 -0600 | [diff] [blame] | 4965 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4966 | |
| 4967 | BeginCommandBuffer(); |
| 4968 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4969 | pipeline_layout, 0, 1, &bad_set, 0, NULL); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4970 | m_errorMonitor->VerifyFound(); |
| 4971 | EndCommandBuffer(); |
| 4972 | vkDestroyPipelineLayout(device(), pipeline_layout, NULL); |
| 4973 | vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4974 | } |
| 4975 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4976 | TEST_F(VkLayerTest, InvalidDescriptorSetLayout) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4977 | // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout. |
| 4978 | // ObjectTracker should catch this. |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4979 | uint64_t fake_layout_handle = 0xbaad6001; |
| 4980 | VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4981 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4982 | "Invalid VkDescriptorSetLayout Object 0xbaad6001"); |
| 4983 | |
| 4984 | VkPipelineLayout pipeline_layout; |
| 4985 | VkPipelineLayoutCreateInfo plci = {}; |
| 4986 | plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 4987 | plci.pNext = NULL; |
| 4988 | plci.setLayoutCount = 1; |
| 4989 | plci.pSetLayouts = &bad_layout; |
| 4990 | vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout); |
| 4991 | |
| 4992 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4993 | } |
| 4994 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4995 | TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) { |
| 4996 | TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec " |
| 4997 | "1) A uniform buffer update must have a valid buffer index." |
| 4998 | "2) When using an array of descriptors in a single WriteDescriptor," |
| 4999 | " the descriptor types and stageflags must all be the same." |
| 5000 | "3) Immutable Sampler state must match across descriptors"); |
| 5001 | |
| 5002 | const char *invalid_BufferInfo_ErrorMessage = |
| 5003 | "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, " |
| 5004 | "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or " |
| 5005 | "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL"; |
| 5006 | const char *stateFlag_ErrorMessage = |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5007 | "Attempting write update to descriptor set "; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5008 | const char *immutable_ErrorMessage = |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5009 | "Attempting write update to descriptor set "; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5010 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5011 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage); |
| 5012 | |
| 5013 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5014 | VkDescriptorPoolSize ds_type_count[4] = {}; |
| 5015 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5016 | ds_type_count[0].descriptorCount = 1; |
| 5017 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 5018 | ds_type_count[1].descriptorCount = 1; |
| 5019 | ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 5020 | ds_type_count[2].descriptorCount = 1; |
| 5021 | ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 5022 | ds_type_count[3].descriptorCount = 1; |
| 5023 | |
| 5024 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 5025 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5026 | ds_pool_ci.maxSets = 1; |
| 5027 | ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize); |
| 5028 | ds_pool_ci.pPoolSizes = ds_type_count; |
| 5029 | |
| 5030 | VkDescriptorPool ds_pool; |
| 5031 | VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 5032 | ASSERT_VK_SUCCESS(err); |
| 5033 | |
Mark Mueller | b989672 | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5034 | VkDescriptorSetLayoutBinding layout_binding[3] = {}; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5035 | layout_binding[0].binding = 0; |
| 5036 | layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5037 | layout_binding[0].descriptorCount = 1; |
| 5038 | layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 5039 | layout_binding[0].pImmutableSamplers = NULL; |
| 5040 | |
| 5041 | layout_binding[1].binding = 1; |
| 5042 | layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 5043 | layout_binding[1].descriptorCount = 1; |
| 5044 | layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; |
| 5045 | layout_binding[1].pImmutableSamplers = NULL; |
| 5046 | |
| 5047 | VkSamplerCreateInfo sampler_ci = {}; |
| 5048 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 5049 | sampler_ci.pNext = NULL; |
| 5050 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 5051 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 5052 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 5053 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 5054 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 5055 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 5056 | sampler_ci.mipLodBias = 1.0; |
| 5057 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 5058 | sampler_ci.maxAnisotropy = 1; |
| 5059 | sampler_ci.compareEnable = VK_FALSE; |
| 5060 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 5061 | sampler_ci.minLod = 1.0; |
| 5062 | sampler_ci.maxLod = 1.0; |
| 5063 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 5064 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
| 5065 | VkSampler sampler; |
| 5066 | |
| 5067 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
| 5068 | ASSERT_VK_SUCCESS(err); |
| 5069 | |
| 5070 | layout_binding[2].binding = 2; |
| 5071 | layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 5072 | layout_binding[2].descriptorCount = 1; |
| 5073 | layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; |
| 5074 | layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler); |
| 5075 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5076 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 5077 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5078 | ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding); |
| 5079 | ds_layout_ci.pBindings = layout_binding; |
| 5080 | VkDescriptorSetLayout ds_layout; |
| 5081 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout); |
| 5082 | ASSERT_VK_SUCCESS(err); |
| 5083 | |
| 5084 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 5085 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 5086 | alloc_info.descriptorSetCount = 1; |
| 5087 | alloc_info.descriptorPool = ds_pool; |
| 5088 | alloc_info.pSetLayouts = &ds_layout; |
| 5089 | VkDescriptorSet descriptorSet; |
| 5090 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet); |
| 5091 | ASSERT_VK_SUCCESS(err); |
| 5092 | |
| 5093 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 5094 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5095 | pipeline_layout_ci.pNext = NULL; |
| 5096 | pipeline_layout_ci.setLayoutCount = 1; |
| 5097 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 5098 | |
| 5099 | VkPipelineLayout pipeline_layout; |
| 5100 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout); |
| 5101 | ASSERT_VK_SUCCESS(err); |
| 5102 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5103 | VkWriteDescriptorSet descriptor_write = {}; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5104 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5105 | descriptor_write.dstSet = descriptorSet; |
| 5106 | descriptor_write.dstBinding = 0; |
| 5107 | descriptor_write.descriptorCount = 1; |
| 5108 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5109 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5110 | // 1) The uniform buffer is intentionally invalid here |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5111 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5112 | m_errorMonitor->VerifyFound(); |
| 5113 | |
| 5114 | // Create a buffer to update the descriptor with |
| 5115 | uint32_t qfi = 0; |
| 5116 | VkBufferCreateInfo buffCI = {}; |
| 5117 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 5118 | buffCI.size = 1024; |
| 5119 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 5120 | buffCI.queueFamilyIndexCount = 1; |
| 5121 | buffCI.pQueueFamilyIndices = &qfi; |
| 5122 | |
| 5123 | VkBuffer dyub; |
| 5124 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 5125 | ASSERT_VK_SUCCESS(err); |
| 5126 | VkDescriptorBufferInfo buffInfo = {}; |
| 5127 | buffInfo.buffer = dyub; |
| 5128 | buffInfo.offset = 0; |
| 5129 | buffInfo.range = 1024; |
| 5130 | |
| 5131 | descriptor_write.pBufferInfo = &buffInfo; |
| 5132 | descriptor_write.descriptorCount = 2; |
| 5133 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5134 | // 2) The stateFlags don't match between the first and second descriptor |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5135 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage); |
| 5136 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5137 | m_errorMonitor->VerifyFound(); |
| 5138 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5139 | // 3) The second descriptor has a null_ptr pImmutableSamplers and |
| 5140 | // the third descriptor contains an immutable sampler |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5141 | descriptor_write.dstBinding = 1; |
| 5142 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 5143 | |
| 5144 | |
| 5145 | // Make pImageInfo index non-null to avoid complaints of it missing |
| 5146 | VkDescriptorImageInfo imageInfo = {}; |
| 5147 | imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 5148 | descriptor_write.pImageInfo = &imageInfo; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5149 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage); |
| 5150 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5151 | m_errorMonitor->VerifyFound(); |
| 5152 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 5153 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
| 5154 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 5155 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5156 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5157 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 5158 | } |
| 5159 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5160 | TEST_F(VkLayerTest, InvalidPipeline) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5161 | // Attempt to bind an invalid Pipeline to a valid Command Buffer |
| 5162 | // ObjectTracker should catch this. |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5163 | // Create a valid cmd buffer |
| 5164 | // call vkCmdBindPipeline w/ false Pipeline |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 5165 | uint64_t fake_pipeline_handle = 0xbaad6001; |
| 5166 | VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5167 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5168 | "Invalid VkPipeline Object 0xbaad6001"); |
| 5169 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5170 | BeginCommandBuffer(); |
| 5171 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 5172 | VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline); |
| 5173 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 5174 | // Now issue a draw call with no pipeline bound |
| 5175 | m_errorMonitor->SetDesiredFailureMsg( |
| 5176 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5177 | "At Draw/Dispatch time no valid VkPipeline is bound!"); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 5178 | |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 5179 | BeginCommandBuffer(); |
| 5180 | Draw(1, 0, 0, 0); |
| 5181 | m_errorMonitor->VerifyFound(); |
| 5182 | // Finally same check once more but with Dispatch/Compute |
| 5183 | m_errorMonitor->SetDesiredFailureMsg( |
| 5184 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5185 | "At Draw/Dispatch time no valid VkPipeline is bound!"); |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 5186 | BeginCommandBuffer(); |
| 5187 | vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0); |
| 5188 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 5189 | } |
| 5190 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5191 | TEST_F(VkLayerTest, DescriptorSetNotUpdated) { |
| 5192 | // Create and update CommandBuffer then call QueueSubmit w/o calling End on |
| 5193 | // CommandBuffer |
| 5194 | VkResult err; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5195 | |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 5196 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5197 | " bound but it was never updated. "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5198 | |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5199 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 5200 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5201 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 5202 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5203 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5204 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5205 | |
| 5206 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5207 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5208 | ds_pool_ci.pNext = NULL; |
| 5209 | ds_pool_ci.maxSets = 1; |
| 5210 | ds_pool_ci.poolSizeCount = 1; |
| 5211 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 5212 | |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5213 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5214 | err = |
| 5215 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5216 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5217 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5218 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5219 | dsl_binding.binding = 0; |
| 5220 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5221 | dsl_binding.descriptorCount = 1; |
| 5222 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5223 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5224 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5225 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5226 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5227 | ds_layout_ci.pNext = NULL; |
| 5228 | ds_layout_ci.bindingCount = 1; |
| 5229 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5230 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5231 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5232 | &ds_layout); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5233 | ASSERT_VK_SUCCESS(err); |
| 5234 | |
| 5235 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5236 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5237 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5238 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 5239 | alloc_info.descriptorPool = ds_pool; |
| 5240 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5241 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5242 | &descriptorSet); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5243 | ASSERT_VK_SUCCESS(err); |
| 5244 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5245 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5246 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5247 | pipeline_layout_ci.pNext = NULL; |
| 5248 | pipeline_layout_ci.setLayoutCount = 1; |
| 5249 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5250 | |
| 5251 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5252 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5253 | &pipeline_layout); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5254 | ASSERT_VK_SUCCESS(err); |
| 5255 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5256 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 5257 | VK_SHADER_STAGE_VERTEX_BIT, this); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5258 | // 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] | 5259 | // on more devices |
| 5260 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 5261 | VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5262 | |
Tony Barbour | c95e4ac | 2015-08-04 17:05:26 -0600 | [diff] [blame] | 5263 | VkPipelineObj pipe(m_device); |
| 5264 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 5265 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 5266 | pipe.AddColorAttachment(); |
Tony Barbour | c95e4ac | 2015-08-04 17:05:26 -0600 | [diff] [blame] | 5267 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 5268 | |
| 5269 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5270 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 5271 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 5272 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5273 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5274 | 1, &descriptorSet, 0, NULL); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5275 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5276 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 5277 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 5278 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5279 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5280 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 5281 | } |
| 5282 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5283 | TEST_F(VkLayerTest, InvalidBufferViewObject) { |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5284 | // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5285 | VkResult err; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5286 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5287 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5288 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer " |
| 5289 | "descriptor with invalid buffer view"); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5290 | |
| 5291 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5292 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5293 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5294 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5295 | |
| 5296 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5297 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5298 | ds_pool_ci.pNext = NULL; |
| 5299 | ds_pool_ci.maxSets = 1; |
| 5300 | ds_pool_ci.poolSizeCount = 1; |
| 5301 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5302 | |
| 5303 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5304 | err = |
| 5305 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5306 | ASSERT_VK_SUCCESS(err); |
| 5307 | |
| 5308 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5309 | dsl_binding.binding = 0; |
| 5310 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5311 | dsl_binding.descriptorCount = 1; |
| 5312 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5313 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5314 | |
| 5315 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5316 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5317 | ds_layout_ci.pNext = NULL; |
| 5318 | ds_layout_ci.bindingCount = 1; |
| 5319 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5320 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5321 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5322 | &ds_layout); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5323 | ASSERT_VK_SUCCESS(err); |
| 5324 | |
| 5325 | VkDescriptorSet descriptorSet; |
| 5326 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5327 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5328 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5329 | alloc_info.descriptorPool = ds_pool; |
| 5330 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5331 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5332 | &descriptorSet); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5333 | ASSERT_VK_SUCCESS(err); |
| 5334 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5335 | VkBufferView view = |
| 5336 | (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5337 | VkWriteDescriptorSet descriptor_write; |
| 5338 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 5339 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5340 | descriptor_write.dstSet = descriptorSet; |
| 5341 | descriptor_write.dstBinding = 0; |
| 5342 | descriptor_write.descriptorCount = 1; |
| 5343 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5344 | descriptor_write.pTexelBufferView = &view; |
| 5345 | |
| 5346 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5347 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5348 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5349 | |
| 5350 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5351 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 5352 | } |
| 5353 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5354 | TEST_F(VkLayerTest, InvalidDynamicOffsetCases) { |
| 5355 | // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error |
| 5356 | // cases: |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5357 | // 1. No dynamicOffset supplied |
| 5358 | // 2. Too many dynamicOffsets supplied |
| 5359 | // 3. Dynamic offset oversteps buffer being updated |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5360 | VkResult err; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 5361 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5362 | " requires 1 dynamicOffsets, but only " |
| 5363 | "0 dynamicOffsets are left in " |
| 5364 | "pDynamicOffsets "); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5365 | |
| 5366 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5367 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5368 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5369 | |
| 5370 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5371 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 5372 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5373 | |
| 5374 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5375 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5376 | ds_pool_ci.pNext = NULL; |
| 5377 | ds_pool_ci.maxSets = 1; |
| 5378 | ds_pool_ci.poolSizeCount = 1; |
| 5379 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5380 | |
| 5381 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5382 | err = |
| 5383 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5384 | ASSERT_VK_SUCCESS(err); |
| 5385 | |
| 5386 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5387 | dsl_binding.binding = 0; |
| 5388 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 5389 | dsl_binding.descriptorCount = 1; |
| 5390 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5391 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5392 | |
| 5393 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5394 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5395 | ds_layout_ci.pNext = NULL; |
| 5396 | ds_layout_ci.bindingCount = 1; |
| 5397 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5398 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5399 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5400 | &ds_layout); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5401 | ASSERT_VK_SUCCESS(err); |
| 5402 | |
| 5403 | VkDescriptorSet descriptorSet; |
| 5404 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5405 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5406 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5407 | alloc_info.descriptorPool = ds_pool; |
| 5408 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5409 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5410 | &descriptorSet); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5411 | ASSERT_VK_SUCCESS(err); |
| 5412 | |
| 5413 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5414 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5415 | pipeline_layout_ci.pNext = NULL; |
| 5416 | pipeline_layout_ci.setLayoutCount = 1; |
| 5417 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5418 | |
| 5419 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5420 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5421 | &pipeline_layout); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5422 | ASSERT_VK_SUCCESS(err); |
| 5423 | |
| 5424 | // Create a buffer to update the descriptor with |
| 5425 | uint32_t qfi = 0; |
| 5426 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5427 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 5428 | buffCI.size = 1024; |
| 5429 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 5430 | buffCI.queueFamilyIndexCount = 1; |
| 5431 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5432 | |
| 5433 | VkBuffer dyub; |
| 5434 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 5435 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5436 | // Allocate memory and bind to buffer so we can make it to the appropriate |
| 5437 | // error |
| 5438 | VkMemoryAllocateInfo mem_alloc = {}; |
| 5439 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 5440 | mem_alloc.pNext = NULL; |
| 5441 | mem_alloc.allocationSize = 1024; |
Chris Forbes | b6116cc | 2016-05-08 11:39:59 +1200 | [diff] [blame] | 5442 | mem_alloc.memoryTypeIndex = 0; |
| 5443 | |
| 5444 | VkMemoryRequirements memReqs; |
| 5445 | vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs); |
| 5446 | bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, |
| 5447 | 0); |
| 5448 | if (!pass) { |
| 5449 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
| 5450 | return; |
| 5451 | } |
| 5452 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5453 | VkDeviceMemory mem; |
| 5454 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 5455 | ASSERT_VK_SUCCESS(err); |
| 5456 | err = vkBindBufferMemory(m_device->device(), dyub, mem, 0); |
| 5457 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5458 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 5459 | VkDescriptorBufferInfo buffInfo = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5460 | buffInfo.buffer = dyub; |
| 5461 | buffInfo.offset = 0; |
| 5462 | buffInfo.range = 1024; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5463 | |
| 5464 | VkWriteDescriptorSet descriptor_write; |
| 5465 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 5466 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5467 | descriptor_write.dstSet = descriptorSet; |
| 5468 | descriptor_write.dstBinding = 0; |
| 5469 | descriptor_write.descriptorCount = 1; |
| 5470 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 5471 | descriptor_write.pBufferInfo = &buffInfo; |
| 5472 | |
| 5473 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5474 | |
| 5475 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5476 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5477 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5478 | 1, &descriptorSet, 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5479 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5480 | uint32_t pDynOff[2] = {512, 756}; |
| 5481 | // 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] | 5482 | m_errorMonitor->SetDesiredFailureMsg( |
| 5483 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5484 | "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5485 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5486 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5487 | 1, &descriptorSet, 2, pDynOff); |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5488 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5489 | // Finally cause error due to dynamicOffset being too big |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5490 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5491 | " dynamic offset 512 combined with " |
| 5492 | "offset 0 and range 1024 that " |
| 5493 | "oversteps the buffer size of 1024"); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5494 | // Create PSO to be used for draw-time errors below |
| 5495 | char const *vsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5496 | "#version 450\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5497 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 5498 | "out gl_PerVertex { \n" |
| 5499 | " vec4 gl_Position;\n" |
| 5500 | "};\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5501 | "void main(){\n" |
| 5502 | " gl_Position = vec4(1);\n" |
| 5503 | "}\n"; |
| 5504 | char const *fsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5505 | "#version 450\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5506 | "\n" |
| 5507 | "layout(location=0) out vec4 x;\n" |
| 5508 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 5509 | "void main(){\n" |
| 5510 | " x = vec4(bar.y);\n" |
| 5511 | "}\n"; |
| 5512 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 5513 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 5514 | VkPipelineObj pipe(m_device); |
| 5515 | pipe.AddShader(&vs); |
| 5516 | pipe.AddShader(&fs); |
| 5517 | pipe.AddColorAttachment(); |
| 5518 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 5519 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5520 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 5521 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 5522 | // This update should succeed, but offset size of 512 will overstep buffer |
| 5523 | // /w range 1024 & size 1024 |
| 5524 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5525 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5526 | 1, &descriptorSet, 1, pDynOff); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5527 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5528 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5529 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5530 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
Tobin Ehlis | 512098e | 2016-05-05 09:06:12 -0600 | [diff] [blame] | 5531 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5532 | |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5533 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 5534 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5535 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 5536 | } |
| 5537 | |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5538 | TEST_F(VkLayerTest, InvalidPushConstants) { |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5539 | VkResult err; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5540 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5541 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5542 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5543 | |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5544 | VkPipelineLayout pipeline_layout; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5545 | VkPushConstantRange pc_range = {}; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5546 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 5547 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5548 | pipeline_layout_ci.pushConstantRangeCount = 1; |
| 5549 | pipeline_layout_ci.pPushConstantRanges = &pc_range; |
| 5550 | |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5551 | // |
| 5552 | // Check for invalid push constant ranges in pipeline layouts. |
| 5553 | // |
| 5554 | struct PipelineLayoutTestCase { |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5555 | VkPushConstantRange const range; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5556 | char const *msg; |
| 5557 | }; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5558 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5559 | const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4; |
| 5560 | const std::array<PipelineLayoutTestCase, 10> range_tests = {{ |
| 5561 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, |
| 5562 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5563 | "size 0."}, |
| 5564 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1}, |
| 5565 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5566 | "size 1."}, |
| 5567 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1}, |
| 5568 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5569 | "size 1."}, |
| 5570 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0}, |
| 5571 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5572 | "size 0."}, |
| 5573 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4}, |
| 5574 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5575 | "offset 1. Offset must"}, |
| 5576 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big}, |
| 5577 | "vkCreatePipelineLayout() call has push constants index 0 " |
| 5578 | "with offset "}, |
| 5579 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big}, |
| 5580 | "vkCreatePipelineLayout() call has push constants " |
| 5581 | "index 0 with offset "}, |
| 5582 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0}, |
| 5583 | "vkCreatePipelineLayout() call has push constants index 0 " |
| 5584 | "with offset "}, |
| 5585 | {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020}, |
| 5586 | "vkCreatePipelineLayout() call has push " |
| 5587 | "constants index 0 with offset "}, |
| 5588 | {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0}, |
| 5589 | "vkCreatePipelineLayout() call has push " |
| 5590 | "constants index 0 with offset "}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5591 | }}; |
| 5592 | |
| 5593 | // Check for invalid offset and size |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5594 | for (const auto &iter : range_tests) { |
| 5595 | pc_range = iter.range; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5596 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5597 | iter.msg); |
| 5598 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 5599 | NULL, &pipeline_layout); |
| 5600 | m_errorMonitor->VerifyFound(); |
| 5601 | if (VK_SUCCESS == err) { |
| 5602 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5603 | } |
| 5604 | } |
| 5605 | |
| 5606 | // Check for invalid stage flag |
| 5607 | pc_range.offset = 0; |
| 5608 | pc_range.size = 16; |
| 5609 | pc_range.stageFlags = 0; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5610 | m_errorMonitor->SetDesiredFailureMsg( |
| 5611 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5612 | "vkCreatePipelineLayout() call has no stageFlags set."); |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5613 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5614 | &pipeline_layout); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5615 | m_errorMonitor->VerifyFound(); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5616 | if (VK_SUCCESS == err) { |
| 5617 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5618 | } |
| 5619 | |
| 5620 | // Check for overlapping ranges |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5621 | const uint32_t ranges_per_test = 5; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5622 | struct OverlappingRangeTestCase { |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5623 | VkPushConstantRange const ranges[ranges_per_test]; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5624 | char const *msg; |
| 5625 | }; |
| 5626 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5627 | const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5628 | {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5629 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5630 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5631 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5632 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5633 | "vkCreatePipelineLayout() call has push constants with overlapping " |
| 5634 | "ranges: 0:[0, 4), 1:[0, 4)"}, |
| 5635 | { |
| 5636 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5637 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5638 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5639 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 5640 | {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}}, |
| 5641 | "vkCreatePipelineLayout() call has push constants with " |
| 5642 | "overlapping " |
| 5643 | "ranges: 3:[12, 20), 4:[16, 20)", |
| 5644 | }, |
| 5645 | { |
| 5646 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5647 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 5648 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5649 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5650 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5651 | "vkCreatePipelineLayout() call has push constants with " |
| 5652 | "overlapping " |
| 5653 | "ranges: 0:[16, 20), 1:[12, 20)", |
| 5654 | }, |
| 5655 | { |
| 5656 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5657 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5658 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5659 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 5660 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5661 | "vkCreatePipelineLayout() call has push constants with " |
| 5662 | "overlapping " |
| 5663 | "ranges: 0:[16, 20), 3:[12, 20)", |
| 5664 | }, |
| 5665 | { |
| 5666 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5667 | {VK_SHADER_STAGE_VERTEX_BIT, 32, 4}, |
| 5668 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 96}, |
| 5669 | {VK_SHADER_STAGE_VERTEX_BIT, 40, 8}, |
| 5670 | {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}}, |
| 5671 | "vkCreatePipelineLayout() call has push constants with " |
| 5672 | "overlapping " |
| 5673 | "ranges: 0:[16, 20), 2:[4, 100)", |
| 5674 | }}}; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5675 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5676 | for (const auto &iter : overlapping_range_tests) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5677 | pipeline_layout_ci.pPushConstantRanges = iter.ranges; |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5678 | pipeline_layout_ci.pushConstantRangeCount = ranges_per_test; |
| 5679 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5680 | iter.msg); |
| 5681 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 5682 | NULL, &pipeline_layout); |
| 5683 | m_errorMonitor->VerifyFound(); |
| 5684 | if (VK_SUCCESS == err) { |
| 5685 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5686 | } |
| 5687 | } |
| 5688 | |
| 5689 | // 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] | 5690 | const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = |
| 5691 | {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5692 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5693 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5694 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 4}, |
| 5695 | {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}}, |
| 5696 | ""}, |
| 5697 | {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24}, |
| 5698 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 4}, |
| 5699 | {VK_SHADER_STAGE_VERTEX_BIT, 64, 8}, |
| 5700 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 16}, |
| 5701 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5702 | ""}}}; |
| 5703 | for (const auto &iter : overlapping_range_tests_pos) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5704 | pipeline_layout_ci.pPushConstantRanges = iter.ranges; |
| 5705 | m_errorMonitor->ExpectSuccess(); |
| 5706 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 5707 | NULL, &pipeline_layout); |
| 5708 | m_errorMonitor->VerifyNotFound(); |
| 5709 | if (VK_SUCCESS == err) { |
| 5710 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5711 | } |
| 5712 | } |
| 5713 | |
| 5714 | // |
| 5715 | // CmdPushConstants tests |
| 5716 | // |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5717 | const uint8_t dummy_values[100] = {}; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5718 | |
| 5719 | // 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] | 5720 | const std::array<PipelineLayoutTestCase, 16> cmd_range_tests = {{ |
| 5721 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, |
| 5722 | "vkCmdPushConstants() call has push constants with size 0. Size " |
| 5723 | "must be greater than zero and a multiple of 4."}, |
| 5724 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1}, |
| 5725 | "vkCmdPushConstants() call has push constants with size 1. Size " |
| 5726 | "must be greater than zero and a multiple of 4."}, |
| 5727 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1}, |
| 5728 | "vkCmdPushConstants() call has push constants with size 1. Size " |
| 5729 | "must be greater than zero and a multiple of 4."}, |
| 5730 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0}, |
| 5731 | "vkCmdPushConstants() call has push constants with offset 1. " |
| 5732 | "Offset must be a multiple of 4."}, |
| 5733 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4}, |
| 5734 | "vkCmdPushConstants() call has push constants with offset 1. " |
| 5735 | "Offset must be a multiple of 4."}, |
| 5736 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20}, |
| 5737 | "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = " |
| 5738 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5739 | {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8}, |
| 5740 | "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = " |
| 5741 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5742 | {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8}, |
| 5743 | "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = " |
| 5744 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5745 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80}, |
| 5746 | "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = " |
| 5747 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5748 | {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4}, |
| 5749 | "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in " |
| 5750 | "any of the ranges in pipeline layout"}, |
| 5751 | {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, |
| 5752 | 0, 16}, |
| 5753 | "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in " |
| 5754 | "any of the ranges in pipeline layout"}, |
| 5755 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5756 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5757 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5758 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5759 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5760 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5761 | {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5762 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5763 | {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5764 | "vkCmdPushConstants() call has push constants with offset "}, |
| 5765 | }}; |
| 5766 | |
| 5767 | // Two ranges for testing robustness |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5768 | const VkPushConstantRange pc_range2[] = { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5769 | {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5770 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5771 | }; |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5772 | pipeline_layout_ci.pushConstantRangeCount = |
| 5773 | sizeof(pc_range2) / sizeof(VkPushConstantRange); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5774 | pipeline_layout_ci.pPushConstantRanges = pc_range2; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5775 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5776 | &pipeline_layout); |
| 5777 | ASSERT_VK_SUCCESS(err); |
| 5778 | BeginCommandBuffer(); |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5779 | for (const auto &iter : cmd_range_tests) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5780 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5781 | iter.msg); |
| 5782 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5783 | iter.range.stageFlags, iter.range.offset, |
| 5784 | iter.range.size, dummy_values); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5785 | m_errorMonitor->VerifyFound(); |
| 5786 | } |
| 5787 | |
| 5788 | // Check for invalid stage flag |
| 5789 | m_errorMonitor->SetDesiredFailureMsg( |
| 5790 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5791 | "vkCmdPushConstants() call has no stageFlags set."); |
| 5792 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5793 | 0, 16, dummy_values); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5794 | m_errorMonitor->VerifyFound(); |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5795 | EndCommandBuffer(); |
| 5796 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
| 5797 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5798 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5799 | // overlapping range tests with cmd |
| 5800 | const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{ |
| 5801 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20}, |
| 5802 | "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = " |
| 5803 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5804 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5805 | "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = " |
| 5806 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5807 | {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16}, |
| 5808 | "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = " |
| 5809 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5810 | }}; |
| 5811 | const VkPushConstantRange pc_range3[] = { |
| 5812 | {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, |
| 5813 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
| 5814 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5815 | {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, |
| 5816 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, |
| 5817 | {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, |
| 5818 | {VK_SHADER_STAGE_VERTEX_BIT, 56, 28}, |
| 5819 | }; |
| 5820 | pipeline_layout_ci.pushConstantRangeCount = |
| 5821 | sizeof(pc_range3) / sizeof(VkPushConstantRange); |
| 5822 | pipeline_layout_ci.pPushConstantRanges = pc_range3; |
| 5823 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5824 | &pipeline_layout); |
| 5825 | ASSERT_VK_SUCCESS(err); |
| 5826 | BeginCommandBuffer(); |
| 5827 | for (const auto &iter : cmd_overlap_tests) { |
| 5828 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5829 | iter.msg); |
| 5830 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
| 5831 | iter.range.stageFlags, iter.range.offset, |
| 5832 | iter.range.size, dummy_values); |
| 5833 | m_errorMonitor->VerifyFound(); |
| 5834 | } |
| 5835 | EndCommandBuffer(); |
| 5836 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
| 5837 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5838 | |
| 5839 | // positive overlapping range tests with cmd |
| 5840 | const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{ |
| 5841 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""}, |
| 5842 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""}, |
| 5843 | {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""}, |
| 5844 | {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""}, |
| 5845 | }}; |
| 5846 | const VkPushConstantRange pc_range4[] = { |
| 5847 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 64}, |
| 5848 | {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, |
| 5849 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
| 5850 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5851 | {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, |
| 5852 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, |
| 5853 | {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, |
| 5854 | {VK_SHADER_STAGE_VERTEX_BIT, 56, 28}, |
| 5855 | }; |
| 5856 | pipeline_layout_ci.pushConstantRangeCount = |
| 5857 | sizeof(pc_range4) / sizeof(VkPushConstantRange); |
| 5858 | pipeline_layout_ci.pPushConstantRanges = pc_range4; |
| 5859 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5860 | &pipeline_layout); |
| 5861 | ASSERT_VK_SUCCESS(err); |
| 5862 | BeginCommandBuffer(); |
| 5863 | for (const auto &iter : cmd_overlap_tests_pos) { |
| 5864 | m_errorMonitor->ExpectSuccess(); |
| 5865 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
| 5866 | iter.range.stageFlags, iter.range.offset, |
| 5867 | iter.range.size, dummy_values); |
| 5868 | m_errorMonitor->VerifyNotFound(); |
| 5869 | } |
| 5870 | EndCommandBuffer(); |
| 5871 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5872 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5873 | } |
| 5874 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5875 | TEST_F(VkLayerTest, DescriptorSetCompatibility) { |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5876 | // Test various desriptorSet errors with bad binding combinations |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5877 | VkResult err; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5878 | |
| 5879 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5880 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5881 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5882 | |
| 5883 | static const uint32_t NUM_DESCRIPTOR_TYPES = 5; |
| 5884 | VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5885 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5886 | ds_type_count[0].descriptorCount = 10; |
| 5887 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 5888 | ds_type_count[1].descriptorCount = 2; |
| 5889 | ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
| 5890 | ds_type_count[2].descriptorCount = 2; |
| 5891 | ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 5892 | ds_type_count[3].descriptorCount = 5; |
| 5893 | // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT |
| 5894 | // type |
| 5895 | // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 5896 | ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
| 5897 | ds_type_count[4].descriptorCount = 2; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5898 | |
| 5899 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5900 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5901 | ds_pool_ci.pNext = NULL; |
| 5902 | ds_pool_ci.maxSets = 5; |
| 5903 | ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES; |
| 5904 | ds_pool_ci.pPoolSizes = ds_type_count; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5905 | |
| 5906 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5907 | err = |
| 5908 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5909 | ASSERT_VK_SUCCESS(err); |
| 5910 | |
| 5911 | static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2; |
| 5912 | VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5913 | dsl_binding[0].binding = 0; |
| 5914 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5915 | dsl_binding[0].descriptorCount = 5; |
| 5916 | dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 5917 | dsl_binding[0].pImmutableSamplers = NULL; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5918 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5919 | // Create layout identical to set0 layout but w/ different stageFlags |
| 5920 | VkDescriptorSetLayoutBinding dsl_fs_stage_only = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5921 | dsl_fs_stage_only.binding = 0; |
| 5922 | dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5923 | dsl_fs_stage_only.descriptorCount = 5; |
| 5924 | dsl_fs_stage_only.stageFlags = |
| 5925 | VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at |
| 5926 | // bind time |
| 5927 | dsl_fs_stage_only.pImmutableSamplers = NULL; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5928 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5929 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5930 | ds_layout_ci.pNext = NULL; |
| 5931 | ds_layout_ci.bindingCount = 1; |
| 5932 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5933 | static const uint32_t NUM_LAYOUTS = 4; |
| 5934 | VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5935 | VkDescriptorSetLayout ds_layout_fs_only = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5936 | // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only |
| 5937 | // layout for error case |
| 5938 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5939 | &ds_layout[0]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5940 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 5941 | ds_layout_ci.pBindings = &dsl_fs_stage_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5942 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5943 | &ds_layout_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5944 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5945 | dsl_binding[0].binding = 0; |
| 5946 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5947 | dsl_binding[0].descriptorCount = 2; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 5948 | dsl_binding[1].binding = 1; |
| 5949 | dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
| 5950 | dsl_binding[1].descriptorCount = 2; |
| 5951 | dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL; |
| 5952 | dsl_binding[1].pImmutableSamplers = NULL; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 5953 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5954 | ds_layout_ci.bindingCount = 2; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5955 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5956 | &ds_layout[1]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5957 | ASSERT_VK_SUCCESS(err); |
| 5958 | dsl_binding[0].binding = 0; |
| 5959 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5960 | dsl_binding[0].descriptorCount = 5; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5961 | ds_layout_ci.bindingCount = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5962 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5963 | &ds_layout[2]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5964 | ASSERT_VK_SUCCESS(err); |
| 5965 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5966 | dsl_binding[0].descriptorCount = 2; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5967 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5968 | &ds_layout[3]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5969 | ASSERT_VK_SUCCESS(err); |
| 5970 | |
| 5971 | static const uint32_t NUM_SETS = 4; |
| 5972 | VkDescriptorSet descriptorSet[NUM_SETS] = {}; |
| 5973 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5974 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5975 | alloc_info.descriptorSetCount = NUM_LAYOUTS; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5976 | alloc_info.descriptorPool = ds_pool; |
| 5977 | alloc_info.pSetLayouts = ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5978 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5979 | descriptorSet); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5980 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5981 | VkDescriptorSet ds0_fs_only = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5982 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5983 | alloc_info.pSetLayouts = &ds_layout_fs_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5984 | err = |
| 5985 | vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5986 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5987 | |
| 5988 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5989 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5990 | pipeline_layout_ci.pNext = NULL; |
| 5991 | pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS; |
| 5992 | pipeline_layout_ci.pSetLayouts = ds_layout; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5993 | |
| 5994 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5995 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5996 | &pipeline_layout); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5997 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5998 | // Create pipelineLayout with only one setLayout |
| 5999 | pipeline_layout_ci.setLayoutCount = 1; |
| 6000 | VkPipelineLayout single_pipe_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6001 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6002 | &single_pipe_layout); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6003 | ASSERT_VK_SUCCESS(err); |
| 6004 | // Create pipelineLayout with 2 descriptor setLayout at index 0 |
| 6005 | pipeline_layout_ci.pSetLayouts = &ds_layout[3]; |
| 6006 | VkPipelineLayout pipe_layout_one_desc; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6007 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6008 | &pipe_layout_one_desc); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6009 | ASSERT_VK_SUCCESS(err); |
| 6010 | // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0 |
| 6011 | pipeline_layout_ci.pSetLayouts = &ds_layout[2]; |
| 6012 | VkPipelineLayout pipe_layout_five_samp; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6013 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6014 | &pipe_layout_five_samp); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6015 | ASSERT_VK_SUCCESS(err); |
| 6016 | // Create pipelineLayout with UB type, but stageFlags for FS only |
| 6017 | pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only; |
| 6018 | VkPipelineLayout pipe_layout_fs_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6019 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6020 | &pipe_layout_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6021 | ASSERT_VK_SUCCESS(err); |
| 6022 | // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine |
| 6023 | VkDescriptorSetLayout pl_bad_s0[2] = {}; |
| 6024 | pl_bad_s0[0] = ds_layout_fs_only; |
| 6025 | pl_bad_s0[1] = ds_layout[1]; |
| 6026 | pipeline_layout_ci.setLayoutCount = 2; |
| 6027 | pipeline_layout_ci.pSetLayouts = pl_bad_s0; |
| 6028 | VkPipelineLayout pipe_layout_bad_set0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6029 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6030 | &pipe_layout_bad_set0); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6031 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6032 | |
| 6033 | // Create a buffer to update the descriptor with |
| 6034 | uint32_t qfi = 0; |
| 6035 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6036 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 6037 | buffCI.size = 1024; |
| 6038 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 6039 | buffCI.queueFamilyIndexCount = 1; |
| 6040 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6041 | |
| 6042 | VkBuffer dyub; |
| 6043 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 6044 | ASSERT_VK_SUCCESS(err); |
| 6045 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 6046 | static const uint32_t NUM_BUFFS = 5; |
| 6047 | VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6048 | for (uint32_t i = 0; i < NUM_BUFFS; ++i) { |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6049 | buffInfo[i].buffer = dyub; |
| 6050 | buffInfo[i].offset = 0; |
| 6051 | buffInfo[i].range = 1024; |
| 6052 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6053 | VkImage image; |
| 6054 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 6055 | const int32_t tex_width = 32; |
| 6056 | const int32_t tex_height = 32; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6057 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6058 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 6059 | image_create_info.pNext = NULL; |
| 6060 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 6061 | image_create_info.format = tex_format; |
| 6062 | image_create_info.extent.width = tex_width; |
| 6063 | image_create_info.extent.height = tex_height; |
| 6064 | image_create_info.extent.depth = 1; |
| 6065 | image_create_info.mipLevels = 1; |
| 6066 | image_create_info.arrayLayers = 1; |
| 6067 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 6068 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 6069 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 6070 | image_create_info.flags = 0; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6071 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 6072 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6073 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6074 | VkMemoryRequirements memReqs; |
| 6075 | VkDeviceMemory imageMem; |
| 6076 | bool pass; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 6077 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6078 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 6079 | memAlloc.pNext = NULL; |
| 6080 | memAlloc.allocationSize = 0; |
| 6081 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 6082 | vkGetImageMemoryRequirements(m_device->device(), image, &memReqs); |
| 6083 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6084 | pass = |
| 6085 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 6086 | ASSERT_TRUE(pass); |
| 6087 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem); |
| 6088 | ASSERT_VK_SUCCESS(err); |
| 6089 | err = vkBindImageMemory(m_device->device(), image, imageMem, 0); |
| 6090 | ASSERT_VK_SUCCESS(err); |
| 6091 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6092 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6093 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 6094 | image_view_create_info.image = image; |
| 6095 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 6096 | image_view_create_info.format = tex_format; |
| 6097 | image_view_create_info.subresourceRange.layerCount = 1; |
| 6098 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 6099 | image_view_create_info.subresourceRange.levelCount = 1; |
| 6100 | image_view_create_info.subresourceRange.aspectMask = |
| 6101 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6102 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6103 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6104 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 6105 | &view); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6106 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6107 | VkDescriptorImageInfo imageInfo[4] = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6108 | imageInfo[0].imageView = view; |
| 6109 | imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 6110 | imageInfo[1].imageView = view; |
| 6111 | imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6112 | imageInfo[2].imageView = view; |
| 6113 | imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 6114 | imageInfo[3].imageView = view; |
| 6115 | imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6116 | |
| 6117 | static const uint32_t NUM_SET_UPDATES = 3; |
| 6118 | VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {}; |
| 6119 | descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 6120 | descriptor_write[0].dstSet = descriptorSet[0]; |
| 6121 | descriptor_write[0].dstBinding = 0; |
| 6122 | descriptor_write[0].descriptorCount = 5; |
| 6123 | descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6124 | descriptor_write[0].pBufferInfo = buffInfo; |
| 6125 | descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 6126 | descriptor_write[1].dstSet = descriptorSet[1]; |
| 6127 | descriptor_write[1].dstBinding = 0; |
| 6128 | descriptor_write[1].descriptorCount = 2; |
| 6129 | descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 6130 | descriptor_write[1].pImageInfo = imageInfo; |
| 6131 | descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 6132 | descriptor_write[2].dstSet = descriptorSet[1]; |
| 6133 | descriptor_write[2].dstBinding = 1; |
| 6134 | descriptor_write[2].descriptorCount = 2; |
| 6135 | descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6136 | descriptor_write[2].pImageInfo = &imageInfo[2]; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6137 | |
| 6138 | vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6139 | |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6140 | // Create PSO to be used for draw-time errors below |
| 6141 | char const *vsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 6142 | "#version 450\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6143 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 6144 | "out gl_PerVertex {\n" |
| 6145 | " vec4 gl_Position;\n" |
| 6146 | "};\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6147 | "void main(){\n" |
| 6148 | " gl_Position = vec4(1);\n" |
| 6149 | "}\n"; |
| 6150 | char const *fsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 6151 | "#version 450\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6152 | "\n" |
| 6153 | "layout(location=0) out vec4 x;\n" |
| 6154 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 6155 | "void main(){\n" |
| 6156 | " x = vec4(bar.y);\n" |
| 6157 | "}\n"; |
| 6158 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6159 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6160 | VkPipelineObj pipe(m_device); |
| 6161 | pipe.AddShader(&vs); |
| 6162 | pipe.AddShader(&fs); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6163 | pipe.AddColorAttachment(); |
| 6164 | pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass()); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6165 | |
| 6166 | BeginCommandBuffer(); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6167 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6168 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 6169 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 6170 | // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding |
| 6171 | // of PSO |
| 6172 | // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of |
| 6173 | // cmd_pipeline.c |
| 6174 | // due to the fact that cmd_alloc_dset_data() has not been called in |
| 6175 | // cmd_bind_graphics_pipeline() |
| 6176 | // TODO : Want to cause various binding incompatibility issues here to test |
| 6177 | // DrawState |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6178 | // First cause various verify_layout_compatibility() fails |
| 6179 | // Second disturb early and late sets and verify INFO msgs |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6180 | // verify_set_layout_compatibility fail cases: |
| 6181 | // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6182 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6183 | " due to: invalid VkPipelineLayout "); |
| 6184 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6185 | VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6186 | (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, |
| 6187 | &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6188 | m_errorMonitor->VerifyFound(); |
| 6189 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6190 | // 2. layoutIndex exceeds # of layouts in layout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6191 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6192 | " attempting to bind set to index 1"); |
| 6193 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6194 | VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, |
| 6195 | 0, 2, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6196 | m_errorMonitor->VerifyFound(); |
| 6197 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6198 | vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6199 | // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5 |
| 6200 | // descriptors |
| 6201 | m_errorMonitor->SetDesiredFailureMsg( |
| 6202 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 6203 | " has 2 descriptors, but DescriptorSetLayout "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6204 | vkCmdBindDescriptorSets( |
| 6205 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6206 | pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6207 | m_errorMonitor->VerifyFound(); |
| 6208 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6209 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL); |
| 6210 | // 4. same # of descriptors but mismatch in type |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6211 | m_errorMonitor->SetDesiredFailureMsg( |
| 6212 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 6213 | " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6214 | vkCmdBindDescriptorSets( |
| 6215 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6216 | pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6217 | m_errorMonitor->VerifyFound(); |
| 6218 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6219 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL); |
| 6220 | // 5. same # of descriptors but mismatch in stageFlags |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6221 | m_errorMonitor->SetDesiredFailureMsg( |
| 6222 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 6223 | " has stageFlags 16 but binding 0 for DescriptorSetLayout "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6224 | vkCmdBindDescriptorSets( |
| 6225 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6226 | pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6227 | m_errorMonitor->VerifyFound(); |
| 6228 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6229 | // Cause INFO messages due to disturbing previously bound Sets |
| 6230 | // First bind sets 0 & 1 |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6231 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6232 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6233 | 2, &descriptorSet[0], 0, NULL); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6234 | // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6235 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 6236 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6237 | " previously bound as set #0 was disturbed "); |
| 6238 | vkCmdBindDescriptorSets( |
| 6239 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6240 | pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6241 | m_errorMonitor->VerifyFound(); |
| 6242 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6243 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6244 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6245 | 2, &descriptorSet[0], 0, NULL); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6246 | // 2. Disturb set after last bound set |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 6247 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6248 | " newly bound as set #0 so set #1 and " |
| 6249 | "any subsequent sets were disturbed "); |
| 6250 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6251 | VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6252 | pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6253 | m_errorMonitor->VerifyFound(); |
| 6254 | |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6255 | // Cause draw-time errors due to PSO incompatibilities |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6256 | // 1. Error due to not binding required set (we actually use same code as |
| 6257 | // above to disturb set0) |
| 6258 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6259 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6260 | 2, &descriptorSet[0], 0, NULL); |
| 6261 | vkCmdBindDescriptorSets( |
| 6262 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6263 | pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL); |
| 6264 | m_errorMonitor->SetDesiredFailureMsg( |
| 6265 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6266 | " uses set #0 but that set is not bound."); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6267 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6268 | m_errorMonitor->VerifyFound(); |
| 6269 | |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6270 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6271 | // 2. Error due to bound set not being compatible with PSO's |
| 6272 | // VkPipelineLayout (diff stageFlags in this case) |
| 6273 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6274 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6275 | 2, &descriptorSet[0], 0, NULL); |
| 6276 | m_errorMonitor->SetDesiredFailureMsg( |
| 6277 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6278 | " bound as set #0 is not compatible with "); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6279 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6280 | m_errorMonitor->VerifyFound(); |
| 6281 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6282 | // Remaining clean-up |
| 6283 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6284 | for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) { |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6285 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL); |
| 6286 | } |
| 6287 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL); |
Tobin Ehlis | 9bfd449 | 2016-05-05 15:09:11 -0600 | [diff] [blame] | 6288 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only); |
| 6289 | vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6290 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6291 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6292 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 6293 | vkFreeMemory(m_device->device(), imageMem, NULL); |
| 6294 | vkDestroyImage(m_device->device(), image, NULL); |
| 6295 | vkDestroyImageView(m_device->device(), view, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6296 | } |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6297 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6298 | TEST_F(VkLayerTest, NoBeginCommandBuffer) { |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6299 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6300 | m_errorMonitor->SetDesiredFailureMsg( |
| 6301 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6302 | "You must call vkBeginCommandBuffer() before this call to "); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6303 | |
| 6304 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6305 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6306 | // Call EndCommandBuffer() w/o calling BeginCommandBuffer() |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6307 | vkEndCommandBuffer(commandBuffer.GetBufferHandle()); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6308 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6309 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6310 | } |
| 6311 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6312 | TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) { |
| 6313 | VkResult err; |
| 6314 | VkCommandBuffer draw_cmd; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6315 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6316 | m_errorMonitor->SetDesiredFailureMsg( |
| 6317 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 61b36f3 | 2015-12-16 08:19:42 -0700 | [diff] [blame] | 6318 | " must specify a valid renderpass parameter."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6319 | |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6320 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6321 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6322 | VkCommandBufferAllocateInfo cmd = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6323 | cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6324 | cmd.pNext = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6325 | cmd.commandPool = m_commandPool; |
| 6326 | cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6327 | cmd.commandBufferCount = 1; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6328 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6329 | err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 6330 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6331 | |
| 6332 | // Force the failure by not setting the Renderpass and Framebuffer fields |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6333 | VkCommandBufferBeginInfo cmd_buf_info = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6334 | VkCommandBufferInheritanceInfo cmd_buf_hinfo = {}; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6335 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6336 | cmd_buf_info.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6337 | cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | |
| 6338 | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6339 | cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo; |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6340 | |
| 6341 | // The error should be caught by validation of the BeginCommandBuffer call |
| 6342 | vkBeginCommandBuffer(draw_cmd, &cmd_buf_info); |
| 6343 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6344 | m_errorMonitor->VerifyFound(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6345 | vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6346 | } |
| 6347 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6348 | TEST_F(VkLayerTest, CommandBufferResetErrors) { |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6349 | // Cause error due to Begin while recording CB |
| 6350 | // Then cause 2 errors for attempting to reset CB w/o having |
| 6351 | // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from |
| 6352 | // which CBs were allocated. Note that this bit is off by default. |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 6353 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6354 | "Cannot call Begin on CB"); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6355 | |
| 6356 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6357 | |
| 6358 | // Calls AllocateCommandBuffers |
| 6359 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
| 6360 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6361 | // Force the failure by setting the Renderpass and Framebuffer fields with |
| 6362 | // (fake) data |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6363 | VkCommandBufferBeginInfo cmd_buf_info = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6364 | VkCommandBufferInheritanceInfo cmd_buf_hinfo = {}; |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6365 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 6366 | cmd_buf_info.pNext = NULL; |
| 6367 | cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6368 | cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo; |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6369 | |
| 6370 | // Begin CB to transition to recording state |
| 6371 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
| 6372 | // Can't re-begin. This should trigger error |
| 6373 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6374 | m_errorMonitor->VerifyFound(); |
| 6375 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6376 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6377 | "Attempt to reset command buffer "); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6378 | VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test |
| 6379 | // Reset attempt will trigger error due to incorrect CommandPool state |
| 6380 | vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6381 | m_errorMonitor->VerifyFound(); |
| 6382 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6383 | m_errorMonitor->SetDesiredFailureMsg( |
| 6384 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6385 | " attempts to implicitly reset cmdBuffer created from "); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6386 | // Transition CB to RECORDED state |
| 6387 | vkEndCommandBuffer(commandBuffer.GetBufferHandle()); |
| 6388 | // Now attempting to Begin will implicitly reset, which triggers error |
| 6389 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6390 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6391 | } |
| 6392 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6393 | TEST_F(VkLayerTest, InvalidPipelineCreateState) { |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6394 | // Attempt to Create Gfx Pipeline w/o a VS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6395 | VkResult err; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6396 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6397 | m_errorMonitor->SetDesiredFailureMsg( |
| 6398 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6399 | "Invalid Pipeline CreateInfo State: Vtx Shader required"); |
| 6400 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6401 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 6402 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 6403 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6404 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6405 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6406 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6407 | |
| 6408 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6409 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6410 | ds_pool_ci.pNext = NULL; |
| 6411 | ds_pool_ci.maxSets = 1; |
| 6412 | ds_pool_ci.poolSizeCount = 1; |
| 6413 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 6414 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6415 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6416 | err = |
| 6417 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6418 | ASSERT_VK_SUCCESS(err); |
| 6419 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6420 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6421 | dsl_binding.binding = 0; |
| 6422 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6423 | dsl_binding.descriptorCount = 1; |
| 6424 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 6425 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6426 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6427 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6428 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6429 | ds_layout_ci.pNext = NULL; |
| 6430 | ds_layout_ci.bindingCount = 1; |
| 6431 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6432 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6433 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6434 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6435 | &ds_layout); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6436 | ASSERT_VK_SUCCESS(err); |
| 6437 | |
| 6438 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6439 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6440 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6441 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6442 | alloc_info.descriptorPool = ds_pool; |
| 6443 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6444 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6445 | &descriptorSet); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6446 | ASSERT_VK_SUCCESS(err); |
| 6447 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6448 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6449 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6450 | pipeline_layout_ci.setLayoutCount = 1; |
| 6451 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6452 | |
| 6453 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6454 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6455 | &pipeline_layout); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6456 | ASSERT_VK_SUCCESS(err); |
| 6457 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6458 | VkViewport vp = {}; // Just need dummy vp to point to |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6459 | VkRect2D sc = {}; // dummy scissor to point to |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6460 | |
| 6461 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6462 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 6463 | vp_state_ci.scissorCount = 1; |
| 6464 | vp_state_ci.pScissors = ≻ |
| 6465 | vp_state_ci.viewportCount = 1; |
| 6466 | vp_state_ci.pViewports = &vp; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6467 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6468 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 6469 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 6470 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 6471 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 6472 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 6473 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 6474 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 6475 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 6476 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6477 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6478 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6479 | gp_ci.pViewportState = &vp_state_ci; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6480 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6481 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6482 | gp_ci.layout = pipeline_layout; |
| 6483 | gp_ci.renderPass = renderPass(); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6484 | |
| 6485 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6486 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 6487 | pc_ci.initialDataSize = 0; |
| 6488 | pc_ci.pInitialData = 0; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6489 | |
| 6490 | VkPipeline pipeline; |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 6491 | VkPipelineCache pipelineCache; |
| 6492 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6493 | err = |
| 6494 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 6495 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6496 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6497 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6498 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6499 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 6500 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6501 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6502 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6503 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6504 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6505 | } |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6506 | /*// TODO : This test should be good, but needs Tess support in compiler to run |
| 6507 | TEST_F(VkLayerTest, InvalidPatchControlPoints) |
| 6508 | { |
| 6509 | // Attempt to Create Gfx Pipeline w/o a VS |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6510 | VkResult err; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6511 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 6512 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6513 | "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH |
| 6514 | primitive "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6515 | |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6516 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6517 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6518 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6519 | VkDescriptorPoolSize ds_type_count = {}; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6520 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6521 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6522 | |
| 6523 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 6524 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6525 | ds_pool_ci.pNext = NULL; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6526 | ds_pool_ci.poolSizeCount = 1; |
| 6527 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6528 | |
| 6529 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6530 | err = vkCreateDescriptorPool(m_device->device(), |
| 6531 | 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] | 6532 | ASSERT_VK_SUCCESS(err); |
| 6533 | |
| 6534 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6535 | dsl_binding.binding = 0; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6536 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | 0212448 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 6537 | dsl_binding.descriptorCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6538 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 6539 | dsl_binding.pImmutableSamplers = NULL; |
| 6540 | |
| 6541 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6542 | ds_layout_ci.sType = |
| 6543 | VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6544 | ds_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6545 | ds_layout_ci.bindingCount = 1; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 6546 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6547 | |
| 6548 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6549 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6550 | &ds_layout); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6551 | ASSERT_VK_SUCCESS(err); |
| 6552 | |
| 6553 | VkDescriptorSet descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6554 | err = vkAllocateDescriptorSets(m_device->device(), ds_pool, |
| 6555 | VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6556 | ASSERT_VK_SUCCESS(err); |
| 6557 | |
| 6558 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6559 | pipeline_layout_ci.sType = |
| 6560 | VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6561 | pipeline_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6562 | pipeline_layout_ci.setLayoutCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6563 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 6564 | |
| 6565 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6566 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6567 | &pipeline_layout); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6568 | ASSERT_VK_SUCCESS(err); |
| 6569 | |
| 6570 | VkPipelineShaderStageCreateInfo shaderStages[3]; |
| 6571 | memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 6572 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6573 | VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, |
| 6574 | this); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6575 | // 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] | 6576 | VkShaderObj |
| 6577 | tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, |
| 6578 | this); |
| 6579 | VkShaderObj |
| 6580 | te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, |
| 6581 | this); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6582 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6583 | shaderStages[0].sType = |
| 6584 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 6585 | shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6586 | shaderStages[0].shader = vs.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6587 | shaderStages[1].sType = |
| 6588 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 6589 | shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6590 | shaderStages[1].shader = tc.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6591 | shaderStages[2].sType = |
| 6592 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 6593 | shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6594 | shaderStages[2].shader = te.handle(); |
| 6595 | |
| 6596 | VkPipelineInputAssemblyStateCreateInfo iaCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6597 | iaCI.sType = |
| 6598 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
Chia-I Wu | 515eb8f | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6599 | iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6600 | |
| 6601 | VkPipelineTessellationStateCreateInfo tsCI = {}; |
| 6602 | tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO; |
| 6603 | tsCI.patchControlPoints = 0; // This will cause an error |
| 6604 | |
| 6605 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 6606 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6607 | gp_ci.pNext = NULL; |
| 6608 | gp_ci.stageCount = 3; |
| 6609 | gp_ci.pStages = shaderStages; |
| 6610 | gp_ci.pVertexInputState = NULL; |
| 6611 | gp_ci.pInputAssemblyState = &iaCI; |
| 6612 | gp_ci.pTessellationState = &tsCI; |
| 6613 | gp_ci.pViewportState = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6614 | gp_ci.pRasterizationState = NULL; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6615 | gp_ci.pMultisampleState = NULL; |
| 6616 | gp_ci.pDepthStencilState = NULL; |
| 6617 | gp_ci.pColorBlendState = NULL; |
| 6618 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6619 | gp_ci.layout = pipeline_layout; |
| 6620 | gp_ci.renderPass = renderPass(); |
| 6621 | |
| 6622 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 6623 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 6624 | pc_ci.pNext = NULL; |
| 6625 | pc_ci.initialSize = 0; |
| 6626 | pc_ci.initialData = 0; |
| 6627 | pc_ci.maxSize = 0; |
| 6628 | |
| 6629 | VkPipeline pipeline; |
| 6630 | VkPipelineCache pipelineCache; |
| 6631 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6632 | err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, |
| 6633 | &pipelineCache); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6634 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6635 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6636 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6637 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6638 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 6639 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6640 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6641 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6642 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6643 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6644 | } |
| 6645 | */ |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6646 | // Set scissor and viewport counts to different numbers |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6647 | TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6648 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6649 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6650 | m_errorMonitor->SetDesiredFailureMsg( |
| 6651 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6652 | "Gfx Pipeline viewport count (1) must match scissor count (0)."); |
| 6653 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6654 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6655 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6656 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6657 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6658 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6659 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6660 | |
| 6661 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6662 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6663 | ds_pool_ci.maxSets = 1; |
| 6664 | ds_pool_ci.poolSizeCount = 1; |
| 6665 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6666 | |
| 6667 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6668 | err = |
| 6669 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6670 | ASSERT_VK_SUCCESS(err); |
| 6671 | |
| 6672 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6673 | dsl_binding.binding = 0; |
| 6674 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6675 | dsl_binding.descriptorCount = 1; |
| 6676 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6677 | |
| 6678 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6679 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6680 | ds_layout_ci.bindingCount = 1; |
| 6681 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6682 | |
| 6683 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6684 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6685 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6686 | ASSERT_VK_SUCCESS(err); |
| 6687 | |
| 6688 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6689 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6690 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6691 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6692 | alloc_info.descriptorPool = ds_pool; |
| 6693 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6694 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6695 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6696 | ASSERT_VK_SUCCESS(err); |
| 6697 | |
| 6698 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6699 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6700 | pipeline_layout_ci.setLayoutCount = 1; |
| 6701 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6702 | |
| 6703 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6704 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6705 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6706 | ASSERT_VK_SUCCESS(err); |
| 6707 | |
| 6708 | VkViewport vp = {}; // Just need dummy vp to point to |
| 6709 | |
| 6710 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6711 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 6712 | vp_state_ci.scissorCount = 0; |
| 6713 | vp_state_ci.viewportCount = 1; // Count mismatch should cause error |
| 6714 | vp_state_ci.pViewports = &vp; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6715 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6716 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 6717 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 6718 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 6719 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 6720 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 6721 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 6722 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 6723 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 6724 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 6725 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6726 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6727 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6728 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 6729 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6730 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 6731 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6732 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6733 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6734 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 6735 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6736 | |
| 6737 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6738 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6739 | gp_ci.stageCount = 2; |
| 6740 | gp_ci.pStages = shaderStages; |
| 6741 | gp_ci.pViewportState = &vp_state_ci; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6742 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6743 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6744 | gp_ci.layout = pipeline_layout; |
| 6745 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6746 | |
| 6747 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6748 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6749 | |
| 6750 | VkPipeline pipeline; |
| 6751 | VkPipelineCache pipelineCache; |
| 6752 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6753 | err = |
| 6754 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6755 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6756 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6757 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6758 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6759 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6760 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6761 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6762 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6763 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6764 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6765 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6766 | // Don't set viewport state in PSO. This is an error b/c we always need this |
| 6767 | // state |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 6768 | // 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] | 6769 | TEST_F(VkLayerTest, PSOViewportStateNotSet) { |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6770 | // Attempt to Create Gfx Pipeline w/o a VS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6771 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6772 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6773 | m_errorMonitor->SetDesiredFailureMsg( |
| 6774 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6775 | "Gfx Pipeline pViewportState is null. Even if "); |
| 6776 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6777 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6778 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6779 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6780 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6781 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6782 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6783 | |
| 6784 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6785 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6786 | ds_pool_ci.maxSets = 1; |
| 6787 | ds_pool_ci.poolSizeCount = 1; |
| 6788 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6789 | |
| 6790 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6791 | err = |
| 6792 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6793 | ASSERT_VK_SUCCESS(err); |
| 6794 | |
| 6795 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6796 | dsl_binding.binding = 0; |
| 6797 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6798 | dsl_binding.descriptorCount = 1; |
| 6799 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6800 | |
| 6801 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6802 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6803 | ds_layout_ci.bindingCount = 1; |
| 6804 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6805 | |
| 6806 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6807 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6808 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6809 | ASSERT_VK_SUCCESS(err); |
| 6810 | |
| 6811 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6812 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6813 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6814 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6815 | alloc_info.descriptorPool = ds_pool; |
| 6816 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6817 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6818 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6819 | ASSERT_VK_SUCCESS(err); |
| 6820 | |
| 6821 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6822 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6823 | pipeline_layout_ci.setLayoutCount = 1; |
| 6824 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6825 | |
| 6826 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6827 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6828 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6829 | ASSERT_VK_SUCCESS(err); |
| 6830 | |
| 6831 | VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR; |
| 6832 | // Set scissor as dynamic to avoid second error |
| 6833 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6834 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 6835 | dyn_state_ci.dynamicStateCount = 1; |
| 6836 | dyn_state_ci.pDynamicStates = &sc_state; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6837 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 6838 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6839 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6840 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6841 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 6842 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6843 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 6844 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6845 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6846 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6847 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 6848 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6849 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6850 | |
| 6851 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 6852 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 6853 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 6854 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 6855 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 6856 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 6857 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 6858 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 6859 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6860 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6861 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6862 | gp_ci.stageCount = 2; |
| 6863 | gp_ci.pStages = shaderStages; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6864 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6865 | gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state |
| 6866 | // should cause validation error |
| 6867 | gp_ci.pDynamicState = &dyn_state_ci; |
| 6868 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6869 | gp_ci.layout = pipeline_layout; |
| 6870 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6871 | |
| 6872 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6873 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6874 | |
| 6875 | VkPipeline pipeline; |
| 6876 | VkPipelineCache pipelineCache; |
| 6877 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6878 | err = |
| 6879 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6880 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6881 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6882 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6883 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6884 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6885 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6886 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6887 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6888 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6889 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6890 | } |
| 6891 | // Create PSO w/o non-zero viewportCount but no viewport data |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6892 | // Then run second test where dynamic scissor count doesn't match PSO scissor |
| 6893 | // count |
| 6894 | TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) { |
| 6895 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6896 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6897 | m_errorMonitor->SetDesiredFailureMsg( |
| 6898 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6899 | "Gfx Pipeline viewportCount is 1, but pViewports is NULL. "); |
| 6900 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6901 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6902 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6903 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6904 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6905 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6906 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6907 | |
| 6908 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6909 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6910 | ds_pool_ci.maxSets = 1; |
| 6911 | ds_pool_ci.poolSizeCount = 1; |
| 6912 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6913 | |
| 6914 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6915 | err = |
| 6916 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6917 | ASSERT_VK_SUCCESS(err); |
| 6918 | |
| 6919 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6920 | dsl_binding.binding = 0; |
| 6921 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6922 | dsl_binding.descriptorCount = 1; |
| 6923 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6924 | |
| 6925 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6926 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6927 | ds_layout_ci.bindingCount = 1; |
| 6928 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6929 | |
| 6930 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6931 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6932 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6933 | ASSERT_VK_SUCCESS(err); |
| 6934 | |
| 6935 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6936 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6937 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6938 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6939 | alloc_info.descriptorPool = ds_pool; |
| 6940 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6941 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6942 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6943 | ASSERT_VK_SUCCESS(err); |
| 6944 | |
| 6945 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6946 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6947 | pipeline_layout_ci.setLayoutCount = 1; |
| 6948 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6949 | |
| 6950 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6951 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6952 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6953 | ASSERT_VK_SUCCESS(err); |
| 6954 | |
| 6955 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6956 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 6957 | vp_state_ci.viewportCount = 1; |
| 6958 | vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error |
| 6959 | vp_state_ci.scissorCount = 1; |
| 6960 | vp_state_ci.pScissors = |
| 6961 | NULL; // Scissor is dynamic (below) so this won't cause error |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6962 | |
| 6963 | VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR; |
| 6964 | // Set scissor as dynamic to avoid that error |
| 6965 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6966 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 6967 | dyn_state_ci.dynamicStateCount = 1; |
| 6968 | dyn_state_ci.pDynamicStates = &sc_state; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6969 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 6970 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6971 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6972 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6973 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 6974 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6975 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 6976 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6977 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6978 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6979 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 6980 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6981 | |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6982 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 6983 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 6984 | vi_ci.pNext = nullptr; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6985 | vi_ci.vertexBindingDescriptionCount = 0; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6986 | vi_ci.pVertexBindingDescriptions = nullptr; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6987 | vi_ci.vertexAttributeDescriptionCount = 0; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6988 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 6989 | |
| 6990 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 6991 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 6992 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 6993 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6994 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6995 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6996 | rs_ci.pNext = nullptr; |
| 6997 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 6998 | VkPipelineColorBlendAttachmentState att = {}; |
| 6999 | att.blendEnable = VK_FALSE; |
| 7000 | att.colorWriteMask = 0xf; |
| 7001 | |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7002 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 7003 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 7004 | cb_ci.pNext = nullptr; |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 7005 | cb_ci.attachmentCount = 1; |
| 7006 | cb_ci.pAttachments = &att; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 7007 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7008 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7009 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7010 | gp_ci.stageCount = 2; |
| 7011 | gp_ci.pStages = shaderStages; |
| 7012 | gp_ci.pVertexInputState = &vi_ci; |
| 7013 | gp_ci.pInputAssemblyState = &ia_ci; |
| 7014 | gp_ci.pViewportState = &vp_state_ci; |
| 7015 | gp_ci.pRasterizationState = &rs_ci; |
| 7016 | gp_ci.pColorBlendState = &cb_ci; |
| 7017 | gp_ci.pDynamicState = &dyn_state_ci; |
| 7018 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7019 | gp_ci.layout = pipeline_layout; |
| 7020 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7021 | |
| 7022 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7023 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7024 | |
| 7025 | VkPipeline pipeline; |
| 7026 | VkPipelineCache pipelineCache; |
| 7027 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7028 | err = |
| 7029 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7030 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7031 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7032 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7033 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7034 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7035 | |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7036 | // 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] | 7037 | // First need to successfully create the PSO from above by setting |
| 7038 | // pViewports |
| 7039 | m_errorMonitor->SetDesiredFailureMsg( |
| 7040 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7041 | "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO " |
| 7042 | "scissorCount is 1. These counts must match."); |
| 7043 | |
| 7044 | VkViewport vp = {}; // Just need dummy vp to point to |
| 7045 | vp_state_ci.pViewports = &vp; |
| 7046 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7047 | &gp_ci, NULL, &pipeline); |
| 7048 | ASSERT_VK_SUCCESS(err); |
| 7049 | BeginCommandBuffer(); |
| 7050 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7051 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 7052 | VkRect2D scissors[2] = {}; // don't care about data |
| 7053 | // Count of 2 doesn't match PSO count of 1 |
| 7054 | vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors); |
| 7055 | Draw(1, 0, 0, 0); |
| 7056 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7057 | m_errorMonitor->VerifyFound(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7058 | |
| 7059 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7060 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7061 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7062 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7063 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7064 | } |
| 7065 | // Create PSO w/o non-zero scissorCount but no scissor data |
| 7066 | // Then run second test where dynamic viewportCount doesn't match PSO |
| 7067 | // viewportCount |
| 7068 | TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) { |
| 7069 | VkResult err; |
| 7070 | |
| 7071 | m_errorMonitor->SetDesiredFailureMsg( |
| 7072 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7073 | "Gfx Pipeline scissorCount is 1, but pScissors is NULL. "); |
| 7074 | |
| 7075 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7076 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7077 | |
| 7078 | VkDescriptorPoolSize ds_type_count = {}; |
| 7079 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7080 | ds_type_count.descriptorCount = 1; |
| 7081 | |
| 7082 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 7083 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7084 | ds_pool_ci.maxSets = 1; |
| 7085 | ds_pool_ci.poolSizeCount = 1; |
| 7086 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 7087 | |
| 7088 | VkDescriptorPool ds_pool; |
| 7089 | err = |
| 7090 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 7091 | ASSERT_VK_SUCCESS(err); |
| 7092 | |
| 7093 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 7094 | dsl_binding.binding = 0; |
| 7095 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7096 | dsl_binding.descriptorCount = 1; |
| 7097 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7098 | |
| 7099 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 7100 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7101 | ds_layout_ci.bindingCount = 1; |
| 7102 | ds_layout_ci.pBindings = &dsl_binding; |
| 7103 | |
| 7104 | VkDescriptorSetLayout ds_layout; |
| 7105 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7106 | &ds_layout); |
| 7107 | ASSERT_VK_SUCCESS(err); |
| 7108 | |
| 7109 | VkDescriptorSet descriptorSet; |
| 7110 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 7111 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 7112 | alloc_info.descriptorSetCount = 1; |
| 7113 | alloc_info.descriptorPool = ds_pool; |
| 7114 | alloc_info.pSetLayouts = &ds_layout; |
| 7115 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7116 | &descriptorSet); |
| 7117 | ASSERT_VK_SUCCESS(err); |
| 7118 | |
| 7119 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 7120 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7121 | pipeline_layout_ci.setLayoutCount = 1; |
| 7122 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 7123 | |
| 7124 | VkPipelineLayout pipeline_layout; |
| 7125 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7126 | &pipeline_layout); |
| 7127 | ASSERT_VK_SUCCESS(err); |
| 7128 | |
| 7129 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 7130 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7131 | vp_state_ci.scissorCount = 1; |
| 7132 | vp_state_ci.pScissors = |
| 7133 | NULL; // Null scissor w/ count of 1 should cause error |
| 7134 | vp_state_ci.viewportCount = 1; |
| 7135 | vp_state_ci.pViewports = |
| 7136 | NULL; // vp is dynamic (below) so this won't cause error |
| 7137 | |
| 7138 | VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT; |
| 7139 | // Set scissor as dynamic to avoid that error |
| 7140 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
| 7141 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 7142 | dyn_state_ci.dynamicStateCount = 1; |
| 7143 | dyn_state_ci.pDynamicStates = &vp_state; |
| 7144 | |
| 7145 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
| 7146 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 7147 | |
| 7148 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7149 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7150 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7151 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 7152 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7153 | // but add it to be able to run on more devices |
| 7154 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 7155 | shaderStages[1] = fs.GetStageCreateInfo(); |
| 7156 | |
| 7157 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 7158 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 7159 | vi_ci.pNext = nullptr; |
| 7160 | vi_ci.vertexBindingDescriptionCount = 0; |
| 7161 | vi_ci.pVertexBindingDescriptions = nullptr; |
| 7162 | vi_ci.vertexAttributeDescriptionCount = 0; |
| 7163 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 7164 | |
| 7165 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 7166 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 7167 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 7168 | |
| 7169 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
| 7170 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7171 | rs_ci.pNext = nullptr; |
| 7172 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 7173 | VkPipelineColorBlendAttachmentState att = {}; |
| 7174 | att.blendEnable = VK_FALSE; |
| 7175 | att.colorWriteMask = 0xf; |
| 7176 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7177 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 7178 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 7179 | cb_ci.pNext = nullptr; |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 7180 | cb_ci.attachmentCount = 1; |
| 7181 | cb_ci.pAttachments = &att; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7182 | |
| 7183 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 7184 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7185 | gp_ci.stageCount = 2; |
| 7186 | gp_ci.pStages = shaderStages; |
| 7187 | gp_ci.pVertexInputState = &vi_ci; |
| 7188 | gp_ci.pInputAssemblyState = &ia_ci; |
| 7189 | gp_ci.pViewportState = &vp_state_ci; |
| 7190 | gp_ci.pRasterizationState = &rs_ci; |
| 7191 | gp_ci.pColorBlendState = &cb_ci; |
| 7192 | gp_ci.pDynamicState = &dyn_state_ci; |
| 7193 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7194 | gp_ci.layout = pipeline_layout; |
| 7195 | gp_ci.renderPass = renderPass(); |
| 7196 | |
| 7197 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 7198 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 7199 | |
| 7200 | VkPipeline pipeline; |
| 7201 | VkPipelineCache pipelineCache; |
| 7202 | |
| 7203 | err = |
| 7204 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7205 | ASSERT_VK_SUCCESS(err); |
| 7206 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7207 | &gp_ci, NULL, &pipeline); |
| 7208 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7209 | m_errorMonitor->VerifyFound(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7210 | |
| 7211 | // Now hit second fail case where we set scissor w/ different count than PSO |
| 7212 | // First need to successfully create the PSO from above by setting |
| 7213 | // pViewports |
| 7214 | m_errorMonitor->SetDesiredFailureMsg( |
| 7215 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7216 | "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO " |
| 7217 | "viewportCount is 1. These counts must match."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7218 | |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7219 | VkRect2D sc = {}; // Just need dummy vp to point to |
| 7220 | vp_state_ci.pScissors = ≻ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7221 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7222 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7223 | ASSERT_VK_SUCCESS(err); |
| 7224 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7225 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7226 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7227 | VkViewport viewports[2] = {}; // don't care about data |
| 7228 | // Count of 2 doesn't match PSO count of 1 |
Jon Ashburn | 19d3bf1 | 2015-12-30 14:06:55 -0700 | [diff] [blame] | 7229 | vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7230 | Draw(1, 0, 0, 0); |
| 7231 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7232 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7233 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7234 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7235 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7236 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7237 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7238 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7239 | } |
| 7240 | |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7241 | TEST_F(VkLayerTest, PSOLineWidthInvalid) { |
| 7242 | VkResult err; |
| 7243 | |
| 7244 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7245 | "Attempt to set lineWidth to -1"); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7246 | |
| 7247 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7248 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7249 | |
| 7250 | VkDescriptorPoolSize ds_type_count = {}; |
| 7251 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7252 | ds_type_count.descriptorCount = 1; |
| 7253 | |
| 7254 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 7255 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7256 | ds_pool_ci.maxSets = 1; |
| 7257 | ds_pool_ci.poolSizeCount = 1; |
| 7258 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 7259 | |
| 7260 | VkDescriptorPool ds_pool; |
| 7261 | err = |
| 7262 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 7263 | ASSERT_VK_SUCCESS(err); |
| 7264 | |
| 7265 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 7266 | dsl_binding.binding = 0; |
| 7267 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7268 | dsl_binding.descriptorCount = 1; |
| 7269 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7270 | |
| 7271 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 7272 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7273 | ds_layout_ci.bindingCount = 1; |
| 7274 | ds_layout_ci.pBindings = &dsl_binding; |
| 7275 | |
| 7276 | VkDescriptorSetLayout ds_layout; |
| 7277 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7278 | &ds_layout); |
| 7279 | ASSERT_VK_SUCCESS(err); |
| 7280 | |
| 7281 | VkDescriptorSet descriptorSet; |
| 7282 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 7283 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 7284 | alloc_info.descriptorSetCount = 1; |
| 7285 | alloc_info.descriptorPool = ds_pool; |
| 7286 | alloc_info.pSetLayouts = &ds_layout; |
| 7287 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7288 | &descriptorSet); |
| 7289 | ASSERT_VK_SUCCESS(err); |
| 7290 | |
| 7291 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 7292 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7293 | pipeline_layout_ci.setLayoutCount = 1; |
| 7294 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 7295 | |
| 7296 | VkPipelineLayout pipeline_layout; |
| 7297 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7298 | &pipeline_layout); |
| 7299 | ASSERT_VK_SUCCESS(err); |
| 7300 | |
| 7301 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 7302 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7303 | vp_state_ci.scissorCount = 1; |
| 7304 | vp_state_ci.pScissors = NULL; |
| 7305 | vp_state_ci.viewportCount = 1; |
| 7306 | vp_state_ci.pViewports = NULL; |
| 7307 | |
| 7308 | VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, |
| 7309 | VK_DYNAMIC_STATE_SCISSOR, |
| 7310 | VK_DYNAMIC_STATE_LINE_WIDTH}; |
| 7311 | // Set scissor as dynamic to avoid that error |
| 7312 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
| 7313 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 7314 | dyn_state_ci.dynamicStateCount = 2; |
| 7315 | dyn_state_ci.pDynamicStates = dynamic_states; |
| 7316 | |
| 7317 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
| 7318 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 7319 | |
| 7320 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7321 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7322 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7323 | VK_SHADER_STAGE_FRAGMENT_BIT, |
| 7324 | this); // TODO - We shouldn't need a fragment shader |
| 7325 | // but add it to be able to run on more devices |
| 7326 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 7327 | shaderStages[1] = fs.GetStageCreateInfo(); |
| 7328 | |
| 7329 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 7330 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 7331 | vi_ci.pNext = nullptr; |
| 7332 | vi_ci.vertexBindingDescriptionCount = 0; |
| 7333 | vi_ci.pVertexBindingDescriptions = nullptr; |
| 7334 | vi_ci.vertexAttributeDescriptionCount = 0; |
| 7335 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 7336 | |
| 7337 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 7338 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 7339 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 7340 | |
| 7341 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
| 7342 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7343 | rs_ci.pNext = nullptr; |
| 7344 | |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7345 | // Check too low (line width of -1.0f). |
| 7346 | rs_ci.lineWidth = -1.0f; |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7347 | |
| 7348 | VkPipelineColorBlendAttachmentState att = {}; |
| 7349 | att.blendEnable = VK_FALSE; |
| 7350 | att.colorWriteMask = 0xf; |
| 7351 | |
| 7352 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 7353 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 7354 | cb_ci.pNext = nullptr; |
| 7355 | cb_ci.attachmentCount = 1; |
| 7356 | cb_ci.pAttachments = &att; |
| 7357 | |
| 7358 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 7359 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7360 | gp_ci.stageCount = 2; |
| 7361 | gp_ci.pStages = shaderStages; |
| 7362 | gp_ci.pVertexInputState = &vi_ci; |
| 7363 | gp_ci.pInputAssemblyState = &ia_ci; |
| 7364 | gp_ci.pViewportState = &vp_state_ci; |
| 7365 | gp_ci.pRasterizationState = &rs_ci; |
| 7366 | gp_ci.pColorBlendState = &cb_ci; |
| 7367 | gp_ci.pDynamicState = &dyn_state_ci; |
| 7368 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7369 | gp_ci.layout = pipeline_layout; |
| 7370 | gp_ci.renderPass = renderPass(); |
| 7371 | |
| 7372 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 7373 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 7374 | |
| 7375 | VkPipeline pipeline; |
| 7376 | VkPipelineCache pipelineCache; |
| 7377 | |
| 7378 | err = |
| 7379 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7380 | ASSERT_VK_SUCCESS(err); |
| 7381 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7382 | &gp_ci, NULL, &pipeline); |
| 7383 | |
| 7384 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7385 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7386 | |
| 7387 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7388 | "Attempt to set lineWidth to 65536"); |
| 7389 | |
| 7390 | // Check too high (line width of 65536.0f). |
| 7391 | rs_ci.lineWidth = 65536.0f; |
| 7392 | |
| 7393 | err = |
| 7394 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7395 | ASSERT_VK_SUCCESS(err); |
| 7396 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7397 | &gp_ci, NULL, &pipeline); |
| 7398 | |
| 7399 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7400 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7401 | |
| 7402 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7403 | "Attempt to set lineWidth to -1"); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7404 | |
| 7405 | dyn_state_ci.dynamicStateCount = 3; |
| 7406 | |
| 7407 | rs_ci.lineWidth = 1.0f; |
| 7408 | |
| 7409 | err = |
| 7410 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7411 | ASSERT_VK_SUCCESS(err); |
| 7412 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7413 | &gp_ci, NULL, &pipeline); |
| 7414 | BeginCommandBuffer(); |
| 7415 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7416 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 7417 | |
| 7418 | // Check too low with dynamic setting. |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7419 | vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7420 | m_errorMonitor->VerifyFound(); |
| 7421 | |
| 7422 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7423 | "Attempt to set lineWidth to 65536"); |
| 7424 | |
| 7425 | // Check too high with dynamic setting. |
| 7426 | vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f); |
| 7427 | m_errorMonitor->VerifyFound(); |
| 7428 | EndCommandBuffer(); |
| 7429 | |
| 7430 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7431 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7432 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7433 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7434 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7435 | } |
| 7436 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7437 | TEST_F(VkLayerTest, NullRenderPass) { |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7438 | // Bind a NULL RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7439 | m_errorMonitor->SetDesiredFailureMsg( |
| 7440 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7441 | "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()"); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7442 | |
| 7443 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7444 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7445 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 7446 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7447 | // Don't care about RenderPass handle b/c error should be flagged before |
| 7448 | // that |
| 7449 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, |
| 7450 | VK_SUBPASS_CONTENTS_INLINE); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7451 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7452 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7453 | } |
| 7454 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7455 | TEST_F(VkLayerTest, RenderPassWithinRenderPass) { |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7456 | // Bind a BeginRenderPass within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7457 | m_errorMonitor->SetDesiredFailureMsg( |
| 7458 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7459 | "It is invalid to issue this call inside an active render pass"); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7460 | |
| 7461 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7462 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7463 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 7464 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7465 | // Just create a dummy Renderpass that's non-NULL so we can get to the |
| 7466 | // proper error |
Chris Forbes | 38ae7c4 | 2016-06-21 20:51:44 +1200 | [diff] [blame] | 7467 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7468 | VK_SUBPASS_CONTENTS_INLINE); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7469 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7470 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 7471 | } |
| 7472 | |
Chris Forbes | 2eeabe3 | 2016-06-21 20:52:34 +1200 | [diff] [blame] | 7473 | TEST_F(VkLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) { |
| 7474 | m_errorMonitor->ExpectSuccess(); |
| 7475 | |
| 7476 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7477 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7478 | |
| 7479 | BeginCommandBuffer(); // framework implicitly begins the renderpass. |
| 7480 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // end implicit. |
| 7481 | |
| 7482 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, |
| 7483 | VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS); |
| 7484 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 7485 | m_errorMonitor->VerifyNotFound(); |
| 7486 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, |
| 7487 | VK_SUBPASS_CONTENTS_INLINE); |
| 7488 | m_errorMonitor->VerifyNotFound(); |
| 7489 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 7490 | m_errorMonitor->VerifyNotFound(); |
| 7491 | |
| 7492 | m_commandBuffer->EndCommandBuffer(); |
| 7493 | m_errorMonitor->VerifyNotFound(); |
| 7494 | } |
| 7495 | |
Tobin Ehlis | 5a1c033 | 2016-05-31 13:59:26 -0600 | [diff] [blame] | 7496 | TEST_F(VkLayerTest, RenderPassClearOpMismatch) { |
| 7497 | TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than" |
| 7498 | "the number of renderPass attachments that use loadOp" |
| 7499 | "VK_ATTACHMENT_LOAD_OP_CLEAR."); |
| 7500 | |
| 7501 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7502 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7503 | |
| 7504 | // Create a renderPass with a single attachment that uses loadOp CLEAR |
| 7505 | VkAttachmentReference attach = {}; |
| 7506 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 7507 | VkSubpassDescription subpass = {}; |
| 7508 | subpass.inputAttachmentCount = 1; |
| 7509 | subpass.pInputAttachments = &attach; |
| 7510 | VkRenderPassCreateInfo rpci = {}; |
| 7511 | rpci.subpassCount = 1; |
| 7512 | rpci.pSubpasses = &subpass; |
| 7513 | rpci.attachmentCount = 1; |
| 7514 | VkAttachmentDescription attach_desc = {}; |
| 7515 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 7516 | // Set loadOp to CLEAR |
| 7517 | attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 7518 | rpci.pAttachments = &attach_desc; |
| 7519 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 7520 | VkRenderPass rp; |
| 7521 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 7522 | |
| 7523 | VkCommandBufferInheritanceInfo hinfo = {}; |
| 7524 | hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; |
| 7525 | hinfo.renderPass = VK_NULL_HANDLE; |
| 7526 | hinfo.subpass = 0; |
| 7527 | hinfo.framebuffer = VK_NULL_HANDLE; |
| 7528 | hinfo.occlusionQueryEnable = VK_FALSE; |
| 7529 | hinfo.queryFlags = 0; |
| 7530 | hinfo.pipelineStatistics = 0; |
| 7531 | VkCommandBufferBeginInfo info = {}; |
| 7532 | info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
| 7533 | info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 7534 | info.pInheritanceInfo = &hinfo; |
| 7535 | |
| 7536 | vkBeginCommandBuffer(m_commandBuffer->handle(), &info); |
| 7537 | VkRenderPassBeginInfo rp_begin = {}; |
| 7538 | rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 7539 | rp_begin.pNext = NULL; |
| 7540 | rp_begin.renderPass = renderPass(); |
| 7541 | rp_begin.framebuffer = framebuffer(); |
| 7542 | rp_begin.clearValueCount = 0; // Should be 1 |
| 7543 | |
| 7544 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7545 | " has a clearValueCount of 0 but the " |
| 7546 | "actual number of attachments in " |
| 7547 | "renderPass "); |
| 7548 | |
| 7549 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, |
| 7550 | VK_SUBPASS_CONTENTS_INLINE); |
| 7551 | |
| 7552 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 5c70ebd | 2016-06-09 13:45:00 -0600 | [diff] [blame] | 7553 | |
| 7554 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 5a1c033 | 2016-05-31 13:59:26 -0600 | [diff] [blame] | 7555 | } |
| 7556 | |
Cody Northrop | 3bb4d96 | 2016-05-09 16:15:57 -0600 | [diff] [blame] | 7557 | TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) { |
| 7558 | |
| 7559 | TEST_DESCRIPTION("End a command buffer with an active render pass"); |
| 7560 | |
| 7561 | m_errorMonitor->SetDesiredFailureMsg( |
| 7562 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7563 | "It is invalid to issue this call inside an active render pass"); |
| 7564 | |
| 7565 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7566 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7567 | |
| 7568 | // The framework's BeginCommandBuffer calls CreateRenderPass |
| 7569 | BeginCommandBuffer(); |
| 7570 | |
| 7571 | // Call directly into vkEndCommandBuffer instead of the |
| 7572 | // the framework's EndCommandBuffer, which inserts a |
| 7573 | // vkEndRenderPass |
| 7574 | vkEndCommandBuffer(m_commandBuffer->GetBufferHandle()); |
| 7575 | |
| 7576 | m_errorMonitor->VerifyFound(); |
| 7577 | |
| 7578 | // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY |
| 7579 | // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT |
| 7580 | } |
| 7581 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7582 | TEST_F(VkLayerTest, FillBufferWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7583 | // Call CmdFillBuffer within an active renderpass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7584 | m_errorMonitor->SetDesiredFailureMsg( |
| 7585 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7586 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7587 | |
| 7588 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7589 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7590 | |
| 7591 | // Renderpass is started here |
| 7592 | BeginCommandBuffer(); |
| 7593 | |
| 7594 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7595 | vk_testing::Buffer dstBuffer; |
| 7596 | dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7597 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7598 | m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7599 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7600 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7601 | } |
| 7602 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7603 | TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7604 | // Call CmdUpdateBuffer within an active renderpass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7605 | m_errorMonitor->SetDesiredFailureMsg( |
| 7606 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7607 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7608 | |
| 7609 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7610 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7611 | |
| 7612 | // Renderpass is started here |
| 7613 | BeginCommandBuffer(); |
| 7614 | |
| 7615 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7616 | vk_testing::Buffer dstBuffer; |
| 7617 | dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7618 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7619 | VkDeviceSize dstOffset = 0; |
| 7620 | VkDeviceSize dataSize = 1024; |
| 7621 | const uint32_t *pData = NULL; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7622 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7623 | vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), |
| 7624 | dstOffset, dataSize, pData); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7625 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7626 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7627 | } |
| 7628 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7629 | TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7630 | // Call CmdClearColorImage within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7631 | m_errorMonitor->SetDesiredFailureMsg( |
| 7632 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7633 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7634 | |
| 7635 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7636 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7637 | |
| 7638 | // Renderpass is started here |
| 7639 | BeginCommandBuffer(); |
| 7640 | |
Michael Lentine | 0a369f6 | 2016-02-03 16:51:46 -0600 | [diff] [blame] | 7641 | VkClearColorValue clear_color; |
| 7642 | memset(clear_color.uint32, 0, sizeof(uint32_t) * 4); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7643 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 7644 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 7645 | const int32_t tex_width = 32; |
| 7646 | const int32_t tex_height = 32; |
| 7647 | VkImageCreateInfo image_create_info = {}; |
| 7648 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 7649 | image_create_info.pNext = NULL; |
| 7650 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 7651 | image_create_info.format = tex_format; |
| 7652 | image_create_info.extent.width = tex_width; |
| 7653 | image_create_info.extent.height = tex_height; |
| 7654 | image_create_info.extent.depth = 1; |
| 7655 | image_create_info.mipLevels = 1; |
| 7656 | image_create_info.arrayLayers = 1; |
| 7657 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 7658 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 7659 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7660 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7661 | vk_testing::Image dstImage; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7662 | dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 7663 | reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7664 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7665 | const VkImageSubresourceRange range = vk_testing::Image::subresource_range( |
| 7666 | image_create_info, VK_IMAGE_ASPECT_COLOR_BIT); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7667 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7668 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), |
| 7669 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7670 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7671 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7672 | } |
| 7673 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7674 | TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7675 | // Call CmdClearDepthStencilImage within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7676 | m_errorMonitor->SetDesiredFailureMsg( |
| 7677 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7678 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7679 | |
| 7680 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7681 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7682 | |
| 7683 | // Renderpass is started here |
| 7684 | BeginCommandBuffer(); |
| 7685 | |
| 7686 | VkClearDepthStencilValue clear_value = {0}; |
Dustin Graves | a2e5c94 | 2016-02-11 18:28:06 -0700 | [diff] [blame] | 7687 | VkMemoryPropertyFlags reqs = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7688 | VkImageCreateInfo image_create_info = vk_testing::Image::create_info(); |
| 7689 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 7690 | image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 7691 | image_create_info.extent.width = 64; |
| 7692 | image_create_info.extent.height = 64; |
| 7693 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 7694 | image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7695 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7696 | vk_testing::Image dstImage; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7697 | dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 7698 | reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7699 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7700 | const VkImageSubresourceRange range = vk_testing::Image::subresource_range( |
| 7701 | image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7702 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7703 | vkCmdClearDepthStencilImage( |
| 7704 | m_commandBuffer->GetBufferHandle(), dstImage.handle(), |
| 7705 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, |
| 7706 | &range); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7707 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7708 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7709 | } |
| 7710 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7711 | TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) { |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 7712 | // Call CmdClearAttachmentss outside of an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7713 | VkResult err; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7714 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 7715 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7716 | "vkCmdClearAttachments: This call " |
| 7717 | "must be issued inside an active " |
| 7718 | "render pass"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7719 | |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7720 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7721 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7722 | |
| 7723 | // Start no RenderPass |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7724 | err = m_commandBuffer->BeginCommandBuffer(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7725 | ASSERT_VK_SUCCESS(err); |
| 7726 | |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 7727 | VkClearAttachment color_attachment; |
| 7728 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 7729 | color_attachment.clearValue.color.float32[0] = 0; |
| 7730 | color_attachment.clearValue.color.float32[1] = 0; |
| 7731 | color_attachment.clearValue.color.float32[2] = 0; |
| 7732 | color_attachment.clearValue.color.float32[3] = 0; |
| 7733 | color_attachment.colorAttachment = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7734 | VkClearRect clear_rect = {{{0, 0}, {32, 32}}}; |
| 7735 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 7736 | &color_attachment, 1, &clear_rect); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7737 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7738 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7739 | } |
| 7740 | |
Karl Schultz | 9e66a29 | 2016-04-21 15:57:51 -0600 | [diff] [blame] | 7741 | TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) { |
| 7742 | // Try to add a buffer memory barrier with no buffer. |
| 7743 | m_errorMonitor->SetDesiredFailureMsg( |
| 7744 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7745 | "required parameter pBufferMemoryBarriers[i].buffer specified as VK_NULL_HANDLE"); |
| 7746 | |
| 7747 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7748 | BeginCommandBuffer(); |
| 7749 | |
| 7750 | VkBufferMemoryBarrier buf_barrier = {}; |
| 7751 | buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; |
| 7752 | buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 7753 | buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 7754 | buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7755 | buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7756 | buf_barrier.buffer = VK_NULL_HANDLE; |
| 7757 | buf_barrier.offset = 0; |
| 7758 | buf_barrier.size = VK_WHOLE_SIZE; |
| 7759 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7760 | VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, |
| 7761 | 0, 0, nullptr, 1, &buf_barrier, 0, nullptr); |
| 7762 | |
| 7763 | m_errorMonitor->VerifyFound(); |
| 7764 | } |
| 7765 | |
Tony Barbour | 7fd5c0f | 2016-05-03 16:11:53 -0600 | [diff] [blame] | 7766 | TEST_F(VkLayerTest, InvalidBarriers) { |
| 7767 | TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER "); |
| 7768 | |
| 7769 | m_errorMonitor->SetDesiredFailureMsg( |
| 7770 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass"); |
| 7771 | |
| 7772 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7773 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7774 | |
| 7775 | VkMemoryBarrier mem_barrier = {}; |
| 7776 | mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER; |
| 7777 | mem_barrier.pNext = NULL; |
| 7778 | mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 7779 | mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 7780 | BeginCommandBuffer(); |
| 7781 | // BeginCommandBuffer() starts a render pass |
| 7782 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7783 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7784 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1, |
| 7785 | &mem_barrier, 0, nullptr, 0, nullptr); |
| 7786 | m_errorMonitor->VerifyFound(); |
| 7787 | |
| 7788 | m_errorMonitor->SetDesiredFailureMsg( |
| 7789 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7790 | "Image Layout cannot be transitioned to UNDEFINED"); |
| 7791 | VkImageObj image(m_device); |
| 7792 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 7793 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 7794 | ASSERT_TRUE(image.initialized()); |
| 7795 | VkImageMemoryBarrier img_barrier = {}; |
| 7796 | img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 7797 | img_barrier.pNext = NULL; |
| 7798 | img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 7799 | img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 7800 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 7801 | // New layout can't be UNDEFINED |
| 7802 | img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 7803 | img_barrier.image = image.handle(); |
| 7804 | img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7805 | img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7806 | img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 7807 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 7808 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 7809 | img_barrier.subresourceRange.layerCount = 1; |
| 7810 | img_barrier.subresourceRange.levelCount = 1; |
| 7811 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7812 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7813 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 7814 | nullptr, 1, &img_barrier); |
| 7815 | m_errorMonitor->VerifyFound(); |
| 7816 | img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 7817 | |
| 7818 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7819 | "Subresource must have the sum of the " |
| 7820 | "baseArrayLayer"); |
| 7821 | // baseArrayLayer + layerCount must be <= image's arrayLayers |
| 7822 | img_barrier.subresourceRange.baseArrayLayer = 1; |
| 7823 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7824 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7825 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 7826 | nullptr, 1, &img_barrier); |
| 7827 | m_errorMonitor->VerifyFound(); |
| 7828 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 7829 | |
| 7830 | m_errorMonitor->SetDesiredFailureMsg( |
| 7831 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7832 | "Subresource must have the sum of the baseMipLevel"); |
| 7833 | // baseMipLevel + levelCount must be <= image's mipLevels |
| 7834 | img_barrier.subresourceRange.baseMipLevel = 1; |
| 7835 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7836 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7837 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 7838 | nullptr, 1, &img_barrier); |
| 7839 | m_errorMonitor->VerifyFound(); |
| 7840 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 7841 | |
| 7842 | m_errorMonitor->SetDesiredFailureMsg( |
| 7843 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7844 | "Buffer Barriers cannot be used during a render pass"); |
| 7845 | vk_testing::Buffer buffer; |
| 7846 | buffer.init(*m_device, 256); |
| 7847 | VkBufferMemoryBarrier buf_barrier = {}; |
| 7848 | buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; |
| 7849 | buf_barrier.pNext = NULL; |
| 7850 | buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 7851 | buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 7852 | buf_barrier.buffer = buffer.handle(); |
| 7853 | buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7854 | buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7855 | buf_barrier.offset = 0; |
| 7856 | buf_barrier.size = VK_WHOLE_SIZE; |
| 7857 | // Can't send buffer barrier during a render pass |
| 7858 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7859 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7860 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 7861 | &buf_barrier, 0, nullptr); |
| 7862 | m_errorMonitor->VerifyFound(); |
| 7863 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 7864 | |
| 7865 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7866 | "which is not less than total size"); |
| 7867 | buf_barrier.offset = 257; |
| 7868 | // Offset greater than total size |
| 7869 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7870 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7871 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 7872 | &buf_barrier, 0, nullptr); |
| 7873 | m_errorMonitor->VerifyFound(); |
| 7874 | buf_barrier.offset = 0; |
| 7875 | |
| 7876 | m_errorMonitor->SetDesiredFailureMsg( |
| 7877 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size"); |
| 7878 | buf_barrier.size = 257; |
| 7879 | // Size greater than total size |
| 7880 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7881 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7882 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 7883 | &buf_barrier, 0, nullptr); |
| 7884 | m_errorMonitor->VerifyFound(); |
| 7885 | buf_barrier.size = VK_WHOLE_SIZE; |
| 7886 | |
| 7887 | m_errorMonitor->SetDesiredFailureMsg( |
| 7888 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7889 | "Image is a depth and stencil format and thus must " |
| 7890 | "have both VK_IMAGE_ASPECT_DEPTH_BIT and " |
| 7891 | "VK_IMAGE_ASPECT_STENCIL_BIT set."); |
| 7892 | VkDepthStencilObj ds_image(m_device); |
| 7893 | ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT); |
| 7894 | ASSERT_TRUE(ds_image.initialized()); |
| 7895 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 7896 | img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 7897 | img_barrier.image = ds_image.handle(); |
| 7898 | // Leave aspectMask at COLOR on purpose |
| 7899 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7900 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7901 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 7902 | nullptr, 1, &img_barrier); |
| 7903 | m_errorMonitor->VerifyFound(); |
| 7904 | } |
| 7905 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7906 | TEST_F(VkLayerTest, IdxBufferAlignmentError) { |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7907 | // Bind a BeginRenderPass within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7908 | VkResult err; |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7909 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7910 | m_errorMonitor->SetDesiredFailureMsg( |
| 7911 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7912 | "vkCmdBindIndexBuffer() offset (0x7) does not fall on "); |
| 7913 | |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7914 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7915 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7916 | uint32_t qfi = 0; |
| 7917 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7918 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 7919 | buffCI.size = 1024; |
| 7920 | buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; |
| 7921 | buffCI.queueFamilyIndexCount = 1; |
| 7922 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7923 | |
| 7924 | VkBuffer ib; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7925 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7926 | ASSERT_VK_SUCCESS(err); |
| 7927 | |
| 7928 | BeginCommandBuffer(); |
| 7929 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7930 | // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7931 | // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7932 | // 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] | 7933 | vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, |
| 7934 | VK_INDEX_TYPE_UINT16); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7935 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7936 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 7937 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7938 | vkDestroyBuffer(m_device->device(), ib, NULL); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7939 | } |
| 7940 | |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 7941 | TEST_F(VkLayerTest, InvalidQueueFamilyIndex) { |
| 7942 | // Create an out-of-range queueFamilyIndex |
| 7943 | m_errorMonitor->SetDesiredFailureMsg( |
| 7944 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Dustin Graves | de62853 | 2016-04-21 16:30:17 -0600 | [diff] [blame] | 7945 | "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one " |
| 7946 | "of the indices specified when the device was created, via the " |
| 7947 | "VkDeviceQueueCreateInfo structure."); |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 7948 | |
| 7949 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7950 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7951 | VkBufferCreateInfo buffCI = {}; |
| 7952 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 7953 | buffCI.size = 1024; |
| 7954 | buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; |
| 7955 | buffCI.queueFamilyIndexCount = 1; |
| 7956 | // Introduce failure by specifying invalid queue_family_index |
| 7957 | uint32_t qfi = 777; |
| 7958 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 24aab04 | 2016-03-24 10:54:18 -0600 | [diff] [blame] | 7959 | buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 7960 | |
| 7961 | VkBuffer ib; |
| 7962 | vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib); |
| 7963 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7964 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7965 | vkDestroyBuffer(m_device->device(), ib, NULL); |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 7966 | } |
| 7967 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7968 | TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) { |
| 7969 | // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be |
| 7970 | // secondary) |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7971 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7972 | m_errorMonitor->SetDesiredFailureMsg( |
| 7973 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7974 | "vkCmdExecuteCommands() called w/ Primary Cmd Buffer "); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 7975 | |
| 7976 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7977 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 7978 | |
| 7979 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7980 | // ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7981 | VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle(); |
| 7982 | vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 7983 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7984 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 7985 | } |
| 7986 | |
Tobin Ehlis | 17826bd | 2016-05-25 11:12:50 -0600 | [diff] [blame] | 7987 | TEST_F(VkLayerTest, DSUsageBitsErrors) { |
| 7988 | TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers " |
| 7989 | "that do not have correct usage bits sets."); |
| 7990 | VkResult err; |
| 7991 | |
| 7992 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7993 | VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {}; |
| 7994 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 7995 | ds_type_count[i].type = VkDescriptorType(i); |
| 7996 | ds_type_count[i].descriptorCount = 1; |
| 7997 | } |
| 7998 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 7999 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8000 | ds_pool_ci.pNext = NULL; |
| 8001 | ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 8002 | ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 8003 | ds_pool_ci.pPoolSizes = ds_type_count; |
| 8004 | |
| 8005 | VkDescriptorPool ds_pool; |
| 8006 | err = |
| 8007 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 8008 | ASSERT_VK_SUCCESS(err); |
| 8009 | |
| 8010 | // Create 10 layouts where each has a single descriptor of different type |
| 8011 | VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = |
| 8012 | {}; |
| 8013 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 8014 | dsl_binding[i].binding = 0; |
| 8015 | dsl_binding[i].descriptorType = VkDescriptorType(i); |
| 8016 | dsl_binding[i].descriptorCount = 1; |
| 8017 | dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL; |
| 8018 | dsl_binding[i].pImmutableSamplers = NULL; |
| 8019 | } |
| 8020 | |
| 8021 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 8022 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8023 | ds_layout_ci.pNext = NULL; |
| 8024 | ds_layout_ci.bindingCount = 1; |
| 8025 | VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE]; |
| 8026 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 8027 | ds_layout_ci.pBindings = dsl_binding + i; |
| 8028 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, |
| 8029 | NULL, ds_layouts + i); |
| 8030 | ASSERT_VK_SUCCESS(err); |
| 8031 | } |
| 8032 | VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {}; |
| 8033 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 8034 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 8035 | alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 8036 | alloc_info.descriptorPool = ds_pool; |
| 8037 | alloc_info.pSetLayouts = ds_layouts; |
| 8038 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8039 | descriptor_sets); |
| 8040 | ASSERT_VK_SUCCESS(err); |
| 8041 | |
| 8042 | // Create a buffer & bufferView to be used for invalid updates |
| 8043 | VkBufferCreateInfo buff_ci = {}; |
| 8044 | buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 8045 | // This usage is not valid for any descriptor type |
| 8046 | buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; |
| 8047 | buff_ci.size = 256; |
| 8048 | buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 8049 | VkBuffer buffer; |
| 8050 | err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer); |
| 8051 | ASSERT_VK_SUCCESS(err); |
| 8052 | |
| 8053 | VkBufferViewCreateInfo buff_view_ci = {}; |
| 8054 | buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; |
| 8055 | buff_view_ci.buffer = buffer; |
| 8056 | buff_view_ci.format = VK_FORMAT_R8_UNORM; |
| 8057 | buff_view_ci.range = VK_WHOLE_SIZE; |
| 8058 | VkBufferView buff_view; |
| 8059 | err = |
| 8060 | vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view); |
| 8061 | ASSERT_VK_SUCCESS(err); |
| 8062 | |
| 8063 | // Create an image to be used for invalid updates |
| 8064 | VkImageCreateInfo image_ci = {}; |
| 8065 | image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 8066 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 8067 | image_ci.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 8068 | image_ci.extent.width = 64; |
| 8069 | image_ci.extent.height = 64; |
| 8070 | image_ci.extent.depth = 1; |
| 8071 | image_ci.mipLevels = 1; |
| 8072 | image_ci.arrayLayers = 1; |
| 8073 | image_ci.samples = VK_SAMPLE_COUNT_1_BIT; |
| 8074 | image_ci.tiling = VK_IMAGE_TILING_LINEAR; |
| 8075 | image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 8076 | // This usage is not valid for any descriptor type |
| 8077 | image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 8078 | image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 8079 | VkImage image; |
| 8080 | err = vkCreateImage(m_device->device(), &image_ci, NULL, &image); |
| 8081 | ASSERT_VK_SUCCESS(err); |
| 8082 | // Bind memory to image |
| 8083 | VkMemoryRequirements mem_reqs; |
| 8084 | VkDeviceMemory image_mem; |
| 8085 | bool pass; |
| 8086 | VkMemoryAllocateInfo mem_alloc = {}; |
| 8087 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 8088 | mem_alloc.pNext = NULL; |
| 8089 | mem_alloc.allocationSize = 0; |
| 8090 | mem_alloc.memoryTypeIndex = 0; |
| 8091 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 8092 | mem_alloc.allocationSize = mem_reqs.size; |
| 8093 | pass = |
| 8094 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 8095 | ASSERT_TRUE(pass); |
| 8096 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem); |
| 8097 | ASSERT_VK_SUCCESS(err); |
| 8098 | err = vkBindImageMemory(m_device->device(), image, image_mem, 0); |
| 8099 | ASSERT_VK_SUCCESS(err); |
| 8100 | // Now create view for image |
| 8101 | VkImageViewCreateInfo image_view_ci = {}; |
| 8102 | image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 8103 | image_view_ci.image = image; |
| 8104 | image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 8105 | image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 8106 | image_view_ci.subresourceRange.layerCount = 1; |
| 8107 | image_view_ci.subresourceRange.baseArrayLayer = 0; |
| 8108 | image_view_ci.subresourceRange.levelCount = 1; |
| 8109 | image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 8110 | VkImageView image_view; |
| 8111 | err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, |
| 8112 | &image_view); |
| 8113 | ASSERT_VK_SUCCESS(err); |
| 8114 | |
| 8115 | VkDescriptorBufferInfo buff_info = {}; |
| 8116 | buff_info.buffer = buffer; |
| 8117 | VkDescriptorImageInfo img_info = {}; |
| 8118 | img_info.imageView = image_view; |
| 8119 | VkWriteDescriptorSet descriptor_write = {}; |
| 8120 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 8121 | descriptor_write.dstBinding = 0; |
| 8122 | descriptor_write.descriptorCount = 1; |
| 8123 | descriptor_write.pTexelBufferView = &buff_view; |
| 8124 | descriptor_write.pBufferInfo = &buff_info; |
| 8125 | descriptor_write.pImageInfo = &img_info; |
| 8126 | |
| 8127 | // These error messages align with VkDescriptorType struct |
| 8128 | const char *error_msgs[] = { |
| 8129 | "", // placeholder, no error for SAMPLER descriptor |
| 8130 | " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.", |
| 8131 | " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.", |
| 8132 | " does not have VK_IMAGE_USAGE_STORAGE_BIT set.", |
| 8133 | " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.", |
| 8134 | " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.", |
| 8135 | " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.", |
| 8136 | " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.", |
| 8137 | " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.", |
| 8138 | " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.", |
| 8139 | " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."}; |
| 8140 | // Start loop at 1 as SAMPLER desc type has no usage bit error |
| 8141 | for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 8142 | descriptor_write.descriptorType = VkDescriptorType(i); |
| 8143 | descriptor_write.dstSet = descriptor_sets[i]; |
| 8144 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8145 | error_msgs[i]); |
| 8146 | |
| 8147 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, |
| 8148 | NULL); |
| 8149 | |
| 8150 | m_errorMonitor->VerifyFound(); |
| 8151 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL); |
| 8152 | } |
| 8153 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL); |
| 8154 | vkDestroyImage(m_device->device(), image, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 8155 | vkFreeMemory(m_device->device(), image_mem, NULL); |
Tobin Ehlis | 17826bd | 2016-05-25 11:12:50 -0600 | [diff] [blame] | 8156 | vkDestroyImageView(m_device->device(), image_view, NULL); |
| 8157 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 8158 | vkDestroyBufferView(m_device->device(), buff_view, NULL); |
| 8159 | vkFreeDescriptorSets(m_device->device(), ds_pool, |
| 8160 | VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets); |
| 8161 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 8162 | } |
| 8163 | |
Tobin Ehlis | 2fc296b | 2016-06-15 14:05:27 -0600 | [diff] [blame] | 8164 | TEST_F(VkLayerTest, DSAspectBitsErrors) { |
| 8165 | // TODO : Initially only catching case where DEPTH & STENCIL aspect bits |
| 8166 | // are set, but could expand this test to hit more cases. |
| 8167 | TEST_DESCRIPTION("Attempt to update descriptor sets for images " |
| 8168 | "that do not have correct aspect bits sets."); |
| 8169 | VkResult err; |
| 8170 | |
| 8171 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8172 | VkDescriptorPoolSize ds_type_count = {}; |
| 8173 | ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 8174 | ds_type_count.descriptorCount = 1; |
| 8175 | |
| 8176 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 8177 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8178 | ds_pool_ci.pNext = NULL; |
| 8179 | ds_pool_ci.maxSets = 5; |
| 8180 | ds_pool_ci.poolSizeCount = 1; |
| 8181 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 8182 | |
| 8183 | VkDescriptorPool ds_pool; |
| 8184 | err = |
| 8185 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 8186 | ASSERT_VK_SUCCESS(err); |
| 8187 | |
| 8188 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 8189 | dsl_binding.binding = 0; |
| 8190 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 8191 | dsl_binding.descriptorCount = 1; |
| 8192 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8193 | dsl_binding.pImmutableSamplers = NULL; |
| 8194 | |
| 8195 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 8196 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8197 | ds_layout_ci.pNext = NULL; |
| 8198 | ds_layout_ci.bindingCount = 1; |
| 8199 | ds_layout_ci.pBindings = &dsl_binding; |
| 8200 | VkDescriptorSetLayout ds_layout; |
| 8201 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8202 | &ds_layout); |
| 8203 | ASSERT_VK_SUCCESS(err); |
| 8204 | |
| 8205 | VkDescriptorSet descriptor_set = {}; |
| 8206 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 8207 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 8208 | alloc_info.descriptorSetCount = 1; |
| 8209 | alloc_info.descriptorPool = ds_pool; |
| 8210 | alloc_info.pSetLayouts = &ds_layout; |
| 8211 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8212 | &descriptor_set); |
| 8213 | ASSERT_VK_SUCCESS(err); |
| 8214 | |
| 8215 | // Create an image to be used for invalid updates |
| 8216 | VkImageCreateInfo image_ci = {}; |
| 8217 | image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 8218 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 8219 | image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 8220 | image_ci.extent.width = 64; |
| 8221 | image_ci.extent.height = 64; |
| 8222 | image_ci.extent.depth = 1; |
| 8223 | image_ci.mipLevels = 1; |
| 8224 | image_ci.arrayLayers = 1; |
| 8225 | image_ci.samples = VK_SAMPLE_COUNT_1_BIT; |
| 8226 | image_ci.tiling = VK_IMAGE_TILING_LINEAR; |
| 8227 | image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 8228 | image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 8229 | image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 8230 | VkImage image; |
| 8231 | err = vkCreateImage(m_device->device(), &image_ci, NULL, &image); |
| 8232 | ASSERT_VK_SUCCESS(err); |
| 8233 | // Bind memory to image |
| 8234 | VkMemoryRequirements mem_reqs; |
| 8235 | VkDeviceMemory image_mem; |
| 8236 | bool pass; |
| 8237 | VkMemoryAllocateInfo mem_alloc = {}; |
| 8238 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 8239 | mem_alloc.pNext = NULL; |
| 8240 | mem_alloc.allocationSize = 0; |
| 8241 | mem_alloc.memoryTypeIndex = 0; |
| 8242 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 8243 | mem_alloc.allocationSize = mem_reqs.size; |
| 8244 | pass = |
| 8245 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 8246 | ASSERT_TRUE(pass); |
| 8247 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem); |
| 8248 | ASSERT_VK_SUCCESS(err); |
| 8249 | err = vkBindImageMemory(m_device->device(), image, image_mem, 0); |
| 8250 | ASSERT_VK_SUCCESS(err); |
| 8251 | // Now create view for image |
| 8252 | VkImageViewCreateInfo image_view_ci = {}; |
| 8253 | image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 8254 | image_view_ci.image = image; |
| 8255 | image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 8256 | image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 8257 | image_view_ci.subresourceRange.layerCount = 1; |
| 8258 | image_view_ci.subresourceRange.baseArrayLayer = 0; |
| 8259 | image_view_ci.subresourceRange.levelCount = 1; |
| 8260 | // Setting both depth & stencil aspect bits is illegal for descriptor |
| 8261 | image_view_ci.subresourceRange.aspectMask = |
| 8262 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 8263 | |
| 8264 | VkImageView image_view; |
| 8265 | err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, |
| 8266 | &image_view); |
| 8267 | ASSERT_VK_SUCCESS(err); |
| 8268 | |
| 8269 | VkDescriptorImageInfo img_info = {}; |
| 8270 | img_info.imageView = image_view; |
| 8271 | VkWriteDescriptorSet descriptor_write = {}; |
| 8272 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 8273 | descriptor_write.dstBinding = 0; |
| 8274 | descriptor_write.descriptorCount = 1; |
| 8275 | descriptor_write.pTexelBufferView = NULL; |
| 8276 | descriptor_write.pBufferInfo = NULL; |
| 8277 | descriptor_write.pImageInfo = &img_info; |
| 8278 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 8279 | descriptor_write.dstSet = descriptor_set; |
| 8280 | const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT " |
| 8281 | "or VK_IMAGE_ASPECT_STENCIL_BIT "; |
| 8282 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8283 | error_msg); |
| 8284 | |
| 8285 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8286 | |
| 8287 | m_errorMonitor->VerifyFound(); |
| 8288 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8289 | vkDestroyImage(m_device->device(), image, NULL); |
| 8290 | vkFreeMemory(m_device->device(), image_mem, NULL); |
| 8291 | vkDestroyImageView(m_device->device(), image_view, NULL); |
| 8292 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set); |
| 8293 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 8294 | } |
| 8295 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8296 | TEST_F(VkLayerTest, DSTypeMismatch) { |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8297 | // 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] | 8298 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8299 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8300 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8301 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8302 | " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update " |
| 8303 | "type is VK_DESCRIPTOR_TYPE_SAMPLER"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8304 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8305 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8306 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8307 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8308 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8309 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8310 | |
| 8311 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8312 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8313 | ds_pool_ci.pNext = NULL; |
| 8314 | ds_pool_ci.maxSets = 1; |
| 8315 | ds_pool_ci.poolSizeCount = 1; |
| 8316 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8317 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8318 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8319 | err = |
| 8320 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8321 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8322 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8323 | dsl_binding.binding = 0; |
| 8324 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8325 | dsl_binding.descriptorCount = 1; |
| 8326 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8327 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8328 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8329 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8330 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8331 | ds_layout_ci.pNext = NULL; |
| 8332 | ds_layout_ci.bindingCount = 1; |
| 8333 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8334 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8335 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8336 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8337 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8338 | ASSERT_VK_SUCCESS(err); |
| 8339 | |
| 8340 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8341 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8342 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8343 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8344 | alloc_info.descriptorPool = ds_pool; |
| 8345 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8346 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8347 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8348 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8349 | |
Tobin Ehlis | 30db8f8 | 2016-05-05 08:19:48 -0600 | [diff] [blame] | 8350 | VkSamplerCreateInfo sampler_ci = {}; |
| 8351 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8352 | sampler_ci.pNext = NULL; |
| 8353 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8354 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8355 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8356 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8357 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8358 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8359 | sampler_ci.mipLodBias = 1.0; |
| 8360 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8361 | sampler_ci.maxAnisotropy = 1; |
| 8362 | sampler_ci.compareEnable = VK_FALSE; |
| 8363 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8364 | sampler_ci.minLod = 1.0; |
| 8365 | sampler_ci.maxLod = 1.0; |
| 8366 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8367 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
| 8368 | VkSampler sampler; |
| 8369 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
| 8370 | ASSERT_VK_SUCCESS(err); |
| 8371 | |
| 8372 | VkDescriptorImageInfo info = {}; |
| 8373 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8374 | |
| 8375 | VkWriteDescriptorSet descriptor_write; |
| 8376 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8377 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8378 | descriptor_write.dstSet = descriptorSet; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8379 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8380 | // This is a mismatched type for the layout which expects BUFFER |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8381 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8382 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8383 | |
| 8384 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8385 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8386 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8387 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8388 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8389 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8390 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8391 | } |
| 8392 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8393 | TEST_F(VkLayerTest, DSUpdateOutOfBounds) { |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8394 | // For overlapping Update, have arrayIndex exceed that of layout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8395 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8396 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8397 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8398 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8399 | " binding #0 with 1 total descriptors but update of 1 descriptors " |
| 8400 | "starting at binding offset of 0 combined with update array element " |
| 8401 | "offset of 1 oversteps the size of this descriptor set."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8402 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8403 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8404 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8405 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8406 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8407 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8408 | |
| 8409 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8410 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8411 | ds_pool_ci.pNext = NULL; |
| 8412 | ds_pool_ci.maxSets = 1; |
| 8413 | ds_pool_ci.poolSizeCount = 1; |
| 8414 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8415 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8416 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8417 | err = |
| 8418 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8419 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8420 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8421 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8422 | dsl_binding.binding = 0; |
| 8423 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8424 | dsl_binding.descriptorCount = 1; |
| 8425 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8426 | dsl_binding.pImmutableSamplers = NULL; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8427 | |
| 8428 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8429 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8430 | ds_layout_ci.pNext = NULL; |
| 8431 | ds_layout_ci.bindingCount = 1; |
| 8432 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8433 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8434 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8435 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8436 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8437 | ASSERT_VK_SUCCESS(err); |
| 8438 | |
| 8439 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8440 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8441 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8442 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8443 | alloc_info.descriptorPool = ds_pool; |
| 8444 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8445 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8446 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8447 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8448 | |
Tobin Ehlis | 30db8f8 | 2016-05-05 08:19:48 -0600 | [diff] [blame] | 8449 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 8450 | VkDescriptorBufferInfo buff_info = {}; |
| 8451 | buff_info.buffer = |
| 8452 | VkBuffer(0); // Don't care about buffer handle for this test |
| 8453 | buff_info.offset = 0; |
| 8454 | buff_info.range = 1024; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8455 | |
| 8456 | VkWriteDescriptorSet descriptor_write; |
| 8457 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8458 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8459 | descriptor_write.dstSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8460 | descriptor_write.dstArrayElement = |
| 8461 | 1; /* This index out of bounds for the update */ |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8462 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8463 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8464 | descriptor_write.pBufferInfo = &buff_info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8465 | |
| 8466 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8467 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8468 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8469 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8470 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8471 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8472 | } |
| 8473 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8474 | TEST_F(VkLayerTest, InvalidDSUpdateIndex) { |
| 8475 | // Create layout w/ count of 1 and attempt update to that layout w/ binding |
| 8476 | // index 2 |
| 8477 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8478 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8479 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8480 | " does not have binding 2."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8481 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8482 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8483 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8484 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8485 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8486 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8487 | |
| 8488 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8489 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8490 | ds_pool_ci.pNext = NULL; |
| 8491 | ds_pool_ci.maxSets = 1; |
| 8492 | ds_pool_ci.poolSizeCount = 1; |
| 8493 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 8494 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8495 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8496 | err = |
| 8497 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8498 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8499 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8500 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8501 | dsl_binding.binding = 0; |
| 8502 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8503 | dsl_binding.descriptorCount = 1; |
| 8504 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8505 | dsl_binding.pImmutableSamplers = NULL; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8506 | |
| 8507 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8508 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8509 | ds_layout_ci.pNext = NULL; |
| 8510 | ds_layout_ci.bindingCount = 1; |
| 8511 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8512 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8513 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8514 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8515 | ASSERT_VK_SUCCESS(err); |
| 8516 | |
| 8517 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8518 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8519 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8520 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8521 | alloc_info.descriptorPool = ds_pool; |
| 8522 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8523 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8524 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8525 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8526 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8527 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8528 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8529 | sampler_ci.pNext = NULL; |
| 8530 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8531 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8532 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8533 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8534 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8535 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8536 | sampler_ci.mipLodBias = 1.0; |
| 8537 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8538 | sampler_ci.maxAnisotropy = 1; |
| 8539 | sampler_ci.compareEnable = VK_FALSE; |
| 8540 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8541 | sampler_ci.minLod = 1.0; |
| 8542 | sampler_ci.maxLod = 1.0; |
| 8543 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8544 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8545 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8546 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8547 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8548 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8549 | |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8550 | VkDescriptorImageInfo info = {}; |
| 8551 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8552 | |
| 8553 | VkWriteDescriptorSet descriptor_write; |
| 8554 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8555 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8556 | descriptor_write.dstSet = descriptorSet; |
| 8557 | descriptor_write.dstBinding = 2; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8558 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8559 | // 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] | 8560 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8561 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8562 | |
| 8563 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8564 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8565 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8566 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8567 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8568 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8569 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8570 | } |
| 8571 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8572 | TEST_F(VkLayerTest, InvalidDSUpdateStruct) { |
| 8573 | // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* |
| 8574 | // types |
| 8575 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8576 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 8577 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 660bcdc | 2016-05-17 10:39:46 -0600 | [diff] [blame] | 8578 | ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8579 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8580 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 8581 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8582 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8583 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8584 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8585 | |
| 8586 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8587 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8588 | ds_pool_ci.pNext = NULL; |
| 8589 | ds_pool_ci.maxSets = 1; |
| 8590 | ds_pool_ci.poolSizeCount = 1; |
| 8591 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 8592 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8593 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8594 | err = |
| 8595 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8596 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8597 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8598 | dsl_binding.binding = 0; |
| 8599 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8600 | dsl_binding.descriptorCount = 1; |
| 8601 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8602 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8603 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8604 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8605 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8606 | ds_layout_ci.pNext = NULL; |
| 8607 | ds_layout_ci.bindingCount = 1; |
| 8608 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8609 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8610 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8611 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8612 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8613 | ASSERT_VK_SUCCESS(err); |
| 8614 | |
| 8615 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8616 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8617 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8618 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8619 | alloc_info.descriptorPool = ds_pool; |
| 8620 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8621 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8622 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8623 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8624 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8625 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8626 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8627 | sampler_ci.pNext = NULL; |
| 8628 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8629 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8630 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8631 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8632 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8633 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8634 | sampler_ci.mipLodBias = 1.0; |
| 8635 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8636 | sampler_ci.maxAnisotropy = 1; |
| 8637 | sampler_ci.compareEnable = VK_FALSE; |
| 8638 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8639 | sampler_ci.minLod = 1.0; |
| 8640 | sampler_ci.maxLod = 1.0; |
| 8641 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8642 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8643 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8644 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8645 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8646 | |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8647 | VkDescriptorImageInfo info = {}; |
| 8648 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8649 | |
| 8650 | VkWriteDescriptorSet descriptor_write; |
| 8651 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8652 | descriptor_write.sType = |
| 8653 | (VkStructureType)0x99999999; /* Intentionally broken struct type */ |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8654 | descriptor_write.dstSet = descriptorSet; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8655 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8656 | // 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] | 8657 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8658 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8659 | |
| 8660 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8661 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8662 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8663 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8664 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8665 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8666 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8667 | } |
| 8668 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8669 | TEST_F(VkLayerTest, SampleDescriptorUpdateError) { |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8670 | // Create a single Sampler descriptor and send it an invalid Sampler |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8671 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8672 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8673 | m_errorMonitor->SetDesiredFailureMsg( |
| 8674 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8675 | "Attempted write update to sampler descriptor with invalid sampler"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8676 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8677 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8678 | // TODO : Farm Descriptor setup code to helper function(s) to reduce copied |
| 8679 | // code |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8680 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8681 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8682 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8683 | |
| 8684 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8685 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8686 | ds_pool_ci.pNext = NULL; |
| 8687 | ds_pool_ci.maxSets = 1; |
| 8688 | ds_pool_ci.poolSizeCount = 1; |
| 8689 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8690 | |
| 8691 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8692 | err = |
| 8693 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8694 | ASSERT_VK_SUCCESS(err); |
| 8695 | |
| 8696 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8697 | dsl_binding.binding = 0; |
| 8698 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8699 | dsl_binding.descriptorCount = 1; |
| 8700 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8701 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8702 | |
| 8703 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8704 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8705 | ds_layout_ci.pNext = NULL; |
| 8706 | ds_layout_ci.bindingCount = 1; |
| 8707 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8708 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8709 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8710 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8711 | ASSERT_VK_SUCCESS(err); |
| 8712 | |
| 8713 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8714 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8715 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8716 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8717 | alloc_info.descriptorPool = ds_pool; |
| 8718 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8719 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8720 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8721 | ASSERT_VK_SUCCESS(err); |
| 8722 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8723 | VkSampler sampler = |
| 8724 | (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8725 | |
| 8726 | VkDescriptorImageInfo descriptor_info; |
| 8727 | memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo)); |
| 8728 | descriptor_info.sampler = sampler; |
| 8729 | |
| 8730 | VkWriteDescriptorSet descriptor_write; |
| 8731 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8732 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8733 | descriptor_write.dstSet = descriptorSet; |
| 8734 | descriptor_write.dstBinding = 0; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8735 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8736 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8737 | descriptor_write.pImageInfo = &descriptor_info; |
| 8738 | |
| 8739 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8740 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8741 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8742 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8743 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8744 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8745 | } |
| 8746 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8747 | TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) { |
| 8748 | // Create a single combined Image/Sampler descriptor and send it an invalid |
| 8749 | // imageView |
| 8750 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8751 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8752 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8753 | "Attempted write update to combined " |
| 8754 | "image sampler descriptor failed due " |
Tobin Ehlis | 63c4b8a | 2016-05-09 10:29:34 -0600 | [diff] [blame] | 8755 | "to: Invalid VkImageView:"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8756 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8757 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8758 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8759 | ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 8760 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8761 | |
| 8762 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8763 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8764 | ds_pool_ci.pNext = NULL; |
| 8765 | ds_pool_ci.maxSets = 1; |
| 8766 | ds_pool_ci.poolSizeCount = 1; |
| 8767 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8768 | |
| 8769 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8770 | err = |
| 8771 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8772 | ASSERT_VK_SUCCESS(err); |
| 8773 | |
| 8774 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8775 | dsl_binding.binding = 0; |
| 8776 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 8777 | dsl_binding.descriptorCount = 1; |
| 8778 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8779 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8780 | |
| 8781 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8782 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8783 | ds_layout_ci.pNext = NULL; |
| 8784 | ds_layout_ci.bindingCount = 1; |
| 8785 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8786 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8787 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8788 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8789 | ASSERT_VK_SUCCESS(err); |
| 8790 | |
| 8791 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8792 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8793 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8794 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8795 | alloc_info.descriptorPool = ds_pool; |
| 8796 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8797 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8798 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8799 | ASSERT_VK_SUCCESS(err); |
| 8800 | |
| 8801 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8802 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8803 | sampler_ci.pNext = NULL; |
| 8804 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8805 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8806 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8807 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8808 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8809 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8810 | sampler_ci.mipLodBias = 1.0; |
| 8811 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8812 | sampler_ci.maxAnisotropy = 1; |
| 8813 | sampler_ci.compareEnable = VK_FALSE; |
| 8814 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8815 | sampler_ci.minLod = 1.0; |
| 8816 | sampler_ci.maxLod = 1.0; |
| 8817 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8818 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8819 | |
| 8820 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8821 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8822 | ASSERT_VK_SUCCESS(err); |
| 8823 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8824 | VkImageView view = |
| 8825 | (VkImageView)((size_t)0xbaadbeef); // invalid imageView object |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8826 | |
| 8827 | VkDescriptorImageInfo descriptor_info; |
| 8828 | memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo)); |
| 8829 | descriptor_info.sampler = sampler; |
| 8830 | descriptor_info.imageView = view; |
| 8831 | |
| 8832 | VkWriteDescriptorSet descriptor_write; |
| 8833 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8834 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8835 | descriptor_write.dstSet = descriptorSet; |
| 8836 | descriptor_write.dstBinding = 0; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8837 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8838 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 8839 | descriptor_write.pImageInfo = &descriptor_info; |
| 8840 | |
| 8841 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8842 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8843 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8844 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8845 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8846 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8847 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8848 | } |
| 8849 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8850 | TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) { |
| 8851 | // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update |
| 8852 | // into the other |
| 8853 | VkResult err; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8854 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8855 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8856 | " binding #1 with type " |
| 8857 | "VK_DESCRIPTOR_TYPE_SAMPLER. Types do " |
| 8858 | "not match."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8859 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8860 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8861 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8862 | VkDescriptorPoolSize ds_type_count[2] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8863 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8864 | ds_type_count[0].descriptorCount = 1; |
| 8865 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8866 | ds_type_count[1].descriptorCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8867 | |
| 8868 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8869 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8870 | ds_pool_ci.pNext = NULL; |
| 8871 | ds_pool_ci.maxSets = 1; |
| 8872 | ds_pool_ci.poolSizeCount = 2; |
| 8873 | ds_pool_ci.pPoolSizes = ds_type_count; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8874 | |
| 8875 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8876 | err = |
| 8877 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8878 | ASSERT_VK_SUCCESS(err); |
| 8879 | VkDescriptorSetLayoutBinding dsl_binding[2] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8880 | dsl_binding[0].binding = 0; |
| 8881 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8882 | dsl_binding[0].descriptorCount = 1; |
| 8883 | dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 8884 | dsl_binding[0].pImmutableSamplers = NULL; |
| 8885 | dsl_binding[1].binding = 1; |
| 8886 | dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8887 | dsl_binding[1].descriptorCount = 1; |
| 8888 | dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL; |
| 8889 | dsl_binding[1].pImmutableSamplers = NULL; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8890 | |
| 8891 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8892 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8893 | ds_layout_ci.pNext = NULL; |
| 8894 | ds_layout_ci.bindingCount = 2; |
| 8895 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8896 | |
| 8897 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8898 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8899 | &ds_layout); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8900 | ASSERT_VK_SUCCESS(err); |
| 8901 | |
| 8902 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8903 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8904 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8905 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8906 | alloc_info.descriptorPool = ds_pool; |
| 8907 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8908 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8909 | &descriptorSet); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8910 | ASSERT_VK_SUCCESS(err); |
| 8911 | |
| 8912 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8913 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8914 | sampler_ci.pNext = NULL; |
| 8915 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8916 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8917 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8918 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8919 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8920 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8921 | sampler_ci.mipLodBias = 1.0; |
| 8922 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8923 | sampler_ci.maxAnisotropy = 1; |
| 8924 | sampler_ci.compareEnable = VK_FALSE; |
| 8925 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8926 | sampler_ci.minLod = 1.0; |
| 8927 | sampler_ci.maxLod = 1.0; |
| 8928 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8929 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8930 | |
| 8931 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8932 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8933 | ASSERT_VK_SUCCESS(err); |
| 8934 | |
| 8935 | VkDescriptorImageInfo info = {}; |
| 8936 | info.sampler = sampler; |
| 8937 | |
| 8938 | VkWriteDescriptorSet descriptor_write; |
| 8939 | memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet)); |
| 8940 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8941 | descriptor_write.dstSet = descriptorSet; |
| 8942 | descriptor_write.dstBinding = 1; // SAMPLER binding from layout above |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8943 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8944 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8945 | descriptor_write.pImageInfo = &info; |
| 8946 | // This write update should succeed |
| 8947 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8948 | // Now perform a copy update that fails due to type mismatch |
| 8949 | VkCopyDescriptorSet copy_ds_update; |
| 8950 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 8951 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 8952 | copy_ds_update.srcSet = descriptorSet; |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 8953 | copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8954 | copy_ds_update.dstSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8955 | copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8956 | copy_ds_update.descriptorCount = 1; // copy 1 descriptor |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8957 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 8958 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8959 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8960 | // 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] | 8961 | m_errorMonitor->SetDesiredFailureMsg( |
| 8962 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8963 | " does not have copy update src binding of 3."); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8964 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 8965 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 8966 | copy_ds_update.srcSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8967 | copy_ds_update.srcBinding = |
| 8968 | 3; // ERROR : Invalid binding for matching layout |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8969 | copy_ds_update.dstSet = descriptorSet; |
| 8970 | copy_ds_update.dstBinding = 0; |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 8971 | copy_ds_update.descriptorCount = 1; // Copy 1 descriptor |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8972 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 8973 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8974 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8975 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8976 | // 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] | 8977 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8978 | VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus " |
| 8979 | "update array offset of 0 and update of " |
| 8980 | "5 descriptors oversteps total number " |
| 8981 | "of descriptors in set: 2."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8982 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8983 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 8984 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 8985 | copy_ds_update.srcSet = descriptorSet; |
| 8986 | copy_ds_update.srcBinding = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8987 | copy_ds_update.dstSet = descriptorSet; |
| 8988 | copy_ds_update.dstBinding = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8989 | copy_ds_update.descriptorCount = |
| 8990 | 5; // ERROR copy 5 descriptors (out of bounds for layout) |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8991 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 8992 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8993 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8994 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8995 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8996 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8997 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8998 | } |
| 8999 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9000 | TEST_F(VkLayerTest, NumSamplesMismatch) { |
| 9001 | // Create CommandBuffer where MSAA samples doesn't match RenderPass |
| 9002 | // sampleCount |
| 9003 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9004 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9005 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9006 | "Num samples mismatch! "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9007 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9008 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9009 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9010 | VkDescriptorPoolSize ds_type_count = {}; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9011 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9012 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9013 | |
| 9014 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9015 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9016 | ds_pool_ci.pNext = NULL; |
| 9017 | ds_pool_ci.maxSets = 1; |
| 9018 | ds_pool_ci.poolSizeCount = 1; |
| 9019 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 9020 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9021 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9022 | err = |
| 9023 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9024 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9025 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9026 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 9027 | dsl_binding.binding = 0; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9028 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | 0212448 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 9029 | dsl_binding.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9030 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9031 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9032 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9033 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9034 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9035 | ds_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 9036 | ds_layout_ci.bindingCount = 1; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 9037 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9038 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9039 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9040 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9041 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9042 | ASSERT_VK_SUCCESS(err); |
| 9043 | |
| 9044 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9045 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9046 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9047 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9048 | alloc_info.descriptorPool = ds_pool; |
| 9049 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9050 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9051 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9052 | ASSERT_VK_SUCCESS(err); |
| 9053 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9054 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9055 | pipe_ms_state_ci.sType = |
| 9056 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9057 | pipe_ms_state_ci.pNext = NULL; |
| 9058 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT; |
| 9059 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9060 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9061 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9062 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9063 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9064 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9065 | pipeline_layout_ci.pNext = NULL; |
| 9066 | pipeline_layout_ci.setLayoutCount = 1; |
| 9067 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9068 | |
| 9069 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9070 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9071 | &pipeline_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9072 | ASSERT_VK_SUCCESS(err); |
| 9073 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9074 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9075 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9076 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9077 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9078 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9079 | // but add it to be able to run on more devices |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9080 | VkPipelineObj pipe(m_device); |
| 9081 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 9082 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9083 | pipe.AddColorAttachment(); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9084 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 9085 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9086 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 9087 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9088 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9089 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 9090 | |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9091 | // Render triangle (the error should trigger on the attempt to draw). |
| 9092 | Draw(3, 1, 0, 0); |
| 9093 | |
| 9094 | // Finalize recording of the command buffer |
| 9095 | EndCommandBuffer(); |
| 9096 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9097 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9098 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9099 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9100 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9101 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 9102 | } |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9103 | |
Tobin Ehlis | 85aa15a | 2016-06-15 10:52:37 -0600 | [diff] [blame] | 9104 | TEST_F(VkLayerTest, RenderPassIncompatible) { |
| 9105 | TEST_DESCRIPTION("Hit RenderPass incompatible cases. " |
| 9106 | "Initial case is drawing with an active renderpass that's " |
| 9107 | "not compatible with the bound PSO's creation renderpass"); |
| 9108 | VkResult err; |
| 9109 | |
| 9110 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9111 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9112 | |
| 9113 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 9114 | dsl_binding.binding = 0; |
| 9115 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9116 | dsl_binding.descriptorCount = 1; |
| 9117 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9118 | dsl_binding.pImmutableSamplers = NULL; |
| 9119 | |
| 9120 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9121 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9122 | ds_layout_ci.pNext = NULL; |
| 9123 | ds_layout_ci.bindingCount = 1; |
| 9124 | ds_layout_ci.pBindings = &dsl_binding; |
| 9125 | |
| 9126 | VkDescriptorSetLayout ds_layout; |
| 9127 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9128 | &ds_layout); |
| 9129 | ASSERT_VK_SUCCESS(err); |
| 9130 | |
| 9131 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 9132 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9133 | pipeline_layout_ci.pNext = NULL; |
| 9134 | pipeline_layout_ci.setLayoutCount = 1; |
| 9135 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 9136 | |
| 9137 | VkPipelineLayout pipeline_layout; |
| 9138 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9139 | &pipeline_layout); |
| 9140 | ASSERT_VK_SUCCESS(err); |
| 9141 | |
| 9142 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9143 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9144 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9145 | VK_SHADER_STAGE_FRAGMENT_BIT, |
| 9146 | this); // We shouldn't need a fragment shader |
| 9147 | // but add it to be able to run on more devices |
| 9148 | // Create a renderpass that will be incompatible with default renderpass |
| 9149 | VkAttachmentReference attach = {}; |
| 9150 | attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 9151 | VkAttachmentReference color_att = {}; |
| 9152 | color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 9153 | VkSubpassDescription subpass = {}; |
| 9154 | subpass.inputAttachmentCount = 1; |
| 9155 | subpass.pInputAttachments = &attach; |
| 9156 | subpass.colorAttachmentCount = 1; |
| 9157 | subpass.pColorAttachments = &color_att; |
| 9158 | VkRenderPassCreateInfo rpci = {}; |
| 9159 | rpci.subpassCount = 1; |
| 9160 | rpci.pSubpasses = &subpass; |
| 9161 | rpci.attachmentCount = 1; |
| 9162 | VkAttachmentDescription attach_desc = {}; |
| 9163 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
Cody Northrop | bd16af1 | 2016-06-21 09:25:48 -0600 | [diff] [blame] | 9164 | // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM |
| 9165 | attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM; |
Tobin Ehlis | 85aa15a | 2016-06-15 10:52:37 -0600 | [diff] [blame] | 9166 | rpci.pAttachments = &attach_desc; |
| 9167 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 9168 | VkRenderPass rp; |
| 9169 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9170 | VkPipelineObj pipe(m_device); |
| 9171 | pipe.AddShader(&vs); |
| 9172 | pipe.AddShader(&fs); |
| 9173 | pipe.AddColorAttachment(); |
| 9174 | VkViewport view_port = {}; |
| 9175 | m_viewports.push_back(view_port); |
| 9176 | pipe.SetViewport(m_viewports); |
| 9177 | VkRect2D rect = {}; |
| 9178 | m_scissors.push_back(rect); |
| 9179 | pipe.SetScissor(m_scissors); |
| 9180 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 9181 | |
| 9182 | VkCommandBufferInheritanceInfo cbii = {}; |
| 9183 | cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; |
| 9184 | cbii.renderPass = rp; |
| 9185 | cbii.subpass = 0; |
| 9186 | VkCommandBufferBeginInfo cbbi = {}; |
| 9187 | cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 9188 | cbbi.pInheritanceInfo = &cbii; |
| 9189 | vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi); |
| 9190 | VkRenderPassBeginInfo rpbi = {}; |
| 9191 | rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 9192 | rpbi.framebuffer = m_framebuffer; |
| 9193 | rpbi.renderPass = rp; |
| 9194 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, |
| 9195 | VK_SUBPASS_CONTENTS_INLINE); |
| 9196 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9197 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 9198 | |
| 9199 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9200 | " is incompatible w/ gfx pipeline "); |
| 9201 | // Render triangle (the error should trigger on the attempt to draw). |
| 9202 | Draw(3, 1, 0, 0); |
| 9203 | |
| 9204 | // Finalize recording of the command buffer |
| 9205 | EndCommandBuffer(); |
| 9206 | |
| 9207 | m_errorMonitor->VerifyFound(); |
| 9208 | |
| 9209 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9210 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9211 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 9212 | } |
| 9213 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9214 | TEST_F(VkLayerTest, NumBlendAttachMismatch) { |
| 9215 | // Create Pipeline where the number of blend attachments doesn't match the |
| 9216 | // number of color attachments. In this case, we don't add any color |
| 9217 | // blend attachments even though we have a color attachment. |
| 9218 | VkResult err; |
| 9219 | |
| 9220 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9221 | "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] | 9222 | |
| 9223 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9224 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9225 | VkDescriptorPoolSize ds_type_count = {}; |
| 9226 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9227 | ds_type_count.descriptorCount = 1; |
| 9228 | |
| 9229 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 9230 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9231 | ds_pool_ci.pNext = NULL; |
| 9232 | ds_pool_ci.maxSets = 1; |
| 9233 | ds_pool_ci.poolSizeCount = 1; |
| 9234 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 9235 | |
| 9236 | VkDescriptorPool ds_pool; |
| 9237 | err = |
| 9238 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 9239 | ASSERT_VK_SUCCESS(err); |
| 9240 | |
| 9241 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 9242 | dsl_binding.binding = 0; |
| 9243 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9244 | dsl_binding.descriptorCount = 1; |
| 9245 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9246 | dsl_binding.pImmutableSamplers = NULL; |
| 9247 | |
| 9248 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9249 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9250 | ds_layout_ci.pNext = NULL; |
| 9251 | ds_layout_ci.bindingCount = 1; |
| 9252 | ds_layout_ci.pBindings = &dsl_binding; |
| 9253 | |
| 9254 | VkDescriptorSetLayout ds_layout; |
| 9255 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9256 | &ds_layout); |
| 9257 | ASSERT_VK_SUCCESS(err); |
| 9258 | |
| 9259 | VkDescriptorSet descriptorSet; |
| 9260 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 9261 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 9262 | alloc_info.descriptorSetCount = 1; |
| 9263 | alloc_info.descriptorPool = ds_pool; |
| 9264 | alloc_info.pSetLayouts = &ds_layout; |
| 9265 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9266 | &descriptorSet); |
| 9267 | ASSERT_VK_SUCCESS(err); |
| 9268 | |
| 9269 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
| 9270 | pipe_ms_state_ci.sType = |
| 9271 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9272 | pipe_ms_state_ci.pNext = NULL; |
| 9273 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; |
| 9274 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9275 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9276 | pipe_ms_state_ci.pSampleMask = NULL; |
| 9277 | |
| 9278 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 9279 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9280 | pipeline_layout_ci.pNext = NULL; |
| 9281 | pipeline_layout_ci.setLayoutCount = 1; |
| 9282 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 9283 | |
| 9284 | VkPipelineLayout pipeline_layout; |
| 9285 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9286 | &pipeline_layout); |
| 9287 | ASSERT_VK_SUCCESS(err); |
| 9288 | |
| 9289 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9290 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9291 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9292 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9293 | this); // We shouldn't need a fragment shader |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9294 | // but add it to be able to run on more devices |
| 9295 | VkPipelineObj pipe(m_device); |
| 9296 | pipe.AddShader(&vs); |
| 9297 | pipe.AddShader(&fs); |
| 9298 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 9299 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 9300 | |
| 9301 | BeginCommandBuffer(); |
| 9302 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9303 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 9304 | |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9305 | // Render triangle (the error should trigger on the attempt to draw). |
| 9306 | Draw(3, 1, 0, 0); |
| 9307 | |
| 9308 | // Finalize recording of the command buffer |
| 9309 | EndCommandBuffer(); |
| 9310 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9311 | m_errorMonitor->VerifyFound(); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9312 | |
| 9313 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9314 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9315 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 9316 | } |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9317 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 9318 | TEST_F(VkLayerTest, MissingClearAttachment) { |
| 9319 | TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment " |
| 9320 | "structure passed to vkCmdClearAttachments"); |
| 9321 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9322 | "vkCmdClearAttachments() attachment index 1 not found in attachment " |
| 9323 | "reference array of active subpass 0"); |
| 9324 | |
| 9325 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments); |
| 9326 | m_errorMonitor->VerifyFound(); |
| 9327 | } |
| 9328 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9329 | TEST_F(VkLayerTest, ClearCmdNoDraw) { |
| 9330 | // Create CommandBuffer where we add ClearCmd for FB Color attachment prior |
| 9331 | // to issuing a Draw |
| 9332 | VkResult err; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9333 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9334 | m_errorMonitor->SetDesiredFailureMsg( |
Tony Barbour | 7e56d30 | 2016-03-02 15:12:01 -0700 | [diff] [blame] | 9335 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9336 | "vkCmdClearAttachments() issued on CB object "); |
| 9337 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9338 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9339 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9340 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9341 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9342 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9343 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9344 | |
| 9345 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9346 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9347 | ds_pool_ci.pNext = NULL; |
| 9348 | ds_pool_ci.maxSets = 1; |
| 9349 | ds_pool_ci.poolSizeCount = 1; |
| 9350 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9351 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9352 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9353 | err = |
| 9354 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9355 | ASSERT_VK_SUCCESS(err); |
| 9356 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9357 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9358 | dsl_binding.binding = 0; |
| 9359 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9360 | dsl_binding.descriptorCount = 1; |
| 9361 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9362 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9363 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9364 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9365 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9366 | ds_layout_ci.pNext = NULL; |
| 9367 | ds_layout_ci.bindingCount = 1; |
| 9368 | ds_layout_ci.pBindings = &dsl_binding; |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9369 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9370 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9371 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9372 | &ds_layout); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9373 | ASSERT_VK_SUCCESS(err); |
| 9374 | |
| 9375 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9376 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9377 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9378 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9379 | alloc_info.descriptorPool = ds_pool; |
| 9380 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9381 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9382 | &descriptorSet); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9383 | ASSERT_VK_SUCCESS(err); |
| 9384 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9385 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9386 | pipe_ms_state_ci.sType = |
| 9387 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9388 | pipe_ms_state_ci.pNext = NULL; |
| 9389 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT; |
| 9390 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9391 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9392 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9393 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9394 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9395 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9396 | pipeline_layout_ci.pNext = NULL; |
| 9397 | pipeline_layout_ci.setLayoutCount = 1; |
| 9398 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9399 | |
| 9400 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9401 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9402 | &pipeline_layout); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9403 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9404 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9405 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9406 | VK_SHADER_STAGE_VERTEX_BIT, this); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9407 | // 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] | 9408 | // on more devices |
| 9409 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9410 | VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9411 | |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9412 | VkPipelineObj pipe(m_device); |
| 9413 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 9414 | pipe.AddShader(&fs); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9415 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 9416 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 9417 | |
| 9418 | BeginCommandBuffer(); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9419 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9420 | // Main thing we care about for this test is that the VkImage obj we're |
| 9421 | // clearing matches Color Attachment of FB |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9422 | // Also pass down other dummy params to keep driver and paramchecker happy |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 9423 | VkClearAttachment color_attachment; |
| 9424 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9425 | color_attachment.clearValue.color.float32[0] = 1.0; |
| 9426 | color_attachment.clearValue.color.float32[1] = 1.0; |
| 9427 | color_attachment.clearValue.color.float32[2] = 1.0; |
| 9428 | color_attachment.clearValue.color.float32[3] = 1.0; |
| 9429 | color_attachment.colorAttachment = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9430 | VkClearRect clear_rect = { |
| 9431 | {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}}; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9432 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9433 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 9434 | &color_attachment, 1, &clear_rect); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9435 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9436 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9437 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9438 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9439 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9440 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9441 | } |
| 9442 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9443 | TEST_F(VkLayerTest, VtxBufferBadIndex) { |
| 9444 | VkResult err; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9445 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9446 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 9447 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | dfcd9b6 | 2015-12-14 15:14:10 -0700 | [diff] [blame] | 9448 | "but no vertex buffers are attached to this Pipeline State Object"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9449 | |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9450 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 9451 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9452 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9453 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9454 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9455 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9456 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9457 | |
| 9458 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9459 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9460 | ds_pool_ci.pNext = NULL; |
| 9461 | ds_pool_ci.maxSets = 1; |
| 9462 | ds_pool_ci.poolSizeCount = 1; |
| 9463 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9464 | |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 9465 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9466 | err = |
| 9467 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9468 | ASSERT_VK_SUCCESS(err); |
| 9469 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9470 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9471 | dsl_binding.binding = 0; |
| 9472 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9473 | dsl_binding.descriptorCount = 1; |
| 9474 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9475 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9476 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9477 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9478 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9479 | ds_layout_ci.pNext = NULL; |
| 9480 | ds_layout_ci.bindingCount = 1; |
| 9481 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9482 | |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9483 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9484 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9485 | &ds_layout); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9486 | ASSERT_VK_SUCCESS(err); |
| 9487 | |
| 9488 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9489 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9490 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9491 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9492 | alloc_info.descriptorPool = ds_pool; |
| 9493 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9494 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9495 | &descriptorSet); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9496 | ASSERT_VK_SUCCESS(err); |
| 9497 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9498 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9499 | pipe_ms_state_ci.sType = |
| 9500 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9501 | pipe_ms_state_ci.pNext = NULL; |
| 9502 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; |
| 9503 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9504 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9505 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9506 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9507 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9508 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9509 | pipeline_layout_ci.pNext = NULL; |
| 9510 | pipeline_layout_ci.setLayoutCount = 1; |
| 9511 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 9512 | VkPipelineLayout pipeline_layout; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9513 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9514 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9515 | &pipeline_layout); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9516 | ASSERT_VK_SUCCESS(err); |
| 9517 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9518 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9519 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9520 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9521 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9522 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9523 | // but add it to be able to run on more devices |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9524 | VkPipelineObj pipe(m_device); |
| 9525 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 9526 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9527 | pipe.AddColorAttachment(); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9528 | pipe.SetMSAA(&pipe_ms_state_ci); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 9529 | pipe.SetViewport(m_viewports); |
| 9530 | pipe.SetScissor(m_scissors); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9531 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 9532 | |
| 9533 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9534 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9535 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | f7bf450 | 2015-09-09 15:12:35 -0600 | [diff] [blame] | 9536 | // Don't care about actual data, just need to get to draw to flag error |
| 9537 | static const float vbo_data[3] = {1.f, 0.f, 1.f}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9538 | VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), |
| 9539 | (const void *)&vbo_data); |
Tobin Ehlis | f7bf450 | 2015-09-09 15:12:35 -0600 | [diff] [blame] | 9540 | 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] | 9541 | Draw(1, 0, 0, 0); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9542 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9543 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9544 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9545 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9546 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9547 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9548 | } |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 9549 | // INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here) |
| 9550 | TEST_F(VkLayerTest, InvalidImageLayout) { |
| 9551 | TEST_DESCRIPTION("Hit all possible validation checks associated with the " |
| 9552 | "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having" |
| 9553 | "images in the wrong layout when they're copied or transitioned."); |
| 9554 | // 3 in ValidateCmdBufImageLayouts |
| 9555 | // * -1 Attempt to submit cmd buf w/ deleted image |
| 9556 | // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource |
| 9557 | // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource |
| 9558 | m_errorMonitor->SetDesiredFailureMsg( |
| 9559 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9560 | "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL."); |
| 9561 | |
| 9562 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9563 | // Create src & dst images to use for copy operations |
| 9564 | VkImage src_image; |
| 9565 | VkImage dst_image; |
| 9566 | |
| 9567 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 9568 | const int32_t tex_width = 32; |
| 9569 | const int32_t tex_height = 32; |
| 9570 | |
| 9571 | VkImageCreateInfo image_create_info = {}; |
| 9572 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 9573 | image_create_info.pNext = NULL; |
| 9574 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 9575 | image_create_info.format = tex_format; |
| 9576 | image_create_info.extent.width = tex_width; |
| 9577 | image_create_info.extent.height = tex_height; |
| 9578 | image_create_info.extent.depth = 1; |
| 9579 | image_create_info.mipLevels = 1; |
| 9580 | image_create_info.arrayLayers = 4; |
| 9581 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 9582 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 9583 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 9584 | image_create_info.flags = 0; |
| 9585 | |
| 9586 | VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image); |
| 9587 | ASSERT_VK_SUCCESS(err); |
| 9588 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image); |
| 9589 | ASSERT_VK_SUCCESS(err); |
| 9590 | |
| 9591 | BeginCommandBuffer(); |
| 9592 | VkImageCopy copyRegion; |
| 9593 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9594 | copyRegion.srcSubresource.mipLevel = 0; |
| 9595 | copyRegion.srcSubresource.baseArrayLayer = 0; |
| 9596 | copyRegion.srcSubresource.layerCount = 1; |
| 9597 | copyRegion.srcOffset.x = 0; |
| 9598 | copyRegion.srcOffset.y = 0; |
| 9599 | copyRegion.srcOffset.z = 0; |
| 9600 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9601 | copyRegion.dstSubresource.mipLevel = 0; |
| 9602 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 9603 | copyRegion.dstSubresource.layerCount = 1; |
| 9604 | copyRegion.dstOffset.x = 0; |
| 9605 | copyRegion.dstOffset.y = 0; |
| 9606 | copyRegion.dstOffset.z = 0; |
| 9607 | copyRegion.extent.width = 1; |
| 9608 | copyRegion.extent.height = 1; |
| 9609 | copyRegion.extent.depth = 1; |
| 9610 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9611 | m_errorMonitor->VerifyFound(); |
| 9612 | // Now cause error due to src image layout changing |
| 9613 | m_errorMonitor->SetDesiredFailureMsg( |
| 9614 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9615 | "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL."); |
| 9616 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9617 | m_errorMonitor->VerifyFound(); |
| 9618 | // Final src error is due to bad layout type |
| 9619 | m_errorMonitor->SetDesiredFailureMsg( |
| 9620 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9621 | "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL."); |
| 9622 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9623 | m_errorMonitor->VerifyFound(); |
| 9624 | // Now verify same checks for dst |
| 9625 | m_errorMonitor->SetDesiredFailureMsg( |
| 9626 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9627 | "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL."); |
| 9628 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9629 | m_errorMonitor->VerifyFound(); |
| 9630 | // Now cause error due to src image layout changing |
| 9631 | m_errorMonitor->SetDesiredFailureMsg( |
| 9632 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9633 | "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL."); |
| 9634 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, ©Region); |
| 9635 | m_errorMonitor->VerifyFound(); |
| 9636 | m_errorMonitor->SetDesiredFailureMsg( |
| 9637 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9638 | "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL."); |
| 9639 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, ©Region); |
| 9640 | m_errorMonitor->VerifyFound(); |
| 9641 | // Now cause error due to bad image layout transition in PipelineBarrier |
| 9642 | VkImageMemoryBarrier image_barrier[1] = {}; |
| 9643 | image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 9644 | image_barrier[0].image = src_image; |
| 9645 | image_barrier[0].subresourceRange.layerCount = 2; |
| 9646 | image_barrier[0].subresourceRange.levelCount = 2; |
| 9647 | image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9648 | m_errorMonitor->SetDesiredFailureMsg( |
| 9649 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9650 | "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL."); |
| 9651 | vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier); |
| 9652 | m_errorMonitor->VerifyFound(); |
| 9653 | |
| 9654 | // Finally some layout errors at RenderPass create time |
| 9655 | // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing. |
| 9656 | VkAttachmentReference attach = {}; |
| 9657 | // perf warning for GENERAL layout w/ non-DS input attachment |
| 9658 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 9659 | VkSubpassDescription subpass = {}; |
| 9660 | subpass.inputAttachmentCount = 1; |
| 9661 | subpass.pInputAttachments = &attach; |
| 9662 | VkRenderPassCreateInfo rpci = {}; |
| 9663 | rpci.subpassCount = 1; |
| 9664 | rpci.pSubpasses = &subpass; |
| 9665 | rpci.attachmentCount = 1; |
| 9666 | VkAttachmentDescription attach_desc = {}; |
| 9667 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 9668 | rpci.pAttachments = &attach_desc; |
Tobin Ehlis | 1efce02 | 2016-05-11 10:40:34 -0600 | [diff] [blame] | 9669 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 9670 | VkRenderPass rp; |
| 9671 | m_errorMonitor->SetDesiredFailureMsg( |
| 9672 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9673 | "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL."); |
| 9674 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9675 | m_errorMonitor->VerifyFound(); |
| 9676 | // error w/ non-general layout |
| 9677 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 9678 | |
| 9679 | m_errorMonitor->SetDesiredFailureMsg( |
| 9680 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9681 | "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL."); |
| 9682 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9683 | m_errorMonitor->VerifyFound(); |
| 9684 | subpass.inputAttachmentCount = 0; |
| 9685 | subpass.colorAttachmentCount = 1; |
| 9686 | subpass.pColorAttachments = &attach; |
| 9687 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 9688 | // perf warning for GENERAL layout on color attachment |
| 9689 | m_errorMonitor->SetDesiredFailureMsg( |
| 9690 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9691 | "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL."); |
| 9692 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9693 | m_errorMonitor->VerifyFound(); |
| 9694 | // error w/ non-color opt or GENERAL layout for color attachment |
| 9695 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 9696 | m_errorMonitor->SetDesiredFailureMsg( |
| 9697 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9698 | "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL."); |
| 9699 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9700 | m_errorMonitor->VerifyFound(); |
| 9701 | subpass.colorAttachmentCount = 0; |
| 9702 | subpass.pDepthStencilAttachment = &attach; |
| 9703 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 9704 | // perf warning for GENERAL layout on DS attachment |
| 9705 | m_errorMonitor->SetDesiredFailureMsg( |
| 9706 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9707 | "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL."); |
| 9708 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9709 | m_errorMonitor->VerifyFound(); |
| 9710 | // error w/ non-ds opt or GENERAL layout for color attachment |
| 9711 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 9712 | m_errorMonitor->SetDesiredFailureMsg( |
| 9713 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9714 | "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL."); |
| 9715 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9716 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 1efce02 | 2016-05-11 10:40:34 -0600 | [diff] [blame] | 9717 | // For this error we need a valid renderpass so create default one |
| 9718 | attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 9719 | attach.attachment = 0; |
| 9720 | attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 9721 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
| 9722 | attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE; |
| 9723 | attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 9724 | attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 9725 | // Can't do a CLEAR load on READ_ONLY initialLayout |
| 9726 | attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 9727 | attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 9728 | attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 9729 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9730 | " with invalid first layout " |
| 9731 | "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_" |
| 9732 | "ONLY_OPTIMAL"); |
| 9733 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9734 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 9735 | |
| 9736 | vkDestroyImage(m_device->device(), src_image, NULL); |
| 9737 | vkDestroyImage(m_device->device(), dst_image, NULL); |
| 9738 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9739 | #endif // DRAW_STATE_TESTS |
| 9740 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 9741 | #if THREADING_TESTS |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9742 | #if GTEST_IS_THREADSAFE |
| 9743 | struct thread_data_struct { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9744 | VkCommandBuffer commandBuffer; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9745 | VkEvent event; |
| 9746 | bool bailout; |
| 9747 | }; |
| 9748 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9749 | extern "C" void *AddToCommandBuffer(void *arg) { |
| 9750 | struct thread_data_struct *data = (struct thread_data_struct *)arg; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9751 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9752 | for (int i = 0; i < 10000; i++) { |
| 9753 | vkCmdSetEvent(data->commandBuffer, data->event, |
| 9754 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9755 | if (data->bailout) { |
| 9756 | break; |
| 9757 | } |
| 9758 | } |
| 9759 | return NULL; |
| 9760 | } |
| 9761 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9762 | TEST_F(VkLayerTest, ThreadCommandBufferCollision) { |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 9763 | test_platform_thread thread; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9764 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9765 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9766 | "THREADING ERROR"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9767 | |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9768 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9769 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 9770 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9771 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9772 | // Calls AllocateCommandBuffers |
| 9773 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
Mark Lobodzinski | 5495d13 | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 9774 | |
| 9775 | // Avoid creating RenderPass |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9776 | commandBuffer.BeginCommandBuffer(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9777 | |
| 9778 | VkEventCreateInfo event_info; |
| 9779 | VkEvent event; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9780 | VkResult err; |
| 9781 | |
| 9782 | memset(&event_info, 0, sizeof(event_info)); |
| 9783 | event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 9784 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9785 | err = vkCreateEvent(device(), &event_info, NULL, &event); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9786 | ASSERT_VK_SUCCESS(err); |
| 9787 | |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9788 | err = vkResetEvent(device(), event); |
| 9789 | ASSERT_VK_SUCCESS(err); |
| 9790 | |
| 9791 | struct thread_data_struct data; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9792 | data.commandBuffer = commandBuffer.GetBufferHandle(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9793 | data.event = event; |
| 9794 | data.bailout = false; |
| 9795 | m_errorMonitor->SetBailout(&data.bailout); |
| 9796 | // Add many entries to command buffer from another thread. |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 9797 | test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9798 | // Add many entries to command buffer from this thread at the same time. |
| 9799 | AddToCommandBuffer(&data); |
Mark Lobodzinski | 5495d13 | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 9800 | |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 9801 | test_platform_thread_join(thread, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9802 | commandBuffer.EndCommandBuffer(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9803 | |
Mike Stroyan | 10b8cb7 | 2016-01-22 15:22:03 -0700 | [diff] [blame] | 9804 | m_errorMonitor->SetBailout(NULL); |
| 9805 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9806 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9807 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9808 | vkDestroyEvent(device(), event, NULL); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9809 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9810 | #endif // GTEST_IS_THREADSAFE |
| 9811 | #endif // THREADING_TESTS |
| 9812 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9813 | #if SHADER_CHECKER_TESTS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9814 | TEST_F(VkLayerTest, InvalidSPIRVCodeSize) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9815 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9816 | "Invalid SPIR-V header"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9817 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9818 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9819 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9820 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9821 | VkShaderModule module; |
| 9822 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 9823 | struct icd_spv_header spv; |
| 9824 | |
| 9825 | spv.magic = ICD_SPV_MAGIC; |
| 9826 | spv.version = ICD_SPV_VERSION; |
| 9827 | spv.gen_magic = 0; |
| 9828 | |
| 9829 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 9830 | moduleCreateInfo.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9831 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9832 | moduleCreateInfo.codeSize = 4; |
| 9833 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9834 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9835 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9836 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9837 | } |
| 9838 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9839 | TEST_F(VkLayerTest, InvalidSPIRVMagic) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9840 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9841 | "Invalid SPIR-V magic number"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9842 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9843 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9844 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9845 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9846 | VkShaderModule module; |
| 9847 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 9848 | struct icd_spv_header spv; |
| 9849 | |
| 9850 | spv.magic = ~ICD_SPV_MAGIC; |
| 9851 | spv.version = ICD_SPV_VERSION; |
| 9852 | spv.gen_magic = 0; |
| 9853 | |
| 9854 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 9855 | moduleCreateInfo.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9856 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9857 | moduleCreateInfo.codeSize = sizeof(spv) + 10; |
| 9858 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9859 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9860 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9861 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9862 | } |
| 9863 | |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9864 | #if 0 |
| 9865 | // Not currently covered by SPIRV-Tools validator |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9866 | TEST_F(VkLayerTest, InvalidSPIRVVersion) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9867 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9868 | "Invalid SPIR-V header"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9869 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9870 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9871 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9872 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9873 | VkShaderModule module; |
| 9874 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 9875 | struct icd_spv_header spv; |
| 9876 | |
| 9877 | spv.magic = ICD_SPV_MAGIC; |
| 9878 | spv.version = ~ICD_SPV_VERSION; |
| 9879 | spv.gen_magic = 0; |
| 9880 | |
| 9881 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 9882 | moduleCreateInfo.pNext = NULL; |
| 9883 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9884 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9885 | moduleCreateInfo.codeSize = sizeof(spv) + 10; |
| 9886 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9887 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9888 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9889 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9890 | } |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9891 | #endif |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9892 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9893 | TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 9894 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9895 | "not consumed by fragment shader"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9896 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9897 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 9898 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9899 | |
| 9900 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9901 | "#version 450\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9902 | "\n" |
| 9903 | "layout(location=0) out float x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 9904 | "out gl_PerVertex {\n" |
| 9905 | " vec4 gl_Position;\n" |
| 9906 | "};\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9907 | "void main(){\n" |
| 9908 | " gl_Position = vec4(1);\n" |
| 9909 | " x = 0;\n" |
| 9910 | "}\n"; |
| 9911 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9912 | "#version 450\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9913 | "\n" |
| 9914 | "layout(location=0) out vec4 color;\n" |
| 9915 | "void main(){\n" |
| 9916 | " color = vec4(1);\n" |
| 9917 | "}\n"; |
| 9918 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 9919 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9920 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9921 | |
| 9922 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 9923 | pipe.AddColorAttachment(); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9924 | pipe.AddShader(&vs); |
| 9925 | pipe.AddShader(&fs); |
| 9926 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9927 | VkDescriptorSetObj descriptorSet(m_device); |
| 9928 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9929 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9930 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 9931 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9932 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9933 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9934 | } |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9935 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9936 | TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9937 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9938 | "not written by vertex shader"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9939 | |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9940 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 9941 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9942 | |
| 9943 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9944 | "#version 450\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9945 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 9946 | "out gl_PerVertex {\n" |
| 9947 | " vec4 gl_Position;\n" |
| 9948 | "};\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9949 | "void main(){\n" |
| 9950 | " gl_Position = vec4(1);\n" |
| 9951 | "}\n"; |
| 9952 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9953 | "#version 450\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9954 | "\n" |
| 9955 | "layout(location=0) in float x;\n" |
| 9956 | "layout(location=0) out vec4 color;\n" |
| 9957 | "void main(){\n" |
| 9958 | " color = vec4(x);\n" |
| 9959 | "}\n"; |
| 9960 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 9961 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9962 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9963 | |
| 9964 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 9965 | pipe.AddColorAttachment(); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9966 | pipe.AddShader(&vs); |
| 9967 | pipe.AddShader(&fs); |
| 9968 | |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9969 | VkDescriptorSetObj descriptorSet(m_device); |
| 9970 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9971 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9972 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 9973 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9974 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9975 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9976 | } |
| 9977 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9978 | TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) { |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9979 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9980 | "not written by vertex shader"); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9981 | |
| 9982 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9983 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9984 | |
| 9985 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9986 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9987 | "\n" |
| 9988 | "out gl_PerVertex {\n" |
| 9989 | " vec4 gl_Position;\n" |
| 9990 | "};\n" |
| 9991 | "void main(){\n" |
| 9992 | " gl_Position = vec4(1);\n" |
| 9993 | "}\n"; |
| 9994 | char const *fsSource = |
| 9995 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9996 | "\n" |
| 9997 | "in block { layout(location=0) float x; } ins;\n" |
| 9998 | "layout(location=0) out vec4 color;\n" |
| 9999 | "void main(){\n" |
| 10000 | " color = vec4(ins.x);\n" |
| 10001 | "}\n"; |
| 10002 | |
| 10003 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10004 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10005 | |
| 10006 | VkPipelineObj pipe(m_device); |
| 10007 | pipe.AddColorAttachment(); |
| 10008 | pipe.AddShader(&vs); |
| 10009 | pipe.AddShader(&fs); |
| 10010 | |
| 10011 | VkDescriptorSetObj descriptorSet(m_device); |
| 10012 | descriptorSet.AppendDummy(); |
| 10013 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10014 | |
| 10015 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10016 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10017 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10018 | } |
| 10019 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10020 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) { |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10021 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10022 | "Type mismatch on location 0.0: 'ptr to " |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10023 | "output arr[2] of float32' vs 'ptr to " |
| 10024 | "input arr[3] of float32'"); |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10025 | |
| 10026 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10027 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10028 | |
| 10029 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10030 | "#version 450\n" |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10031 | "\n" |
| 10032 | "layout(location=0) out float x[2];\n" |
| 10033 | "out gl_PerVertex {\n" |
| 10034 | " vec4 gl_Position;\n" |
| 10035 | "};\n" |
| 10036 | "void main(){\n" |
| 10037 | " x[0] = 0; x[1] = 0;\n" |
| 10038 | " gl_Position = vec4(1);\n" |
| 10039 | "}\n"; |
| 10040 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10041 | "#version 450\n" |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10042 | "\n" |
| 10043 | "layout(location=0) in float x[3];\n" |
| 10044 | "layout(location=0) out vec4 color;\n" |
| 10045 | "void main(){\n" |
| 10046 | " color = vec4(x[0] + x[1] + x[2]);\n" |
| 10047 | "}\n"; |
| 10048 | |
| 10049 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10050 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10051 | |
| 10052 | VkPipelineObj pipe(m_device); |
| 10053 | pipe.AddColorAttachment(); |
| 10054 | pipe.AddShader(&vs); |
| 10055 | pipe.AddShader(&fs); |
| 10056 | |
| 10057 | VkDescriptorSetObj descriptorSet(m_device); |
| 10058 | descriptorSet.AppendDummy(); |
| 10059 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10060 | |
| 10061 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10062 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10063 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 10064 | } |
| 10065 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10066 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10067 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10068 | "Type mismatch on location 0"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10069 | |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10070 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10071 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10072 | |
| 10073 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10074 | "#version 450\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10075 | "\n" |
| 10076 | "layout(location=0) out int x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10077 | "out gl_PerVertex {\n" |
| 10078 | " vec4 gl_Position;\n" |
| 10079 | "};\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10080 | "void main(){\n" |
| 10081 | " x = 0;\n" |
| 10082 | " gl_Position = vec4(1);\n" |
| 10083 | "}\n"; |
| 10084 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10085 | "#version 450\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10086 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10087 | "layout(location=0) in float x;\n" /* VS writes int */ |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10088 | "layout(location=0) out vec4 color;\n" |
| 10089 | "void main(){\n" |
| 10090 | " color = vec4(x);\n" |
| 10091 | "}\n"; |
| 10092 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10093 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10094 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10095 | |
| 10096 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10097 | pipe.AddColorAttachment(); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10098 | pipe.AddShader(&vs); |
| 10099 | pipe.AddShader(&fs); |
| 10100 | |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10101 | VkDescriptorSetObj descriptorSet(m_device); |
| 10102 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10103 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10104 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10105 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10106 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10107 | m_errorMonitor->VerifyFound(); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 10108 | } |
| 10109 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10110 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) { |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10111 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10112 | "Type mismatch on location 0"); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10113 | |
| 10114 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10115 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10116 | |
| 10117 | char const *vsSource = |
| 10118 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10119 | "\n" |
| 10120 | "out block { layout(location=0) int x; } outs;\n" |
| 10121 | "out gl_PerVertex {\n" |
| 10122 | " vec4 gl_Position;\n" |
| 10123 | "};\n" |
| 10124 | "void main(){\n" |
| 10125 | " outs.x = 0;\n" |
| 10126 | " gl_Position = vec4(1);\n" |
| 10127 | "}\n"; |
| 10128 | char const *fsSource = |
| 10129 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10130 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10131 | "in block { layout(location=0) float x; } ins;\n" /* VS writes int */ |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10132 | "layout(location=0) out vec4 color;\n" |
| 10133 | "void main(){\n" |
| 10134 | " color = vec4(ins.x);\n" |
| 10135 | "}\n"; |
| 10136 | |
| 10137 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10138 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10139 | |
| 10140 | VkPipelineObj pipe(m_device); |
| 10141 | pipe.AddColorAttachment(); |
| 10142 | pipe.AddShader(&vs); |
| 10143 | pipe.AddShader(&fs); |
| 10144 | |
| 10145 | VkDescriptorSetObj descriptorSet(m_device); |
| 10146 | descriptorSet.AppendDummy(); |
| 10147 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10148 | |
| 10149 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10150 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10151 | m_errorMonitor->VerifyFound(); |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10152 | } |
| 10153 | |
| 10154 | TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) { |
| 10155 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10156 | "location 0.0 which is not written by vertex shader"); |
| 10157 | |
| 10158 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10159 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10160 | |
| 10161 | char const *vsSource = |
| 10162 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10163 | "\n" |
| 10164 | "out block { layout(location=1) float x; } outs;\n" |
| 10165 | "out gl_PerVertex {\n" |
| 10166 | " vec4 gl_Position;\n" |
| 10167 | "};\n" |
| 10168 | "void main(){\n" |
| 10169 | " outs.x = 0;\n" |
| 10170 | " gl_Position = vec4(1);\n" |
| 10171 | "}\n"; |
| 10172 | char const *fsSource = |
| 10173 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10174 | "\n" |
| 10175 | "in block { layout(location=0) float x; } ins;\n" |
| 10176 | "layout(location=0) out vec4 color;\n" |
| 10177 | "void main(){\n" |
| 10178 | " color = vec4(ins.x);\n" |
| 10179 | "}\n"; |
| 10180 | |
| 10181 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10182 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10183 | |
| 10184 | VkPipelineObj pipe(m_device); |
| 10185 | pipe.AddColorAttachment(); |
| 10186 | pipe.AddShader(&vs); |
| 10187 | pipe.AddShader(&fs); |
| 10188 | |
| 10189 | VkDescriptorSetObj descriptorSet(m_device); |
| 10190 | descriptorSet.AppendDummy(); |
| 10191 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10192 | |
| 10193 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10194 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10195 | m_errorMonitor->VerifyFound(); |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10196 | } |
| 10197 | |
| 10198 | TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) { |
| 10199 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10200 | "location 0.1 which is not written by vertex shader"); |
| 10201 | |
| 10202 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10203 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10204 | |
| 10205 | char const *vsSource = |
| 10206 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10207 | "\n" |
| 10208 | "out block { layout(location=0, component=0) float x; } outs;\n" |
| 10209 | "out gl_PerVertex {\n" |
| 10210 | " vec4 gl_Position;\n" |
| 10211 | "};\n" |
| 10212 | "void main(){\n" |
| 10213 | " outs.x = 0;\n" |
| 10214 | " gl_Position = vec4(1);\n" |
| 10215 | "}\n"; |
| 10216 | char const *fsSource = |
| 10217 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10218 | "\n" |
| 10219 | "in block { layout(location=0, component=1) float x; } ins;\n" |
| 10220 | "layout(location=0) out vec4 color;\n" |
| 10221 | "void main(){\n" |
| 10222 | " color = vec4(ins.x);\n" |
| 10223 | "}\n"; |
| 10224 | |
| 10225 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10226 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10227 | |
| 10228 | VkPipelineObj pipe(m_device); |
| 10229 | pipe.AddColorAttachment(); |
| 10230 | pipe.AddShader(&vs); |
| 10231 | pipe.AddShader(&fs); |
| 10232 | |
| 10233 | VkDescriptorSetObj descriptorSet(m_device); |
| 10234 | descriptorSet.AppendDummy(); |
| 10235 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10236 | |
| 10237 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10238 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10239 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10240 | } |
| 10241 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10242 | TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 10243 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10244 | "location 0 not consumed by VS"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10245 | |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10246 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10247 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10248 | |
| 10249 | VkVertexInputBindingDescription input_binding; |
| 10250 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10251 | |
| 10252 | VkVertexInputAttributeDescription input_attrib; |
| 10253 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10254 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10255 | |
| 10256 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10257 | "#version 450\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10258 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10259 | "out gl_PerVertex {\n" |
| 10260 | " vec4 gl_Position;\n" |
| 10261 | "};\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10262 | "void main(){\n" |
| 10263 | " gl_Position = vec4(1);\n" |
| 10264 | "}\n"; |
| 10265 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10266 | "#version 450\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10267 | "\n" |
| 10268 | "layout(location=0) out vec4 color;\n" |
| 10269 | "void main(){\n" |
| 10270 | " color = vec4(1);\n" |
| 10271 | "}\n"; |
| 10272 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10273 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10274 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10275 | |
| 10276 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10277 | pipe.AddColorAttachment(); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10278 | pipe.AddShader(&vs); |
| 10279 | pipe.AddShader(&fs); |
| 10280 | |
| 10281 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10282 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10283 | |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10284 | VkDescriptorSetObj descriptorSet(m_device); |
| 10285 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10286 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10287 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10288 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10289 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10290 | m_errorMonitor->VerifyFound(); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10291 | } |
| 10292 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10293 | TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 10294 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10295 | "location 0 not consumed by VS"); |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10296 | |
| 10297 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10298 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10299 | |
| 10300 | VkVertexInputBindingDescription input_binding; |
| 10301 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10302 | |
| 10303 | VkVertexInputAttributeDescription input_attrib; |
| 10304 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10305 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10306 | |
| 10307 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10308 | "#version 450\n" |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10309 | "\n" |
| 10310 | "layout(location=1) in float x;\n" |
| 10311 | "out gl_PerVertex {\n" |
| 10312 | " vec4 gl_Position;\n" |
| 10313 | "};\n" |
| 10314 | "void main(){\n" |
| 10315 | " gl_Position = vec4(x);\n" |
| 10316 | "}\n"; |
| 10317 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10318 | "#version 450\n" |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10319 | "\n" |
| 10320 | "layout(location=0) out vec4 color;\n" |
| 10321 | "void main(){\n" |
| 10322 | " color = vec4(1);\n" |
| 10323 | "}\n"; |
| 10324 | |
| 10325 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10326 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10327 | |
| 10328 | VkPipelineObj pipe(m_device); |
| 10329 | pipe.AddColorAttachment(); |
| 10330 | pipe.AddShader(&vs); |
| 10331 | pipe.AddShader(&fs); |
| 10332 | |
| 10333 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10334 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10335 | |
| 10336 | VkDescriptorSetObj descriptorSet(m_device); |
| 10337 | descriptorSet.AppendDummy(); |
| 10338 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10339 | |
| 10340 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10341 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10342 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10343 | } |
| 10344 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10345 | TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) { |
| 10346 | m_errorMonitor->SetDesiredFailureMsg( |
| 10347 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10348 | "VS consumes input at location 0 but not provided"); |
| 10349 | |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10350 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10351 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10352 | |
| 10353 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10354 | "#version 450\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10355 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10356 | "layout(location=0) in vec4 x;\n" /* not provided */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10357 | "out gl_PerVertex {\n" |
| 10358 | " vec4 gl_Position;\n" |
| 10359 | "};\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10360 | "void main(){\n" |
| 10361 | " gl_Position = x;\n" |
| 10362 | "}\n"; |
| 10363 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10364 | "#version 450\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10365 | "\n" |
| 10366 | "layout(location=0) out vec4 color;\n" |
| 10367 | "void main(){\n" |
| 10368 | " color = vec4(1);\n" |
| 10369 | "}\n"; |
| 10370 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10371 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10372 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10373 | |
| 10374 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10375 | pipe.AddColorAttachment(); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10376 | pipe.AddShader(&vs); |
| 10377 | pipe.AddShader(&fs); |
| 10378 | |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10379 | VkDescriptorSetObj descriptorSet(m_device); |
| 10380 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10381 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10382 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10383 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10384 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10385 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10386 | } |
| 10387 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10388 | TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) { |
| 10389 | m_errorMonitor->SetDesiredFailureMsg( |
| 10390 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10391 | "location 0 does not match VS input type"); |
| 10392 | |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10393 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10394 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10395 | |
| 10396 | VkVertexInputBindingDescription input_binding; |
| 10397 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10398 | |
| 10399 | VkVertexInputAttributeDescription input_attrib; |
| 10400 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10401 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10402 | |
| 10403 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10404 | "#version 450\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10405 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10406 | "layout(location=0) in int x;\n" /* attrib provided float */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10407 | "out gl_PerVertex {\n" |
| 10408 | " vec4 gl_Position;\n" |
| 10409 | "};\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10410 | "void main(){\n" |
| 10411 | " gl_Position = vec4(x);\n" |
| 10412 | "}\n"; |
| 10413 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10414 | "#version 450\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10415 | "\n" |
| 10416 | "layout(location=0) out vec4 color;\n" |
| 10417 | "void main(){\n" |
| 10418 | " color = vec4(1);\n" |
| 10419 | "}\n"; |
| 10420 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10421 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10422 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10423 | |
| 10424 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10425 | pipe.AddColorAttachment(); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10426 | pipe.AddShader(&vs); |
| 10427 | pipe.AddShader(&fs); |
| 10428 | |
| 10429 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10430 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10431 | |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10432 | VkDescriptorSetObj descriptorSet(m_device); |
| 10433 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10434 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10435 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10436 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10437 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10438 | m_errorMonitor->VerifyFound(); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10439 | } |
| 10440 | |
Chris Forbes | c68b43c | 2016-04-06 11:18:47 +1200 | [diff] [blame] | 10441 | TEST_F(VkLayerTest, CreatePipelineDuplicateStage) { |
| 10442 | m_errorMonitor->SetDesiredFailureMsg( |
| 10443 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10444 | "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT"); |
| 10445 | |
| 10446 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10447 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10448 | |
| 10449 | char const *vsSource = |
| 10450 | "#version 450\n" |
| 10451 | "\n" |
| 10452 | "out gl_PerVertex {\n" |
| 10453 | " vec4 gl_Position;\n" |
| 10454 | "};\n" |
| 10455 | "void main(){\n" |
| 10456 | " gl_Position = vec4(1);\n" |
| 10457 | "}\n"; |
| 10458 | char const *fsSource = |
| 10459 | "#version 450\n" |
| 10460 | "\n" |
| 10461 | "layout(location=0) out vec4 color;\n" |
| 10462 | "void main(){\n" |
| 10463 | " color = vec4(1);\n" |
| 10464 | "}\n"; |
| 10465 | |
| 10466 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10467 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10468 | |
| 10469 | VkPipelineObj pipe(m_device); |
| 10470 | pipe.AddColorAttachment(); |
| 10471 | pipe.AddShader(&vs); |
| 10472 | pipe.AddShader(&vs); |
| 10473 | pipe.AddShader(&fs); |
| 10474 | |
| 10475 | VkDescriptorSetObj descriptorSet(m_device); |
| 10476 | descriptorSet.AppendDummy(); |
| 10477 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10478 | |
| 10479 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10480 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10481 | m_errorMonitor->VerifyFound(); |
Chris Forbes | c68b43c | 2016-04-06 11:18:47 +1200 | [diff] [blame] | 10482 | } |
| 10483 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10484 | TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10485 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10486 | |
| 10487 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10488 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10489 | |
| 10490 | VkVertexInputBindingDescription input_binding; |
| 10491 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10492 | |
| 10493 | VkVertexInputAttributeDescription input_attribs[2]; |
| 10494 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 10495 | |
| 10496 | for (int i = 0; i < 2; i++) { |
| 10497 | input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 10498 | input_attribs[i].location = i; |
| 10499 | } |
| 10500 | |
| 10501 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10502 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10503 | "\n" |
| 10504 | "layout(location=0) in mat2x4 x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10505 | "out gl_PerVertex {\n" |
| 10506 | " vec4 gl_Position;\n" |
| 10507 | "};\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10508 | "void main(){\n" |
| 10509 | " gl_Position = x[0] + x[1];\n" |
| 10510 | "}\n"; |
| 10511 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10512 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10513 | "\n" |
| 10514 | "layout(location=0) out vec4 color;\n" |
| 10515 | "void main(){\n" |
| 10516 | " color = vec4(1);\n" |
| 10517 | "}\n"; |
| 10518 | |
| 10519 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10520 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10521 | |
| 10522 | VkPipelineObj pipe(m_device); |
| 10523 | pipe.AddColorAttachment(); |
| 10524 | pipe.AddShader(&vs); |
| 10525 | pipe.AddShader(&fs); |
| 10526 | |
| 10527 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10528 | pipe.AddVertexInputAttribs(input_attribs, 2); |
| 10529 | |
| 10530 | VkDescriptorSetObj descriptorSet(m_device); |
| 10531 | descriptorSet.AppendDummy(); |
| 10532 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10533 | |
| 10534 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10535 | |
| 10536 | /* expect success */ |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10537 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10538 | } |
| 10539 | |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10540 | TEST_F(VkLayerTest, CreatePipelineAttribArrayType) |
| 10541 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10542 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10543 | |
| 10544 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10545 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10546 | |
| 10547 | VkVertexInputBindingDescription input_binding; |
| 10548 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10549 | |
| 10550 | VkVertexInputAttributeDescription input_attribs[2]; |
| 10551 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 10552 | |
| 10553 | for (int i = 0; i < 2; i++) { |
| 10554 | input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 10555 | input_attribs[i].location = i; |
| 10556 | } |
| 10557 | |
| 10558 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10559 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10560 | "\n" |
| 10561 | "layout(location=0) in vec4 x[2];\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10562 | "out gl_PerVertex {\n" |
| 10563 | " vec4 gl_Position;\n" |
| 10564 | "};\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10565 | "void main(){\n" |
| 10566 | " gl_Position = x[0] + x[1];\n" |
| 10567 | "}\n"; |
| 10568 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10569 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10570 | "\n" |
| 10571 | "layout(location=0) out vec4 color;\n" |
| 10572 | "void main(){\n" |
| 10573 | " color = vec4(1);\n" |
| 10574 | "}\n"; |
| 10575 | |
| 10576 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10577 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10578 | |
| 10579 | VkPipelineObj pipe(m_device); |
| 10580 | pipe.AddColorAttachment(); |
| 10581 | pipe.AddShader(&vs); |
| 10582 | pipe.AddShader(&fs); |
| 10583 | |
| 10584 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10585 | pipe.AddVertexInputAttribs(input_attribs, 2); |
| 10586 | |
| 10587 | VkDescriptorSetObj descriptorSet(m_device); |
| 10588 | descriptorSet.AppendDummy(); |
| 10589 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10590 | |
| 10591 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10592 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10593 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10594 | } |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10595 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10596 | TEST_F(VkLayerTest, CreatePipelineSimplePositive) |
| 10597 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10598 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10599 | |
| 10600 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10601 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10602 | |
| 10603 | char const *vsSource = |
| 10604 | "#version 450\n" |
| 10605 | "out gl_PerVertex {\n" |
| 10606 | " vec4 gl_Position;\n" |
| 10607 | "};\n" |
| 10608 | "void main(){\n" |
| 10609 | " gl_Position = vec4(0);\n" |
| 10610 | "}\n"; |
| 10611 | char const *fsSource = |
| 10612 | "#version 450\n" |
| 10613 | "\n" |
| 10614 | "layout(location=0) out vec4 color;\n" |
| 10615 | "void main(){\n" |
| 10616 | " color = vec4(1);\n" |
| 10617 | "}\n"; |
| 10618 | |
| 10619 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10620 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10621 | |
| 10622 | VkPipelineObj pipe(m_device); |
| 10623 | pipe.AddColorAttachment(); |
| 10624 | pipe.AddShader(&vs); |
| 10625 | pipe.AddShader(&fs); |
| 10626 | |
| 10627 | VkDescriptorSetObj descriptorSet(m_device); |
| 10628 | descriptorSet.AppendDummy(); |
| 10629 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10630 | |
| 10631 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10632 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10633 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10634 | } |
| 10635 | |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 10636 | TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch) |
| 10637 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10638 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 10639 | |
| 10640 | // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block |
| 10641 | |
| 10642 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10643 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10644 | |
| 10645 | char const *vsSource = |
| 10646 | "#version 450\n" |
| 10647 | "out gl_PerVertex {\n" |
| 10648 | " vec4 gl_Position;\n" |
| 10649 | "};\n" |
| 10650 | "layout(location=0) out vec3 x;\n" |
| 10651 | "layout(location=1) out ivec3 y;\n" |
| 10652 | "layout(location=2) out vec3 z;\n" |
| 10653 | "void main(){\n" |
| 10654 | " gl_Position = vec4(0);\n" |
| 10655 | " x = vec3(0); y = ivec3(0); z = vec3(0);\n" |
| 10656 | "}\n"; |
| 10657 | char const *fsSource = |
| 10658 | "#version 450\n" |
| 10659 | "\n" |
| 10660 | "layout(location=0) out vec4 color;\n" |
| 10661 | "layout(location=0) in float x;\n" |
| 10662 | "layout(location=1) flat in int y;\n" |
| 10663 | "layout(location=2) in vec2 z;\n" |
| 10664 | "void main(){\n" |
| 10665 | " color = vec4(1 + x + y + z.x);\n" |
| 10666 | "}\n"; |
| 10667 | |
| 10668 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10669 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10670 | |
| 10671 | VkPipelineObj pipe(m_device); |
| 10672 | pipe.AddColorAttachment(); |
| 10673 | pipe.AddShader(&vs); |
| 10674 | pipe.AddShader(&fs); |
| 10675 | |
| 10676 | VkDescriptorSetObj descriptorSet(m_device); |
| 10677 | descriptorSet.AppendDummy(); |
| 10678 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10679 | |
| 10680 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10681 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10682 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 10683 | } |
| 10684 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10685 | TEST_F(VkLayerTest, CreatePipelineTessPerVertex) |
| 10686 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10687 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10688 | |
| 10689 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10690 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10691 | |
Chris Forbes | c1e852d | 2016-04-04 19:26:42 +1200 | [diff] [blame] | 10692 | if (!m_device->phy().features().tessellationShader) { |
| 10693 | printf("Device does not support tessellation shaders; skipped.\n"); |
| 10694 | return; |
| 10695 | } |
| 10696 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10697 | char const *vsSource = |
| 10698 | "#version 450\n" |
| 10699 | "void main(){}\n"; |
| 10700 | char const *tcsSource = |
| 10701 | "#version 450\n" |
| 10702 | "layout(location=0) out int x[];\n" |
| 10703 | "layout(vertices=3) out;\n" |
| 10704 | "void main(){\n" |
| 10705 | " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n" |
| 10706 | " gl_TessLevelInner[0] = 1;\n" |
| 10707 | " x[gl_InvocationID] = gl_InvocationID;\n" |
| 10708 | "}\n"; |
| 10709 | char const *tesSource = |
| 10710 | "#version 450\n" |
| 10711 | "layout(triangles, equal_spacing, cw) in;\n" |
| 10712 | "layout(location=0) in int x[];\n" |
| 10713 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 10714 | "void main(){\n" |
| 10715 | " gl_Position.xyz = gl_TessCoord;\n" |
| 10716 | " gl_Position.w = x[0] + x[1] + x[2];\n" |
| 10717 | "}\n"; |
| 10718 | char const *fsSource = |
| 10719 | "#version 450\n" |
| 10720 | "layout(location=0) out vec4 color;\n" |
| 10721 | "void main(){\n" |
| 10722 | " color = vec4(1);\n" |
| 10723 | "}\n"; |
| 10724 | |
| 10725 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10726 | VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this); |
| 10727 | VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this); |
| 10728 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10729 | |
| 10730 | VkPipelineInputAssemblyStateCreateInfo iasci{ |
| 10731 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, |
| 10732 | nullptr, |
| 10733 | 0, |
| 10734 | VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, |
| 10735 | VK_FALSE}; |
| 10736 | |
Chris Forbes | b4cacb6 | 2016-04-04 19:15:00 +1200 | [diff] [blame] | 10737 | VkPipelineTessellationStateCreateInfo tsci{ |
| 10738 | VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, |
| 10739 | nullptr, |
| 10740 | 0, |
| 10741 | 3}; |
| 10742 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10743 | VkPipelineObj pipe(m_device); |
| 10744 | pipe.SetInputAssembly(&iasci); |
Chris Forbes | b4cacb6 | 2016-04-04 19:15:00 +1200 | [diff] [blame] | 10745 | pipe.SetTessellation(&tsci); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10746 | pipe.AddColorAttachment(); |
| 10747 | pipe.AddShader(&vs); |
| 10748 | pipe.AddShader(&tcs); |
| 10749 | pipe.AddShader(&tes); |
| 10750 | pipe.AddShader(&fs); |
| 10751 | |
| 10752 | VkDescriptorSetObj descriptorSet(m_device); |
| 10753 | descriptorSet.AppendDummy(); |
| 10754 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10755 | |
| 10756 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10757 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10758 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10759 | } |
| 10760 | |
Chris Forbes | a0ab815 | 2016-04-20 13:34:27 +1200 | [diff] [blame] | 10761 | TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive) |
| 10762 | { |
| 10763 | m_errorMonitor->ExpectSuccess(); |
| 10764 | |
| 10765 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10766 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10767 | |
| 10768 | if (!m_device->phy().features().geometryShader) { |
| 10769 | printf("Device does not support geometry shaders; skipped.\n"); |
| 10770 | return; |
| 10771 | } |
| 10772 | |
| 10773 | char const *vsSource = |
| 10774 | "#version 450\n" |
| 10775 | "layout(location=0) out VertexData { vec4 x; } vs_out;\n" |
| 10776 | "void main(){\n" |
| 10777 | " vs_out.x = vec4(1);\n" |
| 10778 | "}\n"; |
| 10779 | char const *gsSource = |
| 10780 | "#version 450\n" |
| 10781 | "layout(triangles) in;\n" |
| 10782 | "layout(triangle_strip, max_vertices=3) out;\n" |
| 10783 | "layout(location=0) in VertexData { vec4 x; } gs_in[];\n" |
| 10784 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 10785 | "void main() {\n" |
| 10786 | " gl_Position = gs_in[0].x;\n" |
| 10787 | " EmitVertex();\n" |
| 10788 | "}\n"; |
| 10789 | char const *fsSource = |
| 10790 | "#version 450\n" |
| 10791 | "layout(location=0) out vec4 color;\n" |
| 10792 | "void main(){\n" |
| 10793 | " color = vec4(1);\n" |
| 10794 | "}\n"; |
| 10795 | |
| 10796 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10797 | VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this); |
| 10798 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10799 | |
| 10800 | VkPipelineObj pipe(m_device); |
| 10801 | pipe.AddColorAttachment(); |
| 10802 | pipe.AddShader(&vs); |
| 10803 | pipe.AddShader(&gs); |
| 10804 | pipe.AddShader(&fs); |
| 10805 | |
| 10806 | VkDescriptorSetObj descriptorSet(m_device); |
| 10807 | descriptorSet.AppendDummy(); |
| 10808 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10809 | |
| 10810 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10811 | |
| 10812 | m_errorMonitor->VerifyNotFound(); |
| 10813 | } |
| 10814 | |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 10815 | TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) |
| 10816 | { |
| 10817 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10818 | "is per-vertex in tessellation control shader stage " |
| 10819 | "but per-patch in tessellation evaluation shader stage"); |
| 10820 | |
| 10821 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10822 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10823 | |
Chris Forbes | c1e852d | 2016-04-04 19:26:42 +1200 | [diff] [blame] | 10824 | if (!m_device->phy().features().tessellationShader) { |
| 10825 | printf("Device does not support tessellation shaders; skipped.\n"); |
| 10826 | return; |
| 10827 | } |
| 10828 | |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 10829 | char const *vsSource = |
| 10830 | "#version 450\n" |
| 10831 | "void main(){}\n"; |
| 10832 | char const *tcsSource = |
| 10833 | "#version 450\n" |
| 10834 | "layout(location=0) out int x[];\n" |
| 10835 | "layout(vertices=3) out;\n" |
| 10836 | "void main(){\n" |
| 10837 | " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n" |
| 10838 | " gl_TessLevelInner[0] = 1;\n" |
| 10839 | " x[gl_InvocationID] = gl_InvocationID;\n" |
| 10840 | "}\n"; |
| 10841 | char const *tesSource = |
| 10842 | "#version 450\n" |
| 10843 | "layout(triangles, equal_spacing, cw) in;\n" |
| 10844 | "layout(location=0) patch in int x;\n" |
| 10845 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 10846 | "void main(){\n" |
| 10847 | " gl_Position.xyz = gl_TessCoord;\n" |
| 10848 | " gl_Position.w = x;\n" |
| 10849 | "}\n"; |
| 10850 | char const *fsSource = |
| 10851 | "#version 450\n" |
| 10852 | "layout(location=0) out vec4 color;\n" |
| 10853 | "void main(){\n" |
| 10854 | " color = vec4(1);\n" |
| 10855 | "}\n"; |
| 10856 | |
| 10857 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10858 | VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this); |
| 10859 | VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this); |
| 10860 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10861 | |
| 10862 | VkPipelineInputAssemblyStateCreateInfo iasci{ |
| 10863 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, |
| 10864 | nullptr, |
| 10865 | 0, |
| 10866 | VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, |
| 10867 | VK_FALSE}; |
| 10868 | |
| 10869 | VkPipelineTessellationStateCreateInfo tsci{ |
| 10870 | VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, |
| 10871 | nullptr, |
| 10872 | 0, |
| 10873 | 3}; |
| 10874 | |
| 10875 | VkPipelineObj pipe(m_device); |
| 10876 | pipe.SetInputAssembly(&iasci); |
| 10877 | pipe.SetTessellation(&tsci); |
| 10878 | pipe.AddColorAttachment(); |
| 10879 | pipe.AddShader(&vs); |
| 10880 | pipe.AddShader(&tcs); |
| 10881 | pipe.AddShader(&tes); |
| 10882 | pipe.AddShader(&fs); |
| 10883 | |
| 10884 | VkDescriptorSetObj descriptorSet(m_device); |
| 10885 | descriptorSet.AppendDummy(); |
| 10886 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10887 | |
| 10888 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10889 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10890 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 10891 | } |
| 10892 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10893 | TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) { |
| 10894 | m_errorMonitor->SetDesiredFailureMsg( |
| 10895 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10896 | "Duplicate vertex input binding descriptions for binding 0"); |
| 10897 | |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10898 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10899 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10900 | |
| 10901 | /* Two binding descriptions for binding 0 */ |
| 10902 | VkVertexInputBindingDescription input_bindings[2]; |
| 10903 | memset(input_bindings, 0, sizeof(input_bindings)); |
| 10904 | |
| 10905 | VkVertexInputAttributeDescription input_attrib; |
| 10906 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10907 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10908 | |
| 10909 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10910 | "#version 450\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10911 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10912 | "layout(location=0) in float x;\n" /* attrib provided float */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10913 | "out gl_PerVertex {\n" |
| 10914 | " vec4 gl_Position;\n" |
| 10915 | "};\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10916 | "void main(){\n" |
| 10917 | " gl_Position = vec4(x);\n" |
| 10918 | "}\n"; |
| 10919 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10920 | "#version 450\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10921 | "\n" |
| 10922 | "layout(location=0) out vec4 color;\n" |
| 10923 | "void main(){\n" |
| 10924 | " color = vec4(1);\n" |
| 10925 | "}\n"; |
| 10926 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10927 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10928 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10929 | |
| 10930 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10931 | pipe.AddColorAttachment(); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10932 | pipe.AddShader(&vs); |
| 10933 | pipe.AddShader(&fs); |
| 10934 | |
| 10935 | pipe.AddVertexInputBindings(input_bindings, 2); |
| 10936 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10937 | |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10938 | VkDescriptorSetObj descriptorSet(m_device); |
| 10939 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10940 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10941 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10942 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10943 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10944 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10945 | } |
Chris Forbes | 8f68b56 | 2015-05-25 11:13:32 +1200 | [diff] [blame] | 10946 | |
Chris Forbes | 35efec7 | 2016-04-21 14:32:08 +1200 | [diff] [blame] | 10947 | TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) { |
| 10948 | m_errorMonitor->ExpectSuccess(); |
| 10949 | |
| 10950 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10951 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10952 | |
| 10953 | if (!m_device->phy().features().tessellationShader) { |
| 10954 | printf("Device does not support 64bit vertex attributes; skipped.\n"); |
| 10955 | return; |
| 10956 | } |
| 10957 | |
| 10958 | VkVertexInputBindingDescription input_bindings[1]; |
| 10959 | memset(input_bindings, 0, sizeof(input_bindings)); |
| 10960 | |
| 10961 | VkVertexInputAttributeDescription input_attribs[4]; |
| 10962 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 10963 | input_attribs[0].location = 0; |
| 10964 | input_attribs[0].offset = 0; |
| 10965 | input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 10966 | input_attribs[1].location = 2; |
| 10967 | input_attribs[1].offset = 32; |
| 10968 | input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 10969 | input_attribs[2].location = 4; |
| 10970 | input_attribs[2].offset = 64; |
| 10971 | input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 10972 | input_attribs[3].location = 6; |
| 10973 | input_attribs[3].offset = 96; |
| 10974 | input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 10975 | |
| 10976 | char const *vsSource = |
| 10977 | "#version 450\n" |
| 10978 | "\n" |
| 10979 | "layout(location=0) in dmat4 x;\n" |
| 10980 | "out gl_PerVertex {\n" |
| 10981 | " vec4 gl_Position;\n" |
| 10982 | "};\n" |
| 10983 | "void main(){\n" |
| 10984 | " gl_Position = vec4(x[0][0]);\n" |
| 10985 | "}\n"; |
| 10986 | char const *fsSource = |
| 10987 | "#version 450\n" |
| 10988 | "\n" |
| 10989 | "layout(location=0) out vec4 color;\n" |
| 10990 | "void main(){\n" |
| 10991 | " color = vec4(1);\n" |
| 10992 | "}\n"; |
| 10993 | |
| 10994 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10995 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10996 | |
| 10997 | VkPipelineObj pipe(m_device); |
| 10998 | pipe.AddColorAttachment(); |
| 10999 | pipe.AddShader(&vs); |
| 11000 | pipe.AddShader(&fs); |
| 11001 | |
| 11002 | pipe.AddVertexInputBindings(input_bindings, 1); |
| 11003 | pipe.AddVertexInputAttribs(input_attribs, 4); |
| 11004 | |
| 11005 | VkDescriptorSetObj descriptorSet(m_device); |
| 11006 | descriptorSet.AppendDummy(); |
| 11007 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11008 | |
| 11009 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11010 | |
| 11011 | m_errorMonitor->VerifyNotFound(); |
| 11012 | } |
| 11013 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11014 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11015 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11016 | "Attachment 0 not written by FS"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11017 | |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11018 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11019 | |
| 11020 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11021 | "#version 450\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11022 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11023 | "out gl_PerVertex {\n" |
| 11024 | " vec4 gl_Position;\n" |
| 11025 | "};\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11026 | "void main(){\n" |
| 11027 | " gl_Position = vec4(1);\n" |
| 11028 | "}\n"; |
| 11029 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11030 | "#version 450\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11031 | "\n" |
| 11032 | "void main(){\n" |
| 11033 | "}\n"; |
| 11034 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11035 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11036 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11037 | |
| 11038 | VkPipelineObj pipe(m_device); |
| 11039 | pipe.AddShader(&vs); |
| 11040 | pipe.AddShader(&fs); |
| 11041 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11042 | /* set up CB 0, not written */ |
| 11043 | pipe.AddColorAttachment(); |
| 11044 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11045 | |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11046 | VkDescriptorSetObj descriptorSet(m_device); |
| 11047 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11048 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11049 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11050 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11051 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11052 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 11053 | } |
| 11054 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11055 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11056 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 11057 | VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11058 | "FS writes to output location 1 with no matching attachment"); |
| 11059 | |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11060 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11061 | |
| 11062 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11063 | "#version 450\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11064 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11065 | "out gl_PerVertex {\n" |
| 11066 | " vec4 gl_Position;\n" |
| 11067 | "};\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11068 | "void main(){\n" |
| 11069 | " gl_Position = vec4(1);\n" |
| 11070 | "}\n"; |
| 11071 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11072 | "#version 450\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11073 | "\n" |
| 11074 | "layout(location=0) out vec4 x;\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11075 | "layout(location=1) out vec4 y;\n" /* no matching attachment for this */ |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11076 | "void main(){\n" |
| 11077 | " x = vec4(1);\n" |
| 11078 | " y = vec4(1);\n" |
| 11079 | "}\n"; |
| 11080 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11081 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11082 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11083 | |
| 11084 | VkPipelineObj pipe(m_device); |
| 11085 | pipe.AddShader(&vs); |
| 11086 | pipe.AddShader(&fs); |
| 11087 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11088 | /* set up CB 0, not written */ |
| 11089 | pipe.AddColorAttachment(); |
| 11090 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11091 | /* FS writes CB 1, but we don't configure it */ |
| 11092 | |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11093 | VkDescriptorSetObj descriptorSet(m_device); |
| 11094 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11095 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11096 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11097 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11098 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11099 | m_errorMonitor->VerifyFound(); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 11100 | } |
| 11101 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11102 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11103 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11104 | "does not match FS output type"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11105 | |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11106 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11107 | |
| 11108 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11109 | "#version 450\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11110 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11111 | "out gl_PerVertex {\n" |
| 11112 | " vec4 gl_Position;\n" |
| 11113 | "};\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11114 | "void main(){\n" |
| 11115 | " gl_Position = vec4(1);\n" |
| 11116 | "}\n"; |
| 11117 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11118 | "#version 450\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11119 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11120 | "layout(location=0) out ivec4 x;\n" /* not UNORM */ |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11121 | "void main(){\n" |
| 11122 | " x = ivec4(1);\n" |
| 11123 | "}\n"; |
| 11124 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11125 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11126 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11127 | |
| 11128 | VkPipelineObj pipe(m_device); |
| 11129 | pipe.AddShader(&vs); |
| 11130 | pipe.AddShader(&fs); |
| 11131 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 11132 | /* set up CB 0; type is UNORM by default */ |
| 11133 | pipe.AddColorAttachment(); |
| 11134 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11135 | |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11136 | VkDescriptorSetObj descriptorSet(m_device); |
| 11137 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11138 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11139 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 11140 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11141 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11142 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11143 | } |
Chris Forbes | 7b1b893 | 2015-06-05 14:43:36 +1200 | [diff] [blame] | 11144 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11145 | TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 11146 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11147 | "not declared in pipeline layout"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11148 | |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11149 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11150 | |
| 11151 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11152 | "#version 450\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11153 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 11154 | "out gl_PerVertex {\n" |
| 11155 | " vec4 gl_Position;\n" |
| 11156 | "};\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11157 | "void main(){\n" |
| 11158 | " gl_Position = vec4(1);\n" |
| 11159 | "}\n"; |
| 11160 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 11161 | "#version 450\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11162 | "\n" |
| 11163 | "layout(location=0) out vec4 x;\n" |
| 11164 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 11165 | "void main(){\n" |
| 11166 | " x = vec4(bar.y);\n" |
| 11167 | "}\n"; |
| 11168 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 11169 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11170 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11171 | |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11172 | VkPipelineObj pipe(m_device); |
| 11173 | pipe.AddShader(&vs); |
| 11174 | pipe.AddShader(&fs); |
| 11175 | |
| 11176 | /* set up CB 0; type is UNORM by default */ |
| 11177 | pipe.AddColorAttachment(); |
| 11178 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11179 | |
| 11180 | VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11181 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11182 | |
| 11183 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11184 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11185 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 11186 | } |
| 11187 | |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11188 | TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) { |
| 11189 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11190 | "not declared in layout"); |
| 11191 | |
| 11192 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11193 | |
| 11194 | char const *vsSource = |
| 11195 | "#version 450\n" |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11196 | "\n" |
| 11197 | "layout(push_constant, std430) uniform foo { float x; } consts;\n" |
| 11198 | "out gl_PerVertex {\n" |
| 11199 | " vec4 gl_Position;\n" |
| 11200 | "};\n" |
| 11201 | "void main(){\n" |
| 11202 | " gl_Position = vec4(consts.x);\n" |
| 11203 | "}\n"; |
| 11204 | char const *fsSource = |
| 11205 | "#version 450\n" |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11206 | "\n" |
| 11207 | "layout(location=0) out vec4 x;\n" |
| 11208 | "void main(){\n" |
| 11209 | " x = vec4(1);\n" |
| 11210 | "}\n"; |
| 11211 | |
| 11212 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11213 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11214 | |
| 11215 | VkPipelineObj pipe(m_device); |
| 11216 | pipe.AddShader(&vs); |
| 11217 | pipe.AddShader(&fs); |
| 11218 | |
| 11219 | /* set up CB 0; type is UNORM by default */ |
| 11220 | pipe.AddColorAttachment(); |
| 11221 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11222 | |
| 11223 | VkDescriptorSetObj descriptorSet(m_device); |
| 11224 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11225 | |
| 11226 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11227 | |
| 11228 | /* should have generated an error -- no push constant ranges provided! */ |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11229 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11230 | } |
| 11231 | |
Chris Forbes | 10eb9ae | 2016-05-31 16:09:42 +1200 | [diff] [blame] | 11232 | TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) { |
| 11233 | m_errorMonitor->SetDesiredFailureMsg( |
| 11234 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11235 | "Shader uses descriptor slot 0.0"); |
| 11236 | |
| 11237 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11238 | |
| 11239 | char const *csSource = |
| 11240 | "#version 450\n" |
| 11241 | "\n" |
| 11242 | "layout(local_size_x=1) in;\n" |
| 11243 | "layout(set=0, binding=0) buffer block { vec4 x; };\n" |
| 11244 | "void main(){\n" |
| 11245 | " x = vec4(1);\n" |
| 11246 | "}\n"; |
| 11247 | |
| 11248 | VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this); |
| 11249 | |
| 11250 | VkDescriptorSetObj descriptorSet(m_device); |
| 11251 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11252 | |
| 11253 | VkComputePipelineCreateInfo cpci = { |
| 11254 | VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, |
| 11255 | nullptr, 0, { |
| 11256 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 11257 | nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, |
| 11258 | cs.handle(), "main", nullptr |
| 11259 | }, |
| 11260 | descriptorSet.GetPipelineLayout(), |
| 11261 | VK_NULL_HANDLE, -1 |
| 11262 | }; |
| 11263 | |
| 11264 | VkPipeline pipe; |
| 11265 | VkResult err = vkCreateComputePipelines( |
| 11266 | m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe); |
| 11267 | |
| 11268 | m_errorMonitor->VerifyFound(); |
| 11269 | |
| 11270 | if (err == VK_SUCCESS) { |
| 11271 | vkDestroyPipeline(m_device->device(), pipe, nullptr); |
| 11272 | } |
| 11273 | } |
| 11274 | |
| 11275 | TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) { |
| 11276 | m_errorMonitor->ExpectSuccess(); |
| 11277 | |
| 11278 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11279 | |
| 11280 | char const *csSource = |
| 11281 | "#version 450\n" |
| 11282 | "\n" |
| 11283 | "layout(local_size_x=1) in;\n" |
| 11284 | "layout(set=0, binding=0) buffer block { vec4 x; };\n" |
| 11285 | "void main(){\n" |
| 11286 | " // x is not used.\n" |
| 11287 | "}\n"; |
| 11288 | |
| 11289 | VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this); |
| 11290 | |
| 11291 | VkDescriptorSetObj descriptorSet(m_device); |
| 11292 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11293 | |
| 11294 | VkComputePipelineCreateInfo cpci = { |
| 11295 | VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, |
| 11296 | nullptr, 0, { |
| 11297 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 11298 | nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, |
| 11299 | cs.handle(), "main", nullptr |
| 11300 | }, |
| 11301 | descriptorSet.GetPipelineLayout(), |
| 11302 | VK_NULL_HANDLE, -1 |
| 11303 | }; |
| 11304 | |
| 11305 | VkPipeline pipe; |
| 11306 | VkResult err = vkCreateComputePipelines( |
| 11307 | m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe); |
| 11308 | |
| 11309 | m_errorMonitor->VerifyNotFound(); |
| 11310 | |
| 11311 | if (err == VK_SUCCESS) { |
| 11312 | vkDestroyPipeline(m_device->device(), pipe, nullptr); |
| 11313 | } |
| 11314 | } |
| 11315 | |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 11316 | #endif // SHADER_CHECKER_TESTS |
| 11317 | |
| 11318 | #if DEVICE_LIMITS_TESTS |
Mark Young | c48c4c1 | 2016-04-11 14:26:49 -0600 | [diff] [blame] | 11319 | TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11320 | m_errorMonitor->SetDesiredFailureMsg( |
| 11321 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11322 | "CreateImage extents exceed allowable limits for format"); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11323 | |
| 11324 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11325 | |
| 11326 | // Create an image |
| 11327 | VkImage image; |
| 11328 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11329 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11330 | const int32_t tex_width = 32; |
| 11331 | const int32_t tex_height = 32; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11332 | |
| 11333 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11334 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11335 | image_create_info.pNext = NULL; |
| 11336 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11337 | image_create_info.format = tex_format; |
| 11338 | image_create_info.extent.width = tex_width; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11339 | image_create_info.extent.height = tex_height; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11340 | image_create_info.extent.depth = 1; |
| 11341 | image_create_info.mipLevels = 1; |
| 11342 | image_create_info.arrayLayers = 1; |
| 11343 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11344 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11345 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 11346 | image_create_info.flags = 0; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11347 | |
| 11348 | // Introduce error by sending down a bogus width extent |
| 11349 | image_create_info.extent.width = 65536; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11350 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11351 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11352 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11353 | } |
| 11354 | |
Mark Young | c48c4c1 | 2016-04-11 14:26:49 -0600 | [diff] [blame] | 11355 | TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) { |
| 11356 | m_errorMonitor->SetDesiredFailureMsg( |
| 11357 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11358 | "CreateImage extents is 0 for at least one required dimension"); |
| 11359 | |
| 11360 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11361 | |
| 11362 | // Create an image |
| 11363 | VkImage image; |
| 11364 | |
| 11365 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11366 | const int32_t tex_width = 32; |
| 11367 | const int32_t tex_height = 32; |
| 11368 | |
| 11369 | VkImageCreateInfo image_create_info = {}; |
| 11370 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11371 | image_create_info.pNext = NULL; |
| 11372 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11373 | image_create_info.format = tex_format; |
| 11374 | image_create_info.extent.width = tex_width; |
| 11375 | image_create_info.extent.height = tex_height; |
| 11376 | image_create_info.extent.depth = 1; |
| 11377 | image_create_info.mipLevels = 1; |
| 11378 | image_create_info.arrayLayers = 1; |
| 11379 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11380 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11381 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 11382 | image_create_info.flags = 0; |
| 11383 | |
| 11384 | // Introduce error by sending down a bogus width extent |
| 11385 | image_create_info.extent.width = 0; |
| 11386 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 11387 | |
| 11388 | m_errorMonitor->VerifyFound(); |
| 11389 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 11390 | #endif // DEVICE_LIMITS_TESTS |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11391 | |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11392 | #if IMAGE_TESTS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11393 | TEST_F(VkLayerTest, InvalidImageView) { |
| 11394 | VkResult err; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11395 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11396 | m_errorMonitor->SetDesiredFailureMsg( |
| 11397 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11398 | "vkCreateImageView called with baseMipLevel 10 "); |
| 11399 | |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11400 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11401 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11402 | // Create an image and try to create a view with bad baseMipLevel |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11403 | VkImage image; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11404 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11405 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11406 | const int32_t tex_width = 32; |
| 11407 | const int32_t tex_height = 32; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11408 | |
| 11409 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11410 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11411 | image_create_info.pNext = NULL; |
| 11412 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11413 | image_create_info.format = tex_format; |
| 11414 | image_create_info.extent.width = tex_width; |
| 11415 | image_create_info.extent.height = tex_height; |
| 11416 | image_create_info.extent.depth = 1; |
| 11417 | image_create_info.mipLevels = 1; |
| 11418 | image_create_info.arrayLayers = 1; |
| 11419 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11420 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11421 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 11422 | image_create_info.flags = 0; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11423 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11424 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11425 | ASSERT_VK_SUCCESS(err); |
| 11426 | |
| 11427 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11428 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11429 | image_view_create_info.image = image; |
| 11430 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 11431 | image_view_create_info.format = tex_format; |
| 11432 | image_view_create_info.subresourceRange.layerCount = 1; |
| 11433 | image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error |
| 11434 | image_view_create_info.subresourceRange.levelCount = 1; |
| 11435 | image_view_create_info.subresourceRange.aspectMask = |
| 11436 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11437 | |
| 11438 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11439 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 11440 | &view); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11441 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11442 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 11443 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11444 | } |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11445 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11446 | TEST_F(VkLayerTest, InvalidImageViewAspect) { |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11447 | TEST_DESCRIPTION( |
| 11448 | "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] | 11449 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11450 | "vkCreateImageView: Color image " |
| 11451 | "formats must have ONLY the " |
| 11452 | "VK_IMAGE_ASPECT_COLOR_BIT set"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11453 | |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11454 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11455 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11456 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11457 | VkImageObj image(m_device); |
| 11458 | image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, |
| 11459 | VK_IMAGE_TILING_LINEAR, 0); |
| 11460 | ASSERT_TRUE(image.initialized()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11461 | |
| 11462 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11463 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11464 | image_view_create_info.image = image.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11465 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 11466 | image_view_create_info.format = tex_format; |
| 11467 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 11468 | image_view_create_info.subresourceRange.levelCount = 1; |
| 11469 | // Cause an error by setting an invalid image aspect |
| 11470 | image_view_create_info.subresourceRange.aspectMask = |
| 11471 | VK_IMAGE_ASPECT_METADATA_BIT; |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11472 | |
| 11473 | VkImageView view; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11474 | vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11475 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11476 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11477 | } |
| 11478 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11479 | TEST_F(VkLayerTest, CopyImageLayerCountMismatch) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11480 | VkResult err; |
| 11481 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11482 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11483 | m_errorMonitor->SetDesiredFailureMsg( |
| 11484 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11485 | "vkCmdCopyImage: number of layers in source and destination subresources for pRegions"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11486 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11487 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11488 | |
| 11489 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11490 | VkImage srcImage; |
| 11491 | VkImage dstImage; |
| 11492 | VkDeviceMemory srcMem; |
| 11493 | VkDeviceMemory destMem; |
| 11494 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11495 | |
| 11496 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11497 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11498 | image_create_info.pNext = NULL; |
| 11499 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11500 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11501 | image_create_info.extent.width = 32; |
| 11502 | image_create_info.extent.height = 32; |
| 11503 | image_create_info.extent.depth = 1; |
| 11504 | image_create_info.mipLevels = 1; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11505 | image_create_info.arrayLayers = 4; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11506 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11507 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 11508 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11509 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11510 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11511 | err = |
| 11512 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11513 | ASSERT_VK_SUCCESS(err); |
| 11514 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11515 | err = |
| 11516 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11517 | ASSERT_VK_SUCCESS(err); |
| 11518 | |
| 11519 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11520 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11521 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 11522 | memAlloc.pNext = NULL; |
| 11523 | memAlloc.allocationSize = 0; |
| 11524 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11525 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 11526 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11527 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11528 | pass = |
| 11529 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 11530 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11531 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11532 | ASSERT_VK_SUCCESS(err); |
| 11533 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11534 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11535 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11536 | pass = |
| 11537 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11538 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11539 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11540 | ASSERT_VK_SUCCESS(err); |
| 11541 | |
| 11542 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 11543 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11544 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11545 | ASSERT_VK_SUCCESS(err); |
| 11546 | |
| 11547 | BeginCommandBuffer(); |
| 11548 | VkImageCopy copyRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11549 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11550 | copyRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 11551 | copyRegion.srcSubresource.baseArrayLayer = 0; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11552 | copyRegion.srcSubresource.layerCount = 1; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11553 | copyRegion.srcOffset.x = 0; |
| 11554 | copyRegion.srcOffset.y = 0; |
| 11555 | copyRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11556 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11557 | copyRegion.dstSubresource.mipLevel = 0; |
| 11558 | copyRegion.dstSubresource.baseArrayLayer = 0; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11559 | // Introduce failure by forcing the dst layerCount to differ from src |
| 11560 | copyRegion.dstSubresource.layerCount = 3; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11561 | copyRegion.dstOffset.x = 0; |
| 11562 | copyRegion.dstOffset.y = 0; |
| 11563 | copyRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11564 | copyRegion.extent.width = 1; |
| 11565 | copyRegion.extent.height = 1; |
| 11566 | copyRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11567 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 11568 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11569 | EndCommandBuffer(); |
| 11570 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11571 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11572 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11573 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11574 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11575 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 11576 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11577 | } |
| 11578 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11579 | TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) { |
| 11580 | |
| 11581 | TEST_DESCRIPTION("Creating images with unsuported formats "); |
| 11582 | |
| 11583 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11584 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11585 | VkImageObj image(m_device); |
| 11586 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 11587 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 11588 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 11589 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 11590 | ASSERT_TRUE(image.initialized()); |
| 11591 | |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11592 | // Create image with unsupported format - Expect FORMAT_UNSUPPORTED |
| 11593 | VkImageCreateInfo image_create_info; |
| 11594 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11595 | image_create_info.pNext = NULL; |
| 11596 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11597 | image_create_info.format = VK_FORMAT_UNDEFINED; |
| 11598 | image_create_info.extent.width = 32; |
| 11599 | image_create_info.extent.height = 32; |
| 11600 | image_create_info.extent.depth = 1; |
| 11601 | image_create_info.mipLevels = 1; |
| 11602 | image_create_info.arrayLayers = 1; |
| 11603 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11604 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 11605 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11606 | image_create_info.flags = 0; |
| 11607 | |
| 11608 | m_errorMonitor->SetDesiredFailureMsg( |
| 11609 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11610 | "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED"); |
| 11611 | |
| 11612 | VkImage localImage; |
| 11613 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage); |
| 11614 | m_errorMonitor->VerifyFound(); |
| 11615 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11616 | VkFormat unsupported = VK_FORMAT_UNDEFINED; |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11617 | // Look for a format that is COMPLETELY unsupported with this hardware |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11618 | for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) { |
| 11619 | VkFormat format = static_cast<VkFormat>(f); |
| 11620 | VkFormatProperties fProps = m_device->format_properties(format); |
| 11621 | if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && |
| 11622 | fProps.optimalTilingFeatures == 0) { |
| 11623 | unsupported = format; |
| 11624 | break; |
| 11625 | } |
| 11626 | } |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11627 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11628 | if (unsupported != VK_FORMAT_UNDEFINED) { |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11629 | image_create_info.format = unsupported; |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11630 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11631 | "is an unsupported format"); |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11632 | |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11633 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage); |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11634 | m_errorMonitor->VerifyFound(); |
| 11635 | } |
| 11636 | } |
| 11637 | |
| 11638 | TEST_F(VkLayerTest, ImageLayerViewTests) { |
| 11639 | VkResult ret; |
| 11640 | TEST_DESCRIPTION("Passing bad parameters to CreateImageView"); |
| 11641 | |
| 11642 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11643 | |
| 11644 | VkImageObj image(m_device); |
| 11645 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 11646 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 11647 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 11648 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 11649 | ASSERT_TRUE(image.initialized()); |
| 11650 | |
| 11651 | VkImageView imgView; |
| 11652 | VkImageViewCreateInfo imgViewInfo = {}; |
| 11653 | imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 11654 | imgViewInfo.image = image.handle(); |
| 11655 | imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 11656 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11657 | imgViewInfo.subresourceRange.layerCount = 1; |
| 11658 | imgViewInfo.subresourceRange.baseMipLevel = 0; |
| 11659 | imgViewInfo.subresourceRange.levelCount = 1; |
| 11660 | imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11661 | |
| 11662 | m_errorMonitor->SetDesiredFailureMsg( |
| 11663 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11664 | "vkCreateImageView called with baseMipLevel"); |
| 11665 | // View can't have baseMipLevel >= image's mipLevels - Expect |
| 11666 | // VIEW_CREATE_ERROR |
| 11667 | imgViewInfo.subresourceRange.baseMipLevel = 1; |
| 11668 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11669 | m_errorMonitor->VerifyFound(); |
| 11670 | imgViewInfo.subresourceRange.baseMipLevel = 0; |
| 11671 | |
| 11672 | m_errorMonitor->SetDesiredFailureMsg( |
| 11673 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11674 | "vkCreateImageView called with baseArrayLayer"); |
| 11675 | // View can't have baseArrayLayer >= image's arraySize - Expect |
| 11676 | // VIEW_CREATE_ERROR |
| 11677 | imgViewInfo.subresourceRange.baseArrayLayer = 1; |
| 11678 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11679 | m_errorMonitor->VerifyFound(); |
| 11680 | imgViewInfo.subresourceRange.baseArrayLayer = 0; |
| 11681 | |
| 11682 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11683 | "vkCreateImageView called with 0 in " |
| 11684 | "pCreateInfo->subresourceRange." |
| 11685 | "levelCount"); |
| 11686 | // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR |
| 11687 | imgViewInfo.subresourceRange.levelCount = 0; |
| 11688 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11689 | m_errorMonitor->VerifyFound(); |
| 11690 | imgViewInfo.subresourceRange.levelCount = 1; |
| 11691 | |
| 11692 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11693 | "vkCreateImageView called with 0 in " |
| 11694 | "pCreateInfo->subresourceRange." |
| 11695 | "layerCount"); |
| 11696 | // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR |
| 11697 | imgViewInfo.subresourceRange.layerCount = 0; |
| 11698 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11699 | m_errorMonitor->VerifyFound(); |
| 11700 | imgViewInfo.subresourceRange.layerCount = 1; |
| 11701 | |
| 11702 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11703 | "but both must be color formats"); |
| 11704 | // Can't use depth format for view into color image - Expect INVALID_FORMAT |
| 11705 | imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 11706 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11707 | m_errorMonitor->VerifyFound(); |
| 11708 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11709 | |
| 11710 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11711 | "Formats MUST be IDENTICAL unless " |
| 11712 | "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT " |
| 11713 | "was set on image creation."); |
| 11714 | // Same compatibility class but no MUTABLE_FORMAT bit - Expect |
| 11715 | // VIEW_CREATE_ERROR |
| 11716 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT; |
| 11717 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11718 | m_errorMonitor->VerifyFound(); |
| 11719 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11720 | |
| 11721 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11722 | "can support ImageViews with " |
| 11723 | "differing formats but they must be " |
| 11724 | "in the same compatibility class."); |
| 11725 | // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect |
| 11726 | // VIEW_CREATE_ERROR |
| 11727 | VkImageCreateInfo mutImgInfo = image.create_info(); |
| 11728 | VkImage mutImage; |
| 11729 | mutImgInfo.format = VK_FORMAT_R8_UINT; |
| 11730 | assert( |
| 11731 | m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & |
| 11732 | VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT); |
| 11733 | mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; |
| 11734 | mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 11735 | ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage); |
| 11736 | ASSERT_VK_SUCCESS(ret); |
| 11737 | imgViewInfo.image = mutImage; |
| 11738 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11739 | m_errorMonitor->VerifyFound(); |
| 11740 | imgViewInfo.image = image.handle(); |
| 11741 | vkDestroyImage(m_device->handle(), mutImage, NULL); |
| 11742 | } |
| 11743 | |
| 11744 | TEST_F(VkLayerTest, MiscImageLayerTests) { |
| 11745 | |
| 11746 | TEST_DESCRIPTION("Image layer tests that don't belong elsewhare"); |
| 11747 | |
| 11748 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11749 | |
| 11750 | VkImageObj image(m_device); |
| 11751 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 11752 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 11753 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 11754 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 11755 | ASSERT_TRUE(image.initialized()); |
| 11756 | |
| 11757 | m_errorMonitor->SetDesiredFailureMsg( |
| 11758 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11759 | "number of layers in image subresource is zero"); |
| 11760 | vk_testing::Buffer buffer; |
| 11761 | VkMemoryPropertyFlags reqs = 0; |
| 11762 | buffer.init_as_src(*m_device, 128 * 128 * 4, reqs); |
| 11763 | VkBufferImageCopy region = {}; |
| 11764 | region.bufferRowLength = 128; |
| 11765 | region.bufferImageHeight = 128; |
| 11766 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11767 | // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT |
| 11768 | region.imageSubresource.layerCount = 0; |
| 11769 | region.imageExtent.height = 4; |
| 11770 | region.imageExtent.width = 4; |
| 11771 | region.imageExtent.depth = 1; |
| 11772 | m_commandBuffer->BeginCommandBuffer(); |
| 11773 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 11774 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 11775 | 1, ®ion); |
| 11776 | m_errorMonitor->VerifyFound(); |
| 11777 | region.imageSubresource.layerCount = 1; |
| 11778 | |
| 11779 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11780 | "aspectMasks for each region must " |
| 11781 | "specify only COLOR or DEPTH or " |
| 11782 | "STENCIL"); |
| 11783 | // Expect MISMATCHED_IMAGE_ASPECT |
| 11784 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT; |
| 11785 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 11786 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 11787 | 1, ®ion); |
| 11788 | m_errorMonitor->VerifyFound(); |
| 11789 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11790 | |
| 11791 | m_errorMonitor->SetDesiredFailureMsg( |
| 11792 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11793 | "If the format of srcImage is a depth, stencil, depth stencil or " |
| 11794 | "integer-based format then filter must be VK_FILTER_NEAREST"); |
| 11795 | // Expect INVALID_FILTER |
| 11796 | VkImageObj intImage1(m_device); |
| 11797 | intImage1.init(128, 128, VK_FORMAT_R8_UINT, |
| 11798 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, |
| 11799 | 0); |
| 11800 | VkImageObj intImage2(m_device); |
| 11801 | intImage2.init(128, 128, VK_FORMAT_R8_UINT, |
| 11802 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, |
| 11803 | 0); |
| 11804 | VkImageBlit blitRegion = {}; |
| 11805 | blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11806 | blitRegion.srcSubresource.baseArrayLayer = 0; |
| 11807 | blitRegion.srcSubresource.layerCount = 1; |
| 11808 | blitRegion.srcSubresource.mipLevel = 0; |
| 11809 | blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11810 | blitRegion.dstSubresource.baseArrayLayer = 0; |
| 11811 | blitRegion.dstSubresource.layerCount = 1; |
| 11812 | blitRegion.dstSubresource.mipLevel = 0; |
| 11813 | |
| 11814 | vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), |
| 11815 | intImage1.layout(), intImage2.handle(), intImage2.layout(), |
| 11816 | 16, &blitRegion, VK_FILTER_LINEAR); |
| 11817 | m_errorMonitor->VerifyFound(); |
| 11818 | |
| 11819 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11820 | "called with 0 in ppMemoryBarriers"); |
| 11821 | VkImageMemoryBarrier img_barrier; |
| 11822 | img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 11823 | img_barrier.pNext = NULL; |
| 11824 | img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 11825 | img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 11826 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 11827 | img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 11828 | img_barrier.image = image.handle(); |
| 11829 | img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 11830 | img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 11831 | img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11832 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 11833 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 11834 | // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE |
| 11835 | img_barrier.subresourceRange.layerCount = 0; |
| 11836 | img_barrier.subresourceRange.levelCount = 1; |
| 11837 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 11838 | VK_PIPELINE_STAGE_HOST_BIT, |
| 11839 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 11840 | nullptr, 1, &img_barrier); |
| 11841 | m_errorMonitor->VerifyFound(); |
| 11842 | img_barrier.subresourceRange.layerCount = 1; |
| 11843 | } |
| 11844 | |
| 11845 | TEST_F(VkLayerTest, ImageFormatLimits) { |
| 11846 | |
| 11847 | TEST_DESCRIPTION("Exceed the limits of image format "); |
| 11848 | |
| 11849 | m_errorMonitor->SetDesiredFailureMsg( |
| 11850 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11851 | "CreateImage extents exceed allowable limits for format"); |
| 11852 | VkImageCreateInfo image_create_info = {}; |
| 11853 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11854 | image_create_info.pNext = NULL; |
| 11855 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11856 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11857 | image_create_info.extent.width = 32; |
| 11858 | image_create_info.extent.height = 32; |
| 11859 | image_create_info.extent.depth = 1; |
| 11860 | image_create_info.mipLevels = 1; |
| 11861 | image_create_info.arrayLayers = 1; |
| 11862 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11863 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11864 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11865 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 11866 | image_create_info.flags = 0; |
| 11867 | |
| 11868 | VkImage nullImg; |
| 11869 | VkImageFormatProperties imgFmtProps; |
| 11870 | vkGetPhysicalDeviceImageFormatProperties( |
| 11871 | gpu(), image_create_info.format, image_create_info.imageType, |
| 11872 | image_create_info.tiling, image_create_info.usage, |
| 11873 | image_create_info.flags, &imgFmtProps); |
| 11874 | image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1; |
| 11875 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 11876 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11877 | m_errorMonitor->VerifyFound(); |
| 11878 | image_create_info.extent.depth = 1; |
| 11879 | |
| 11880 | m_errorMonitor->SetDesiredFailureMsg( |
| 11881 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11882 | "exceeds allowable maximum supported by format of"); |
| 11883 | image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1; |
| 11884 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 11885 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11886 | m_errorMonitor->VerifyFound(); |
| 11887 | image_create_info.mipLevels = 1; |
| 11888 | |
| 11889 | m_errorMonitor->SetDesiredFailureMsg( |
| 11890 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11891 | "exceeds allowable maximum supported by format of"); |
| 11892 | image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1; |
| 11893 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 11894 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11895 | m_errorMonitor->VerifyFound(); |
| 11896 | image_create_info.arrayLayers = 1; |
| 11897 | |
| 11898 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11899 | "is not supported by format"); |
| 11900 | int samples = imgFmtProps.sampleCounts >> 1; |
| 11901 | image_create_info.samples = (VkSampleCountFlagBits)samples; |
| 11902 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 11903 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11904 | m_errorMonitor->VerifyFound(); |
| 11905 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11906 | |
| 11907 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11908 | "pCreateInfo->initialLayout, must be " |
| 11909 | "VK_IMAGE_LAYOUT_UNDEFINED or " |
| 11910 | "VK_IMAGE_LAYOUT_PREINITIALIZED"); |
| 11911 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 11912 | // Expect INVALID_LAYOUT |
| 11913 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11914 | m_errorMonitor->VerifyFound(); |
| 11915 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 11916 | } |
| 11917 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11918 | TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 11919 | VkResult err; |
| 11920 | bool pass; |
| 11921 | |
| 11922 | // Create color images with different format sizes and try to copy between them |
| 11923 | m_errorMonitor->SetDesiredFailureMsg( |
| 11924 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11925 | "vkCmdCopyImage called with unmatched source and dest image format sizes"); |
| 11926 | |
| 11927 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11928 | |
| 11929 | // Create two images of different types and try to copy between them |
| 11930 | VkImage srcImage; |
| 11931 | VkImage dstImage; |
| 11932 | VkDeviceMemory srcMem; |
| 11933 | VkDeviceMemory destMem; |
| 11934 | VkMemoryRequirements memReqs; |
| 11935 | |
| 11936 | VkImageCreateInfo image_create_info = {}; |
| 11937 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11938 | image_create_info.pNext = NULL; |
| 11939 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11940 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11941 | image_create_info.extent.width = 32; |
| 11942 | image_create_info.extent.height = 32; |
| 11943 | image_create_info.extent.depth = 1; |
| 11944 | image_create_info.mipLevels = 1; |
| 11945 | image_create_info.arrayLayers = 1; |
| 11946 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11947 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11948 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11949 | image_create_info.flags = 0; |
| 11950 | |
| 11951 | err = |
| 11952 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
| 11953 | ASSERT_VK_SUCCESS(err); |
| 11954 | |
| 11955 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 11956 | // Introduce failure by creating second image with a different-sized format. |
| 11957 | image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16; |
| 11958 | |
| 11959 | err = |
| 11960 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
| 11961 | ASSERT_VK_SUCCESS(err); |
| 11962 | |
| 11963 | // Allocate memory |
| 11964 | VkMemoryAllocateInfo memAlloc = {}; |
| 11965 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 11966 | memAlloc.pNext = NULL; |
| 11967 | memAlloc.allocationSize = 0; |
| 11968 | memAlloc.memoryTypeIndex = 0; |
| 11969 | |
| 11970 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
| 11971 | memAlloc.allocationSize = memReqs.size; |
| 11972 | pass = |
| 11973 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
| 11974 | ASSERT_TRUE(pass); |
| 11975 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
| 11976 | ASSERT_VK_SUCCESS(err); |
| 11977 | |
| 11978 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
| 11979 | memAlloc.allocationSize = memReqs.size; |
| 11980 | pass = |
| 11981 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
| 11982 | ASSERT_TRUE(pass); |
| 11983 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
| 11984 | ASSERT_VK_SUCCESS(err); |
| 11985 | |
| 11986 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 11987 | ASSERT_VK_SUCCESS(err); |
| 11988 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
| 11989 | ASSERT_VK_SUCCESS(err); |
| 11990 | |
| 11991 | BeginCommandBuffer(); |
| 11992 | VkImageCopy copyRegion; |
| 11993 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11994 | copyRegion.srcSubresource.mipLevel = 0; |
| 11995 | copyRegion.srcSubresource.baseArrayLayer = 0; |
| 11996 | copyRegion.srcSubresource.layerCount = 0; |
| 11997 | copyRegion.srcOffset.x = 0; |
| 11998 | copyRegion.srcOffset.y = 0; |
| 11999 | copyRegion.srcOffset.z = 0; |
| 12000 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 12001 | copyRegion.dstSubresource.mipLevel = 0; |
| 12002 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 12003 | copyRegion.dstSubresource.layerCount = 0; |
| 12004 | copyRegion.dstOffset.x = 0; |
| 12005 | copyRegion.dstOffset.y = 0; |
| 12006 | copyRegion.dstOffset.z = 0; |
| 12007 | copyRegion.extent.width = 1; |
| 12008 | copyRegion.extent.height = 1; |
| 12009 | copyRegion.extent.depth = 1; |
| 12010 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12011 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 12012 | EndCommandBuffer(); |
| 12013 | |
| 12014 | m_errorMonitor->VerifyFound(); |
| 12015 | |
| 12016 | vkDestroyImage(m_device->device(), srcImage, NULL); |
| 12017 | vkDestroyImage(m_device->device(), dstImage, NULL); |
| 12018 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12019 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12020 | } |
| 12021 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12022 | TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) { |
| 12023 | VkResult err; |
| 12024 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12025 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12026 | // 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] | 12027 | m_errorMonitor->SetDesiredFailureMsg( |
| 12028 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12029 | "vkCmdCopyImage called with unmatched source and dest image depth"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12030 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12031 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12032 | |
| 12033 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12034 | VkImage srcImage; |
| 12035 | VkImage dstImage; |
| 12036 | VkDeviceMemory srcMem; |
| 12037 | VkDeviceMemory destMem; |
| 12038 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12039 | |
| 12040 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12041 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12042 | image_create_info.pNext = NULL; |
| 12043 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12044 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12045 | image_create_info.extent.width = 32; |
| 12046 | image_create_info.extent.height = 32; |
| 12047 | image_create_info.extent.depth = 1; |
| 12048 | image_create_info.mipLevels = 1; |
| 12049 | image_create_info.arrayLayers = 1; |
| 12050 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12051 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12052 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 12053 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12054 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12055 | err = |
| 12056 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12057 | ASSERT_VK_SUCCESS(err); |
| 12058 | |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 12059 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 12060 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12061 | // Introduce failure by creating second image with a depth/stencil format |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12062 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 12063 | image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 12064 | image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12065 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12066 | err = |
| 12067 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12068 | ASSERT_VK_SUCCESS(err); |
| 12069 | |
| 12070 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12071 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12072 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12073 | memAlloc.pNext = NULL; |
| 12074 | memAlloc.allocationSize = 0; |
| 12075 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12076 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12077 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12078 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12079 | pass = |
| 12080 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12081 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12082 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12083 | ASSERT_VK_SUCCESS(err); |
| 12084 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12085 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12086 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12087 | pass = |
| 12088 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12089 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12090 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12091 | ASSERT_VK_SUCCESS(err); |
| 12092 | |
| 12093 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12094 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12095 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12096 | ASSERT_VK_SUCCESS(err); |
| 12097 | |
| 12098 | BeginCommandBuffer(); |
| 12099 | VkImageCopy copyRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12100 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12101 | copyRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12102 | copyRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12103 | copyRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12104 | copyRegion.srcOffset.x = 0; |
| 12105 | copyRegion.srcOffset.y = 0; |
| 12106 | copyRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12107 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12108 | copyRegion.dstSubresource.mipLevel = 0; |
| 12109 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 12110 | copyRegion.dstSubresource.layerCount = 0; |
| 12111 | copyRegion.dstOffset.x = 0; |
| 12112 | copyRegion.dstOffset.y = 0; |
| 12113 | copyRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12114 | copyRegion.extent.width = 1; |
| 12115 | copyRegion.extent.height = 1; |
| 12116 | copyRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12117 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12118 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12119 | EndCommandBuffer(); |
| 12120 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12121 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12122 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12123 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12124 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12125 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12126 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12127 | } |
| 12128 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12129 | TEST_F(VkLayerTest, ResolveImageLowSampleCount) { |
| 12130 | VkResult err; |
| 12131 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12132 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12133 | m_errorMonitor->SetDesiredFailureMsg( |
| 12134 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12135 | "vkCmdResolveImage called with source sample count less than 2."); |
| 12136 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12137 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12138 | |
| 12139 | // 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] | 12140 | VkImage srcImage; |
| 12141 | VkImage dstImage; |
| 12142 | VkDeviceMemory srcMem; |
| 12143 | VkDeviceMemory destMem; |
| 12144 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12145 | |
| 12146 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12147 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12148 | image_create_info.pNext = NULL; |
| 12149 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12150 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12151 | image_create_info.extent.width = 32; |
| 12152 | image_create_info.extent.height = 1; |
| 12153 | image_create_info.extent.depth = 1; |
| 12154 | image_create_info.mipLevels = 1; |
| 12155 | image_create_info.arrayLayers = 1; |
| 12156 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12157 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12158 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 12159 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12160 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12161 | err = |
| 12162 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12163 | ASSERT_VK_SUCCESS(err); |
| 12164 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12165 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12166 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12167 | err = |
| 12168 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12169 | ASSERT_VK_SUCCESS(err); |
| 12170 | |
| 12171 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12172 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12173 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12174 | memAlloc.pNext = NULL; |
| 12175 | memAlloc.allocationSize = 0; |
| 12176 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12177 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12178 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12179 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12180 | pass = |
| 12181 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12182 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12183 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12184 | ASSERT_VK_SUCCESS(err); |
| 12185 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12186 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12187 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12188 | pass = |
| 12189 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12190 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12191 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12192 | ASSERT_VK_SUCCESS(err); |
| 12193 | |
| 12194 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12195 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12196 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12197 | ASSERT_VK_SUCCESS(err); |
| 12198 | |
| 12199 | BeginCommandBuffer(); |
| 12200 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12201 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12202 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12203 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12204 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12205 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12206 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12207 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12208 | resolveRegion.srcOffset.x = 0; |
| 12209 | resolveRegion.srcOffset.y = 0; |
| 12210 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12211 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12212 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12213 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12214 | resolveRegion.dstSubresource.layerCount = 0; |
| 12215 | resolveRegion.dstOffset.x = 0; |
| 12216 | resolveRegion.dstOffset.y = 0; |
| 12217 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12218 | resolveRegion.extent.width = 1; |
| 12219 | resolveRegion.extent.height = 1; |
| 12220 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12221 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12222 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12223 | EndCommandBuffer(); |
| 12224 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12225 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12226 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12227 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12228 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12229 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12230 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12231 | } |
| 12232 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12233 | TEST_F(VkLayerTest, ResolveImageHighSampleCount) { |
| 12234 | VkResult err; |
| 12235 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12236 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12237 | m_errorMonitor->SetDesiredFailureMsg( |
| 12238 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12239 | "vkCmdResolveImage called with dest sample count greater than 1."); |
| 12240 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12241 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12242 | |
Chris Forbes | a753069 | 2016-05-08 12:35:39 +1200 | [diff] [blame] | 12243 | // 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] | 12244 | VkImage srcImage; |
| 12245 | VkImage dstImage; |
| 12246 | VkDeviceMemory srcMem; |
| 12247 | VkDeviceMemory destMem; |
| 12248 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12249 | |
| 12250 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12251 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12252 | image_create_info.pNext = NULL; |
| 12253 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12254 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12255 | image_create_info.extent.width = 32; |
| 12256 | image_create_info.extent.height = 1; |
| 12257 | image_create_info.extent.depth = 1; |
| 12258 | image_create_info.mipLevels = 1; |
| 12259 | image_create_info.arrayLayers = 1; |
Chris Forbes | a753069 | 2016-05-08 12:35:39 +1200 | [diff] [blame] | 12260 | image_create_info.samples = VK_SAMPLE_COUNT_4_BIT; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12261 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12262 | // Note: Some implementations expect color attachment usage for any |
| 12263 | // multisample surface |
| 12264 | image_create_info.usage = |
| 12265 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12266 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12267 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12268 | err = |
| 12269 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12270 | ASSERT_VK_SUCCESS(err); |
| 12271 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12272 | // Note: Some implementations expect color attachment usage for any |
| 12273 | // multisample surface |
| 12274 | image_create_info.usage = |
| 12275 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12276 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12277 | err = |
| 12278 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12279 | ASSERT_VK_SUCCESS(err); |
| 12280 | |
| 12281 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12282 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12283 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12284 | memAlloc.pNext = NULL; |
| 12285 | memAlloc.allocationSize = 0; |
| 12286 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12287 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12288 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12289 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12290 | pass = |
| 12291 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12292 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12293 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12294 | ASSERT_VK_SUCCESS(err); |
| 12295 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12296 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12297 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12298 | pass = |
| 12299 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12300 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12301 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12302 | ASSERT_VK_SUCCESS(err); |
| 12303 | |
| 12304 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12305 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12306 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12307 | ASSERT_VK_SUCCESS(err); |
| 12308 | |
| 12309 | BeginCommandBuffer(); |
| 12310 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12311 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12312 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12313 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12314 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12315 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12316 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12317 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12318 | resolveRegion.srcOffset.x = 0; |
| 12319 | resolveRegion.srcOffset.y = 0; |
| 12320 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12321 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12322 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12323 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12324 | resolveRegion.dstSubresource.layerCount = 0; |
| 12325 | resolveRegion.dstOffset.x = 0; |
| 12326 | resolveRegion.dstOffset.y = 0; |
| 12327 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12328 | resolveRegion.extent.width = 1; |
| 12329 | resolveRegion.extent.height = 1; |
| 12330 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12331 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12332 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12333 | EndCommandBuffer(); |
| 12334 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12335 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12336 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12337 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12338 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12339 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12340 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12341 | } |
| 12342 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12343 | TEST_F(VkLayerTest, ResolveImageFormatMismatch) { |
| 12344 | VkResult err; |
| 12345 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12346 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12347 | m_errorMonitor->SetDesiredFailureMsg( |
| 12348 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12349 | "vkCmdResolveImage called with unmatched source and dest formats."); |
| 12350 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12351 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12352 | |
| 12353 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12354 | VkImage srcImage; |
| 12355 | VkImage dstImage; |
| 12356 | VkDeviceMemory srcMem; |
| 12357 | VkDeviceMemory destMem; |
| 12358 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12359 | |
| 12360 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12361 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12362 | image_create_info.pNext = NULL; |
| 12363 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12364 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12365 | image_create_info.extent.width = 32; |
| 12366 | image_create_info.extent.height = 1; |
| 12367 | image_create_info.extent.depth = 1; |
| 12368 | image_create_info.mipLevels = 1; |
| 12369 | image_create_info.arrayLayers = 1; |
| 12370 | image_create_info.samples = VK_SAMPLE_COUNT_2_BIT; |
| 12371 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12372 | // Note: Some implementations expect color attachment usage for any |
| 12373 | // multisample surface |
| 12374 | image_create_info.usage = |
| 12375 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12376 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12377 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12378 | err = |
| 12379 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12380 | ASSERT_VK_SUCCESS(err); |
| 12381 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12382 | // Set format to something other than source image |
| 12383 | image_create_info.format = VK_FORMAT_R32_SFLOAT; |
| 12384 | // Note: Some implementations expect color attachment usage for any |
| 12385 | // multisample surface |
| 12386 | image_create_info.usage = |
| 12387 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12388 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12389 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12390 | err = |
| 12391 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12392 | ASSERT_VK_SUCCESS(err); |
| 12393 | |
| 12394 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12395 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12396 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12397 | memAlloc.pNext = NULL; |
| 12398 | memAlloc.allocationSize = 0; |
| 12399 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12400 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12401 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12402 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12403 | pass = |
| 12404 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12405 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12406 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12407 | ASSERT_VK_SUCCESS(err); |
| 12408 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12409 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12410 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12411 | pass = |
| 12412 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12413 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12414 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12415 | ASSERT_VK_SUCCESS(err); |
| 12416 | |
| 12417 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12418 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12419 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12420 | ASSERT_VK_SUCCESS(err); |
| 12421 | |
| 12422 | BeginCommandBuffer(); |
| 12423 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12424 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12425 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12426 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12427 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12428 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12429 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12430 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12431 | resolveRegion.srcOffset.x = 0; |
| 12432 | resolveRegion.srcOffset.y = 0; |
| 12433 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12434 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12435 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12436 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12437 | resolveRegion.dstSubresource.layerCount = 0; |
| 12438 | resolveRegion.dstOffset.x = 0; |
| 12439 | resolveRegion.dstOffset.y = 0; |
| 12440 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12441 | resolveRegion.extent.width = 1; |
| 12442 | resolveRegion.extent.height = 1; |
| 12443 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12444 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12445 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12446 | EndCommandBuffer(); |
| 12447 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12448 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12449 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12450 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12451 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12452 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12453 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12454 | } |
| 12455 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12456 | TEST_F(VkLayerTest, ResolveImageTypeMismatch) { |
| 12457 | VkResult err; |
| 12458 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12459 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12460 | m_errorMonitor->SetDesiredFailureMsg( |
| 12461 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12462 | "vkCmdResolveImage called with unmatched source and dest image types."); |
| 12463 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12464 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12465 | |
| 12466 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12467 | VkImage srcImage; |
| 12468 | VkImage dstImage; |
| 12469 | VkDeviceMemory srcMem; |
| 12470 | VkDeviceMemory destMem; |
| 12471 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12472 | |
| 12473 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12474 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12475 | image_create_info.pNext = NULL; |
| 12476 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12477 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12478 | image_create_info.extent.width = 32; |
| 12479 | image_create_info.extent.height = 1; |
| 12480 | image_create_info.extent.depth = 1; |
| 12481 | image_create_info.mipLevels = 1; |
| 12482 | image_create_info.arrayLayers = 1; |
| 12483 | image_create_info.samples = VK_SAMPLE_COUNT_2_BIT; |
| 12484 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12485 | // Note: Some implementations expect color attachment usage for any |
| 12486 | // multisample surface |
| 12487 | image_create_info.usage = |
| 12488 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12489 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12490 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12491 | err = |
| 12492 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12493 | ASSERT_VK_SUCCESS(err); |
| 12494 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12495 | image_create_info.imageType = VK_IMAGE_TYPE_1D; |
| 12496 | // Note: Some implementations expect color attachment usage for any |
| 12497 | // multisample surface |
| 12498 | image_create_info.usage = |
| 12499 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12500 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12501 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12502 | err = |
| 12503 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12504 | ASSERT_VK_SUCCESS(err); |
| 12505 | |
| 12506 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12507 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12508 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12509 | memAlloc.pNext = NULL; |
| 12510 | memAlloc.allocationSize = 0; |
| 12511 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12512 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12513 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12514 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12515 | pass = |
| 12516 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12517 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12518 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12519 | ASSERT_VK_SUCCESS(err); |
| 12520 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12521 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12522 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12523 | pass = |
| 12524 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12525 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12526 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12527 | ASSERT_VK_SUCCESS(err); |
| 12528 | |
| 12529 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12530 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12531 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12532 | ASSERT_VK_SUCCESS(err); |
| 12533 | |
| 12534 | BeginCommandBuffer(); |
| 12535 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12536 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12537 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12538 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12539 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12540 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12541 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12542 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12543 | resolveRegion.srcOffset.x = 0; |
| 12544 | resolveRegion.srcOffset.y = 0; |
| 12545 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12546 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12547 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12548 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12549 | resolveRegion.dstSubresource.layerCount = 0; |
| 12550 | resolveRegion.dstOffset.x = 0; |
| 12551 | resolveRegion.dstOffset.y = 0; |
| 12552 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12553 | resolveRegion.extent.width = 1; |
| 12554 | resolveRegion.extent.height = 1; |
| 12555 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12556 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12557 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12558 | EndCommandBuffer(); |
| 12559 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12560 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12561 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12562 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12563 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12564 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12565 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12566 | } |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12567 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12568 | TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) { |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12569 | // 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] | 12570 | // to using a DS format, then cause it to hit error due to COLOR_BIT not |
| 12571 | // set in aspect |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12572 | // The image format check comes 2nd in validation so we trigger it first, |
| 12573 | // 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] | 12574 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12575 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12576 | m_errorMonitor->SetDesiredFailureMsg( |
| 12577 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12578 | "Combination depth/stencil image formats can have only the "); |
| 12579 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12580 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12581 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 12582 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12583 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 12584 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12585 | |
| 12586 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12587 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 12588 | ds_pool_ci.pNext = NULL; |
| 12589 | ds_pool_ci.maxSets = 1; |
| 12590 | ds_pool_ci.poolSizeCount = 1; |
| 12591 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12592 | |
| 12593 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12594 | err = |
| 12595 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12596 | ASSERT_VK_SUCCESS(err); |
| 12597 | |
| 12598 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12599 | dsl_binding.binding = 0; |
| 12600 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 12601 | dsl_binding.descriptorCount = 1; |
| 12602 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 12603 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12604 | |
| 12605 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12606 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 12607 | ds_layout_ci.pNext = NULL; |
| 12608 | ds_layout_ci.bindingCount = 1; |
| 12609 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12610 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12611 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 12612 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12613 | ASSERT_VK_SUCCESS(err); |
| 12614 | |
| 12615 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12616 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 12617 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 12618 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12619 | alloc_info.descriptorPool = ds_pool; |
| 12620 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12621 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 12622 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12623 | ASSERT_VK_SUCCESS(err); |
| 12624 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12625 | VkImage image_bad; |
| 12626 | VkImage image_good; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12627 | // One bad format and one good format for Color attachment |
Tobin Ehlis | 269f032 | 2016-05-25 16:24:21 -0600 | [diff] [blame] | 12628 | const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12629 | const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12630 | const int32_t tex_width = 32; |
| 12631 | const int32_t tex_height = 32; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12632 | |
| 12633 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12634 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12635 | image_create_info.pNext = NULL; |
| 12636 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12637 | image_create_info.format = tex_format_bad; |
| 12638 | image_create_info.extent.width = tex_width; |
| 12639 | image_create_info.extent.height = tex_height; |
| 12640 | image_create_info.extent.depth = 1; |
| 12641 | image_create_info.mipLevels = 1; |
| 12642 | image_create_info.arrayLayers = 1; |
| 12643 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12644 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12645 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | |
| 12646 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 12647 | image_create_info.flags = 0; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12648 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12649 | err = |
| 12650 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12651 | ASSERT_VK_SUCCESS(err); |
| 12652 | image_create_info.format = tex_format_good; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12653 | image_create_info.usage = |
| 12654 | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12655 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, |
| 12656 | &image_good); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12657 | ASSERT_VK_SUCCESS(err); |
| 12658 | |
| 12659 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12660 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12661 | image_view_create_info.image = image_bad; |
| 12662 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 12663 | image_view_create_info.format = tex_format_bad; |
| 12664 | image_view_create_info.subresourceRange.baseArrayLayer = 0; |
| 12665 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 12666 | image_view_create_info.subresourceRange.layerCount = 1; |
| 12667 | image_view_create_info.subresourceRange.levelCount = 1; |
| 12668 | image_view_create_info.subresourceRange.aspectMask = |
| 12669 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12670 | |
| 12671 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12672 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 12673 | &view); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12674 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12675 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12676 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12677 | vkDestroyImage(m_device->device(), image_bad, NULL); |
| 12678 | vkDestroyImage(m_device->device(), image_good, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12679 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 12680 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12681 | } |
Tobin Ehlis | 6e23d77 | 2016-05-19 11:08:34 -0600 | [diff] [blame] | 12682 | |
| 12683 | TEST_F(VkLayerTest, ClearImageErrors) { |
| 12684 | TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and " |
| 12685 | "ClearDepthStencilImage with a color image."); |
| 12686 | |
| 12687 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12688 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 12689 | |
| 12690 | // Renderpass is started here so end it as Clear cmds can't be in renderpass |
| 12691 | BeginCommandBuffer(); |
| 12692 | m_commandBuffer->EndRenderPass(); |
| 12693 | |
| 12694 | // Color image |
| 12695 | VkClearColorValue clear_color; |
| 12696 | memset(clear_color.uint32, 0, sizeof(uint32_t) * 4); |
| 12697 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 12698 | const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12699 | const int32_t img_width = 32; |
| 12700 | const int32_t img_height = 32; |
| 12701 | VkImageCreateInfo image_create_info = {}; |
| 12702 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12703 | image_create_info.pNext = NULL; |
| 12704 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12705 | image_create_info.format = color_format; |
| 12706 | image_create_info.extent.width = img_width; |
| 12707 | image_create_info.extent.height = img_height; |
| 12708 | image_create_info.extent.depth = 1; |
| 12709 | image_create_info.mipLevels = 1; |
| 12710 | image_create_info.arrayLayers = 1; |
| 12711 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12712 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12713 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 12714 | |
| 12715 | vk_testing::Image color_image; |
| 12716 | color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 12717 | reqs); |
| 12718 | |
| 12719 | const VkImageSubresourceRange color_range = |
| 12720 | vk_testing::Image::subresource_range(image_create_info, |
| 12721 | VK_IMAGE_ASPECT_COLOR_BIT); |
| 12722 | |
| 12723 | // Depth/Stencil image |
| 12724 | VkClearDepthStencilValue clear_value = {0}; |
| 12725 | reqs = 0; // don't need HOST_VISIBLE DS image |
| 12726 | VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info(); |
| 12727 | ds_image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12728 | ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 12729 | ds_image_create_info.extent.width = 64; |
| 12730 | ds_image_create_info.extent.height = 64; |
| 12731 | ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12732 | ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 12733 | |
| 12734 | vk_testing::Image ds_image; |
| 12735 | ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, |
| 12736 | reqs); |
| 12737 | |
| 12738 | const VkImageSubresourceRange ds_range = |
| 12739 | vk_testing::Image::subresource_range(ds_image_create_info, |
| 12740 | VK_IMAGE_ASPECT_DEPTH_BIT); |
| 12741 | |
| 12742 | m_errorMonitor->SetDesiredFailureMsg( |
| 12743 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12744 | "vkCmdClearColorImage called with depth/stencil image."); |
| 12745 | |
| 12746 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), |
| 12747 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, |
| 12748 | &color_range); |
| 12749 | |
| 12750 | m_errorMonitor->VerifyFound(); |
| 12751 | |
Tony Barbour | 26434b9 | 2016-06-02 09:43:50 -0600 | [diff] [blame] | 12752 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12753 | "vkCmdClearColorImage called with " |
| 12754 | "image created without " |
| 12755 | "VK_IMAGE_USAGE_TRANSFER_DST_BIT"); |
| 12756 | |
| 12757 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), |
| 12758 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, |
| 12759 | &color_range); |
| 12760 | |
| 12761 | m_errorMonitor->VerifyFound(); |
| 12762 | |
Tobin Ehlis | 6e23d77 | 2016-05-19 11:08:34 -0600 | [diff] [blame] | 12763 | // Call CmdClearDepthStencilImage with color image |
| 12764 | m_errorMonitor->SetDesiredFailureMsg( |
| 12765 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12766 | "vkCmdClearDepthStencilImage called without a depth/stencil image."); |
| 12767 | |
| 12768 | vkCmdClearDepthStencilImage( |
| 12769 | m_commandBuffer->GetBufferHandle(), color_image.handle(), |
| 12770 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, |
| 12771 | &ds_range); |
| 12772 | |
| 12773 | m_errorMonitor->VerifyFound(); |
| 12774 | } |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12775 | #endif // IMAGE_TESTS |
| 12776 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 12777 | int main(int argc, char **argv) { |
| 12778 | int result; |
| 12779 | |
Cody Northrop | 8e54a40 | 2016-03-08 22:25:52 -0700 | [diff] [blame] | 12780 | #ifdef ANDROID |
| 12781 | int vulkanSupport = InitVulkan(); |
| 12782 | if (vulkanSupport == 0) |
| 12783 | return 1; |
| 12784 | #endif |
| 12785 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 12786 | ::testing::InitGoogleTest(&argc, argv); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 12787 | VkTestFramework::InitArgs(&argc, argv); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 12788 | |
| 12789 | ::testing::AddGlobalTestEnvironment(new TestEnvironment); |
| 12790 | |
| 12791 | result = RUN_ALL_TESTS(); |
| 12792 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 12793 | VkTestFramework::Finish(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 12794 | return result; |
| 12795 | } |