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 | } |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [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 | |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2414 | TEST_F(VkLayerTest, InvalidUsageBits) |
| 2415 | { |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2416 | TEST_DESCRIPTION( |
Karl Schultz | b5bc11e | 2016-05-04 08:36:08 -0600 | [diff] [blame] | 2417 | "Specify wrong usage for image then create conflicting view of image " |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2418 | "Initialize buffer with wrong usage then perform copy expecting errors " |
| 2419 | "from both the image and the buffer (2 calls)"); |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2420 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2421 | "Invalid usage flag for image "); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2422 | |
| 2423 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2424 | VkImageObj image(m_device); |
| 2425 | // Initialize image with USAGE_INPUT_ATTACHMENT |
Tobin Ehlis | 8b313c0 | 2016-05-25 15:01:52 -0600 | [diff] [blame] | 2426 | image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, |
Karl Schultz | b5bc11e | 2016-05-04 08:36:08 -0600 | [diff] [blame] | 2427 | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 2428 | ASSERT_TRUE(image.initialized()); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2429 | |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2430 | VkImageView dsv; |
| 2431 | VkImageViewCreateInfo dsvci = {}; |
| 2432 | dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 2433 | dsvci.image = image.handle(); |
| 2434 | dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 2435 | dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT; |
| 2436 | dsvci.subresourceRange.layerCount = 1; |
| 2437 | dsvci.subresourceRange.baseMipLevel = 0; |
| 2438 | dsvci.subresourceRange.levelCount = 1; |
| 2439 | dsvci.subresourceRange.aspectMask = |
| 2440 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2441 | |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2442 | // Create a view with depth / stencil aspect for image with different usage |
| 2443 | vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2444 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2445 | m_errorMonitor->VerifyFound(); |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2446 | |
| 2447 | // Initialize buffer with TRANSFER_DST usage |
| 2448 | vk_testing::Buffer buffer; |
| 2449 | VkMemoryPropertyFlags reqs = 0; |
| 2450 | buffer.init_as_dst(*m_device, 128 * 128, reqs); |
| 2451 | VkBufferImageCopy region = {}; |
| 2452 | region.bufferRowLength = 128; |
| 2453 | region.bufferImageHeight = 128; |
| 2454 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 2455 | region.imageSubresource.layerCount = 1; |
| 2456 | region.imageExtent.height = 16; |
| 2457 | region.imageExtent.width = 16; |
| 2458 | region.imageExtent.depth = 1; |
| 2459 | |
| 2460 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2461 | "Invalid usage flag for buffer "); |
| 2462 | // Buffer usage not set to TRANSFER_SRC and image usage not set to |
| 2463 | // TRANSFER_DST |
| 2464 | BeginCommandBuffer(); |
| 2465 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 2466 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 2467 | 1, ®ion); |
| 2468 | m_errorMonitor->VerifyFound(); |
| 2469 | |
| 2470 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2471 | "Invalid usage flag for image "); |
| 2472 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 2473 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 2474 | 1, ®ion); |
| 2475 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2476 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 2477 | #endif // MEM_TRACKER_TESTS |
| 2478 | |
Tobin Ehlis | 4bf96d1 | 2015-06-25 11:58:41 -0600 | [diff] [blame] | 2479 | #if OBJ_TRACKER_TESTS |
Mark Lobodzinski | fc5cc66 | 2016-05-02 17:17:41 -0600 | [diff] [blame] | 2480 | |
| 2481 | TEST_F(VkLayerTest, LeakAnObject) { |
| 2482 | VkResult err; |
| 2483 | |
| 2484 | TEST_DESCRIPTION( |
| 2485 | "Create a fence and destroy its device without first destroying the fence."); |
| 2486 | |
| 2487 | // Note that we have to create a new device since destroying the |
| 2488 | // framework's device causes Teardown() to fail and just calling Teardown |
| 2489 | // will destroy the errorMonitor. |
| 2490 | |
| 2491 | m_errorMonitor->SetDesiredFailureMsg( |
| 2492 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2493 | "OBJ ERROR : VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT object"); |
| 2494 | |
| 2495 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2496 | |
| 2497 | const std::vector<VkQueueFamilyProperties> queue_props = |
| 2498 | m_device->queue_props; |
| 2499 | std::vector<VkDeviceQueueCreateInfo> queue_info; |
| 2500 | queue_info.reserve(queue_props.size()); |
| 2501 | std::vector<std::vector<float>> queue_priorities; |
| 2502 | for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) { |
| 2503 | VkDeviceQueueCreateInfo qi = {}; |
| 2504 | qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; |
| 2505 | qi.pNext = NULL; |
| 2506 | qi.queueFamilyIndex = i; |
| 2507 | qi.queueCount = queue_props[i].queueCount; |
| 2508 | queue_priorities.emplace_back(qi.queueCount, 0.0f); |
| 2509 | qi.pQueuePriorities = queue_priorities[i].data(); |
| 2510 | queue_info.push_back(qi); |
| 2511 | } |
| 2512 | |
| 2513 | std::vector<const char *> device_layer_names; |
| 2514 | std::vector<const char *> device_extension_names; |
| 2515 | device_layer_names.push_back("VK_LAYER_GOOGLE_threading"); |
| 2516 | device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation"); |
| 2517 | device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker"); |
| 2518 | device_layer_names.push_back("VK_LAYER_LUNARG_core_validation"); |
| 2519 | device_layer_names.push_back("VK_LAYER_LUNARG_device_limits"); |
| 2520 | device_layer_names.push_back("VK_LAYER_LUNARG_image"); |
| 2521 | device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects"); |
| 2522 | |
| 2523 | // The sacrificial device object |
| 2524 | VkDevice testDevice; |
| 2525 | VkDeviceCreateInfo device_create_info = {}; |
| 2526 | auto features = m_device->phy().features(); |
| 2527 | device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; |
| 2528 | device_create_info.pNext = NULL; |
| 2529 | device_create_info.queueCreateInfoCount = queue_info.size(); |
| 2530 | device_create_info.pQueueCreateInfos = queue_info.data(); |
| 2531 | device_create_info.enabledLayerCount = device_layer_names.size(); |
| 2532 | device_create_info.ppEnabledLayerNames = device_layer_names.data(); |
| 2533 | device_create_info.pEnabledFeatures = &features; |
| 2534 | err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice); |
| 2535 | ASSERT_VK_SUCCESS(err); |
| 2536 | |
| 2537 | VkFence fence; |
| 2538 | VkFenceCreateInfo fence_create_info = {}; |
| 2539 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 2540 | fence_create_info.pNext = NULL; |
| 2541 | fence_create_info.flags = 0; |
| 2542 | err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence); |
| 2543 | ASSERT_VK_SUCCESS(err); |
| 2544 | |
| 2545 | // Induce failure by not calling vkDestroyFence |
| 2546 | vkDestroyDevice(testDevice, NULL); |
| 2547 | m_errorMonitor->VerifyFound(); |
| 2548 | } |
| 2549 | |
| 2550 | TEST_F(VkLayerTest, InvalidCommandPoolConsistency) { |
| 2551 | |
| 2552 | TEST_DESCRIPTION("Allocate command buffers from one command pool and " |
| 2553 | "attempt to delete them from another."); |
| 2554 | |
| 2555 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2556 | "FreeCommandBuffers is attempting to free Command Buffer"); |
| 2557 | |
| 2558 | VkCommandPool command_pool_one; |
| 2559 | VkCommandPool command_pool_two; |
| 2560 | |
| 2561 | VkCommandPoolCreateInfo pool_create_info{}; |
| 2562 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 2563 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 2564 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 2565 | |
| 2566 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 2567 | &command_pool_one); |
| 2568 | |
| 2569 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 2570 | &command_pool_two); |
| 2571 | |
| 2572 | VkCommandBuffer command_buffer[9]; |
| 2573 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 2574 | command_buffer_allocate_info.sType = |
| 2575 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 2576 | command_buffer_allocate_info.commandPool = command_pool_one; |
| 2577 | command_buffer_allocate_info.commandBufferCount = 9; |
| 2578 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 2579 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 2580 | command_buffer); |
| 2581 | |
| 2582 | vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, |
| 2583 | &command_buffer[3]); |
| 2584 | |
| 2585 | m_errorMonitor->VerifyFound(); |
| 2586 | |
| 2587 | vkDestroyCommandPool(m_device->device(), command_pool_one, NULL); |
| 2588 | vkDestroyCommandPool(m_device->device(), command_pool_two, NULL); |
| 2589 | } |
| 2590 | |
| 2591 | TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) { |
| 2592 | VkResult err; |
| 2593 | |
| 2594 | TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and " |
| 2595 | "attempt to delete them from another."); |
| 2596 | |
| 2597 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2598 | "FreeDescriptorSets is attempting to free descriptorSet"); |
| 2599 | |
| 2600 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2601 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 2602 | |
| 2603 | VkDescriptorPoolSize ds_type_count = {}; |
| 2604 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 2605 | ds_type_count.descriptorCount = 1; |
| 2606 | |
| 2607 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 2608 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 2609 | ds_pool_ci.pNext = NULL; |
| 2610 | ds_pool_ci.flags = 0; |
| 2611 | ds_pool_ci.maxSets = 1; |
| 2612 | ds_pool_ci.poolSizeCount = 1; |
| 2613 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 2614 | |
| 2615 | VkDescriptorPool ds_pool_one; |
| 2616 | err = |
| 2617 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one); |
| 2618 | ASSERT_VK_SUCCESS(err); |
| 2619 | |
| 2620 | // Create a second descriptor pool |
| 2621 | VkDescriptorPool ds_pool_two; |
| 2622 | err = |
| 2623 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two); |
| 2624 | ASSERT_VK_SUCCESS(err); |
| 2625 | |
| 2626 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 2627 | dsl_binding.binding = 0; |
| 2628 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 2629 | dsl_binding.descriptorCount = 1; |
| 2630 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 2631 | dsl_binding.pImmutableSamplers = NULL; |
| 2632 | |
| 2633 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 2634 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 2635 | ds_layout_ci.pNext = NULL; |
| 2636 | ds_layout_ci.bindingCount = 1; |
| 2637 | ds_layout_ci.pBindings = &dsl_binding; |
| 2638 | |
| 2639 | VkDescriptorSetLayout ds_layout; |
| 2640 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 2641 | &ds_layout); |
| 2642 | ASSERT_VK_SUCCESS(err); |
| 2643 | |
| 2644 | VkDescriptorSet descriptorSet; |
| 2645 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 2646 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 2647 | alloc_info.descriptorSetCount = 1; |
| 2648 | alloc_info.descriptorPool = ds_pool_one; |
| 2649 | alloc_info.pSetLayouts = &ds_layout; |
| 2650 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 2651 | &descriptorSet); |
| 2652 | ASSERT_VK_SUCCESS(err); |
| 2653 | |
| 2654 | err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet); |
| 2655 | |
| 2656 | m_errorMonitor->VerifyFound(); |
| 2657 | |
| 2658 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 2659 | vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL); |
| 2660 | vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL); |
| 2661 | } |
| 2662 | |
| 2663 | TEST_F(VkLayerTest, CreateUnknownObject) { |
| 2664 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2665 | "Invalid VkImage Object "); |
| 2666 | |
| 2667 | TEST_DESCRIPTION( |
| 2668 | "Pass an invalid image object handle into a Vulkan API call."); |
| 2669 | |
| 2670 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2671 | |
| 2672 | // Pass bogus handle into GetImageMemoryRequirements |
| 2673 | VkMemoryRequirements mem_reqs; |
| 2674 | uint64_t fakeImageHandle = 0xCADECADE; |
| 2675 | VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle); |
| 2676 | |
| 2677 | vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs); |
| 2678 | |
| 2679 | m_errorMonitor->VerifyFound(); |
| 2680 | } |
| 2681 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2682 | TEST_F(VkLayerTest, PipelineNotBound) { |
| 2683 | VkResult err; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2684 | |
Mark Lobodzinski | fc5cc66 | 2016-05-02 17:17:41 -0600 | [diff] [blame] | 2685 | TEST_DESCRIPTION( |
| 2686 | "Pass in an invalid pipeline object handle into a Vulkan API call."); |
| 2687 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2688 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2689 | "Invalid VkPipeline Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2690 | |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2691 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2692 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2693 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 2694 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2695 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 2696 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2697 | |
| 2698 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2699 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 2700 | ds_pool_ci.pNext = NULL; |
| 2701 | ds_pool_ci.maxSets = 1; |
| 2702 | ds_pool_ci.poolSizeCount = 1; |
| 2703 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2704 | |
| 2705 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2706 | err = |
| 2707 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2708 | ASSERT_VK_SUCCESS(err); |
| 2709 | |
| 2710 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2711 | dsl_binding.binding = 0; |
| 2712 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 2713 | dsl_binding.descriptorCount = 1; |
| 2714 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 2715 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2716 | |
| 2717 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2718 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 2719 | ds_layout_ci.pNext = NULL; |
| 2720 | ds_layout_ci.bindingCount = 1; |
| 2721 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2722 | |
| 2723 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2724 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 2725 | &ds_layout); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2726 | ASSERT_VK_SUCCESS(err); |
| 2727 | |
| 2728 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2729 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 2730 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 2731 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 2732 | alloc_info.descriptorPool = ds_pool; |
| 2733 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2734 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 2735 | &descriptorSet); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2736 | ASSERT_VK_SUCCESS(err); |
| 2737 | |
| 2738 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2739 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 2740 | pipeline_layout_ci.pNext = NULL; |
| 2741 | pipeline_layout_ci.setLayoutCount = 1; |
| 2742 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2743 | |
| 2744 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2745 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 2746 | &pipeline_layout); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2747 | ASSERT_VK_SUCCESS(err); |
| 2748 | |
Mark Young | ad77905 | 2016-01-06 14:26:04 -0700 | [diff] [blame] | 2749 | VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2750 | |
| 2751 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2752 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 2753 | VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2754 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2755 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2756 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2757 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 2758 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 2759 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2760 | } |
Tobin Ehlis | 93d57e1 | 2016-06-20 11:32:13 -0600 | [diff] [blame] | 2761 | #if 0 // Disabling this test for now, needs to be updated |
Mark Lobodzinski | bc18576 | 2016-06-15 16:28:53 -0600 | [diff] [blame] | 2762 | TEST_F(VkLayerTest, BindImageInvalidMemoryType) { |
| 2763 | VkResult err; |
| 2764 | |
| 2765 | TEST_DESCRIPTION("Test validation check for an invalid memory type index " |
| 2766 | "during bind[Buffer|Image]Memory time"); |
| 2767 | |
| 2768 | m_errorMonitor->SetDesiredFailureMsg( |
| 2769 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2770 | "for this object type are not compatible with the memory"); |
| 2771 | |
| 2772 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2773 | |
| 2774 | // Create an image, allocate memory, set a bad typeIndex and then try to |
| 2775 | // bind it |
| 2776 | VkImage image; |
| 2777 | VkDeviceMemory mem; |
| 2778 | VkMemoryRequirements mem_reqs; |
| 2779 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2780 | const int32_t tex_width = 32; |
| 2781 | const int32_t tex_height = 32; |
| 2782 | |
| 2783 | VkImageCreateInfo image_create_info = {}; |
| 2784 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2785 | image_create_info.pNext = NULL; |
| 2786 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2787 | image_create_info.format = tex_format; |
| 2788 | image_create_info.extent.width = tex_width; |
| 2789 | image_create_info.extent.height = tex_height; |
| 2790 | image_create_info.extent.depth = 1; |
| 2791 | image_create_info.mipLevels = 1; |
| 2792 | image_create_info.arrayLayers = 1; |
| 2793 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2794 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 2795 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2796 | image_create_info.flags = 0; |
| 2797 | |
| 2798 | VkMemoryAllocateInfo mem_alloc = {}; |
| 2799 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2800 | mem_alloc.pNext = NULL; |
| 2801 | mem_alloc.allocationSize = 0; |
| 2802 | mem_alloc.memoryTypeIndex = 0; |
| 2803 | |
| 2804 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 2805 | ASSERT_VK_SUCCESS(err); |
| 2806 | |
| 2807 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 2808 | mem_alloc.allocationSize = mem_reqs.size; |
Tobin Ehlis | 93d57e1 | 2016-06-20 11:32:13 -0600 | [diff] [blame] | 2809 | // TODO : This is not an ideal way to cause the error and triggers a segF |
| 2810 | // on at least one android driver when attempting to Allocate the memory. |
| 2811 | // That segF may or may not be a driver bug, but really what we want to do |
| 2812 | // here is find a device-supported memory type that is also not supported |
| 2813 | // for the particular image we're binding the memory too. If no such |
| 2814 | // type exists, then we can print a message and skip the test. |
Mark Lobodzinski | bc18576 | 2016-06-15 16:28:53 -0600 | [diff] [blame] | 2815 | // Introduce Failure, select likely invalid TypeIndex |
| 2816 | mem_alloc.memoryTypeIndex = 31; |
| 2817 | |
| 2818 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 2819 | ASSERT_VK_SUCCESS(err); |
| 2820 | |
| 2821 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 2822 | (void)err; |
| 2823 | |
| 2824 | m_errorMonitor->VerifyFound(); |
| 2825 | |
| 2826 | vkDestroyImage(m_device->device(), image, NULL); |
| 2827 | vkFreeMemory(m_device->device(), mem, NULL); |
| 2828 | } |
Tobin Ehlis | 93d57e1 | 2016-06-20 11:32:13 -0600 | [diff] [blame] | 2829 | #endif |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2830 | TEST_F(VkLayerTest, BindInvalidMemory) { |
| 2831 | VkResult err; |
| 2832 | bool pass; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2833 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2834 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2835 | "Invalid VkDeviceMemory Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2836 | |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2837 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2838 | |
| 2839 | // 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] | 2840 | VkImage image; |
| 2841 | VkDeviceMemory mem; |
| 2842 | VkMemoryRequirements mem_reqs; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2843 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2844 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2845 | const int32_t tex_width = 32; |
| 2846 | const int32_t tex_height = 32; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2847 | |
| 2848 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2849 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2850 | image_create_info.pNext = NULL; |
| 2851 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2852 | image_create_info.format = tex_format; |
| 2853 | image_create_info.extent.width = tex_width; |
| 2854 | image_create_info.extent.height = tex_height; |
| 2855 | image_create_info.extent.depth = 1; |
| 2856 | image_create_info.mipLevels = 1; |
| 2857 | image_create_info.arrayLayers = 1; |
| 2858 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2859 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2860 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2861 | image_create_info.flags = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2862 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2863 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2864 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2865 | mem_alloc.pNext = NULL; |
| 2866 | mem_alloc.allocationSize = 0; |
| 2867 | mem_alloc.memoryTypeIndex = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2868 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2869 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2870 | ASSERT_VK_SUCCESS(err); |
| 2871 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2872 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2873 | |
| 2874 | mem_alloc.allocationSize = mem_reqs.size; |
| 2875 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2876 | pass = |
| 2877 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 2878 | ASSERT_TRUE(pass); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2879 | |
| 2880 | // allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2881 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2882 | ASSERT_VK_SUCCESS(err); |
| 2883 | |
| 2884 | // Introduce validation failure, free memory before binding |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2885 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2886 | |
| 2887 | // Try to bind free memory that has been freed |
| 2888 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 2889 | // This may very well return an error. |
| 2890 | (void)err; |
| 2891 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2892 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2893 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2894 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2895 | } |
| 2896 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2897 | TEST_F(VkLayerTest, BindMemoryToDestroyedObject) { |
| 2898 | VkResult err; |
| 2899 | bool pass; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2900 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2901 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2902 | "Invalid VkImage Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2903 | |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2904 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2905 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2906 | // Create an image object, allocate memory, destroy the object and then try |
| 2907 | // to bind it |
| 2908 | VkImage image; |
| 2909 | VkDeviceMemory mem; |
| 2910 | VkMemoryRequirements mem_reqs; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2911 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2912 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2913 | const int32_t tex_width = 32; |
| 2914 | const int32_t tex_height = 32; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2915 | |
| 2916 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2917 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2918 | image_create_info.pNext = NULL; |
| 2919 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2920 | image_create_info.format = tex_format; |
| 2921 | image_create_info.extent.width = tex_width; |
| 2922 | image_create_info.extent.height = tex_height; |
| 2923 | image_create_info.extent.depth = 1; |
| 2924 | image_create_info.mipLevels = 1; |
| 2925 | image_create_info.arrayLayers = 1; |
| 2926 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2927 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2928 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2929 | image_create_info.flags = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2930 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2931 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2932 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2933 | mem_alloc.pNext = NULL; |
| 2934 | mem_alloc.allocationSize = 0; |
| 2935 | mem_alloc.memoryTypeIndex = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2936 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2937 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2938 | ASSERT_VK_SUCCESS(err); |
| 2939 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2940 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2941 | |
| 2942 | mem_alloc.allocationSize = mem_reqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2943 | pass = |
| 2944 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 2945 | ASSERT_TRUE(pass); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2946 | |
| 2947 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2948 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2949 | ASSERT_VK_SUCCESS(err); |
| 2950 | |
| 2951 | // Introduce validation failure, destroy Image object before binding |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2952 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2953 | ASSERT_VK_SUCCESS(err); |
| 2954 | |
| 2955 | // Now Try to bind memory to this destroyed object |
| 2956 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 2957 | // This may very well return an error. |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2958 | (void)err; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2959 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2960 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2961 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2962 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2963 | } |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 2964 | |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 2965 | #endif // OBJ_TRACKER_TESTS |
| 2966 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 2967 | #if DRAW_STATE_TESTS |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 2968 | |
Mark Lobodzinski | ce7eee7 | 2016-06-14 16:33:29 -0600 | [diff] [blame] | 2969 | // This is a positive test. No errors are expected. |
| 2970 | TEST_F(VkLayerTest, StencilLoadOp) { |
| 2971 | TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to " |
| 2972 | "CLEAR. stencil[Load|Store]Op used to be ignored."); |
| 2973 | VkResult result = VK_SUCCESS; |
| 2974 | VkImageFormatProperties formatProps; |
| 2975 | vkGetPhysicalDeviceImageFormatProperties( |
| 2976 | gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, |
| 2977 | VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 2978 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, |
| 2979 | 0, &formatProps); |
| 2980 | if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) { |
| 2981 | return; |
| 2982 | } |
| 2983 | |
| 2984 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2985 | VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT; |
| 2986 | m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt, |
| 2987 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 2988 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT); |
| 2989 | VkAttachmentDescription att = {}; |
| 2990 | VkAttachmentReference ref = {}; |
| 2991 | att.format = depth_stencil_fmt; |
| 2992 | att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 2993 | att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 2994 | att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 2995 | att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE; |
| 2996 | att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 2997 | att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 2998 | |
| 2999 | VkClearValue clear; |
| 3000 | clear.depthStencil.depth = 1.0; |
| 3001 | clear.depthStencil.stencil = 0; |
| 3002 | ref.attachment = 0; |
| 3003 | ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3004 | |
| 3005 | VkSubpassDescription subpass = {}; |
| 3006 | subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; |
| 3007 | subpass.flags = 0; |
| 3008 | subpass.inputAttachmentCount = 0; |
| 3009 | subpass.pInputAttachments = NULL; |
| 3010 | subpass.colorAttachmentCount = 0; |
| 3011 | subpass.pColorAttachments = NULL; |
| 3012 | subpass.pResolveAttachments = NULL; |
| 3013 | subpass.pDepthStencilAttachment = &ref; |
| 3014 | subpass.preserveAttachmentCount = 0; |
| 3015 | subpass.pPreserveAttachments = NULL; |
| 3016 | |
| 3017 | VkRenderPass rp; |
| 3018 | VkRenderPassCreateInfo rp_info = {}; |
| 3019 | rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 3020 | rp_info.attachmentCount = 1; |
| 3021 | rp_info.pAttachments = &att; |
| 3022 | rp_info.subpassCount = 1; |
| 3023 | rp_info.pSubpasses = &subpass; |
| 3024 | result = vkCreateRenderPass(device(), &rp_info, NULL, &rp); |
| 3025 | ASSERT_VK_SUCCESS(result); |
| 3026 | |
| 3027 | VkImageView *depthView = m_depthStencil->BindInfo(); |
| 3028 | VkFramebufferCreateInfo fb_info = {}; |
| 3029 | fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
| 3030 | fb_info.pNext = NULL; |
| 3031 | fb_info.renderPass = rp; |
| 3032 | fb_info.attachmentCount = 1; |
| 3033 | fb_info.pAttachments = depthView; |
| 3034 | fb_info.width = 100; |
| 3035 | fb_info.height = 100; |
| 3036 | fb_info.layers = 1; |
| 3037 | VkFramebuffer fb; |
| 3038 | result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3039 | ASSERT_VK_SUCCESS(result); |
| 3040 | |
| 3041 | |
| 3042 | VkRenderPassBeginInfo rpbinfo = {}; |
| 3043 | rpbinfo.clearValueCount = 1; |
| 3044 | rpbinfo.pClearValues = &clear; |
| 3045 | rpbinfo.pNext = NULL; |
| 3046 | rpbinfo.renderPass = rp; |
| 3047 | rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 3048 | rpbinfo.renderArea.extent.width = 100; |
| 3049 | rpbinfo.renderArea.extent.height = 100; |
| 3050 | rpbinfo.renderArea.offset.x = 0; |
| 3051 | rpbinfo.renderArea.offset.y = 0; |
| 3052 | rpbinfo.framebuffer = fb; |
| 3053 | |
| 3054 | VkFence fence = {}; |
| 3055 | VkFenceCreateInfo fence_ci = {}; |
| 3056 | fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3057 | fence_ci.pNext = nullptr; |
| 3058 | fence_ci.flags = 0; |
| 3059 | result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence); |
| 3060 | ASSERT_VK_SUCCESS(result); |
| 3061 | |
| 3062 | |
| 3063 | m_commandBuffer->BeginCommandBuffer(); |
| 3064 | m_commandBuffer->BeginRenderPass(rpbinfo); |
| 3065 | m_commandBuffer->EndRenderPass(); |
| 3066 | m_commandBuffer->EndCommandBuffer(); |
| 3067 | m_commandBuffer->QueueCommandBuffer(fence); |
| 3068 | |
| 3069 | VkImageObj destImage(m_device); |
| 3070 | destImage.init(100, 100, depth_stencil_fmt, |
| 3071 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 3072 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 3073 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 3074 | VkImageMemoryBarrier barrier = {}; |
| 3075 | VkImageSubresourceRange range; |
| 3076 | barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 3077 | barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | |
| 3078 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; |
| 3079 | barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | |
| 3080 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT; |
| 3081 | barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3082 | barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 3083 | barrier.image = m_depthStencil->handle(); |
| 3084 | range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3085 | range.baseMipLevel = 0; |
| 3086 | range.levelCount = 1; |
| 3087 | range.baseArrayLayer = 0; |
| 3088 | range.layerCount = 1; |
| 3089 | barrier.subresourceRange = range; |
| 3090 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 3091 | VkCommandBufferObj cmdbuf(m_device, m_commandPool); |
| 3092 | cmdbuf.BeginCommandBuffer(); |
| 3093 | cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3094 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, |
| 3095 | nullptr, 1, &barrier); |
| 3096 | barrier.srcAccessMask = 0; |
| 3097 | barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 3098 | barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; |
| 3099 | barrier.image = destImage.handle(); |
| 3100 | barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | |
| 3101 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; |
| 3102 | cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3103 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, |
| 3104 | nullptr, 1, &barrier); |
| 3105 | VkImageCopy cregion; |
| 3106 | cregion.srcSubresource.aspectMask = |
| 3107 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3108 | cregion.srcSubresource.mipLevel = 0; |
| 3109 | cregion.srcSubresource.baseArrayLayer = 0; |
| 3110 | cregion.srcSubresource.layerCount = 1; |
| 3111 | cregion.srcOffset.x = 0; |
| 3112 | cregion.srcOffset.y = 0; |
| 3113 | cregion.srcOffset.z = 0; |
| 3114 | cregion.dstSubresource.aspectMask = |
| 3115 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3116 | cregion.dstSubresource.mipLevel = 0; |
| 3117 | cregion.dstSubresource.baseArrayLayer = 0; |
| 3118 | cregion.dstSubresource.layerCount = 1; |
| 3119 | cregion.dstOffset.x = 0; |
| 3120 | cregion.dstOffset.y = 0; |
| 3121 | cregion.dstOffset.z = 0; |
| 3122 | cregion.extent.width = 100; |
| 3123 | cregion.extent.height = 100; |
| 3124 | cregion.extent.depth = 1; |
| 3125 | cmdbuf.CopyImage(m_depthStencil->handle(), |
| 3126 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(), |
| 3127 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion); |
| 3128 | cmdbuf.EndCommandBuffer(); |
| 3129 | |
| 3130 | VkSubmitInfo submit_info; |
| 3131 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3132 | submit_info.pNext = NULL; |
| 3133 | submit_info.waitSemaphoreCount = 0; |
| 3134 | submit_info.pWaitSemaphores = NULL; |
| 3135 | submit_info.pWaitDstStageMask = NULL; |
| 3136 | submit_info.commandBufferCount = 1; |
| 3137 | submit_info.pCommandBuffers = &cmdbuf.handle(); |
| 3138 | submit_info.signalSemaphoreCount = 0; |
| 3139 | submit_info.pSignalSemaphores = NULL; |
| 3140 | |
| 3141 | m_errorMonitor->ExpectSuccess(); |
| 3142 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3143 | m_errorMonitor->VerifyNotFound(); |
| 3144 | |
Mark Lobodzinski | d0440da | 2016-06-17 15:10:03 -0600 | [diff] [blame] | 3145 | vkQueueWaitIdle(m_device->m_queue); |
Mark Lobodzinski | ce7eee7 | 2016-06-14 16:33:29 -0600 | [diff] [blame] | 3146 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 3147 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3148 | vkDestroyFramebuffer(m_device->device(), fb, nullptr); |
| 3149 | } |
| 3150 | |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3151 | TEST_F(VkLayerTest, UnusedPreserveAttachment) { |
| 3152 | TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve " |
| 3153 | "attachment reference of VK_ATTACHMENT_UNUSED"); |
| 3154 | |
| 3155 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3156 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 3157 | |
| 3158 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3159 | "must not be VK_ATTACHMENT_UNUSED"); |
| 3160 | |
| 3161 | VkAttachmentReference color_attach = {}; |
| 3162 | color_attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 3163 | color_attach.attachment = 0; |
| 3164 | uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED; |
| 3165 | VkSubpassDescription subpass = {}; |
| 3166 | subpass.colorAttachmentCount = 1; |
| 3167 | subpass.pColorAttachments = &color_attach; |
| 3168 | subpass.preserveAttachmentCount = 1; |
| 3169 | subpass.pPreserveAttachments = &preserve_attachment; |
| 3170 | |
| 3171 | VkRenderPassCreateInfo rpci = {}; |
| 3172 | rpci.subpassCount = 1; |
| 3173 | rpci.pSubpasses = &subpass; |
| 3174 | rpci.attachmentCount = 1; |
| 3175 | VkAttachmentDescription attach_desc = {}; |
| 3176 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 3177 | rpci.pAttachments = &attach_desc; |
| 3178 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 3179 | VkRenderPass rp; |
Mark Lobodzinski | a4feeeb | 2016-06-17 12:00:46 -0600 | [diff] [blame] | 3180 | VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3181 | |
| 3182 | m_errorMonitor->VerifyFound(); |
| 3183 | |
Mark Lobodzinski | a4feeeb | 2016-06-17 12:00:46 -0600 | [diff] [blame] | 3184 | if (result == VK_SUCCESS) { |
| 3185 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 3186 | } |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3187 | } |
| 3188 | |
| 3189 | TEST_F(VkLayerTest, AttachmentUsageMismatch) { |
| 3190 | TEST_DESCRIPTION("Create a framebuffer where a subpass uses a color image " |
| 3191 | "in the depthStencil attachment point"); |
| 3192 | |
| 3193 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3194 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 3195 | |
| 3196 | m_errorMonitor->SetDesiredFailureMsg( |
| 3197 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3198 | "conflicts with the image's IMAGE_USAGE flags"); |
| 3199 | |
| 3200 | // Create a renderPass with a depth-stencil attachment created with |
| 3201 | // IMAGE_USAGE_COLOR_ATTACHMENT |
| 3202 | VkAttachmentReference attach = {}; |
| 3203 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 3204 | VkSubpassDescription subpass = {}; |
| 3205 | // Add our color attachment to pDepthStencilAttachment |
| 3206 | subpass.pDepthStencilAttachment = &attach; |
| 3207 | VkRenderPassCreateInfo rpci = {}; |
| 3208 | rpci.subpassCount = 1; |
| 3209 | rpci.pSubpasses = &subpass; |
| 3210 | rpci.attachmentCount = 1; |
| 3211 | VkAttachmentDescription attach_desc = {}; |
| 3212 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 3213 | rpci.pAttachments = &attach_desc; |
| 3214 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 3215 | VkRenderPass rp; |
| 3216 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3217 | ASSERT_VK_SUCCESS(err); |
| 3218 | |
| 3219 | VkImageView imageView = |
| 3220 | m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM); |
| 3221 | VkFramebufferCreateInfo fb_info = {}; |
| 3222 | fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
| 3223 | fb_info.pNext = NULL; |
| 3224 | fb_info.renderPass = rp; |
| 3225 | fb_info.attachmentCount = 1; |
| 3226 | fb_info.pAttachments = &imageView; |
| 3227 | fb_info.width = 100; |
| 3228 | fb_info.height = 100; |
| 3229 | fb_info.layers = 1; |
| 3230 | |
| 3231 | VkFramebuffer fb; |
| 3232 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3233 | |
| 3234 | m_errorMonitor->VerifyFound(); |
| 3235 | |
| 3236 | if (err == VK_SUCCESS) { |
| 3237 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3238 | } |
| 3239 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 3240 | } |
| 3241 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3242 | // This is a positive test. No errors should be generated. |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3243 | TEST_F(VkLayerTest, WaitEventThenSet) { |
| 3244 | TEST_DESCRIPTION( |
| 3245 | "Wait on a event then set it after the wait has been submitted."); |
| 3246 | |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3247 | m_errorMonitor->ExpectSuccess(); |
| 3248 | |
| 3249 | VkEvent event; |
| 3250 | VkEventCreateInfo event_create_info{}; |
| 3251 | event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 3252 | vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event); |
| 3253 | |
| 3254 | VkCommandPool command_pool; |
| 3255 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3256 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3257 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3258 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3259 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3260 | &command_pool); |
| 3261 | |
| 3262 | VkCommandBuffer command_buffer; |
| 3263 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3264 | command_buffer_allocate_info.sType = |
| 3265 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3266 | command_buffer_allocate_info.commandPool = command_pool; |
| 3267 | command_buffer_allocate_info.commandBufferCount = 1; |
| 3268 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3269 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3270 | &command_buffer); |
| 3271 | |
| 3272 | VkQueue queue = VK_NULL_HANDLE; |
| 3273 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
Tony Barbour | fe302c0 | 2016-06-06 13:05:19 -0600 | [diff] [blame] | 3274 | 0, &queue); |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3275 | |
| 3276 | { |
| 3277 | VkCommandBufferBeginInfo begin_info{}; |
| 3278 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3279 | vkBeginCommandBuffer(command_buffer, &begin_info); |
| 3280 | |
| 3281 | vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, |
| 3282 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, |
| 3283 | nullptr, 0, nullptr); |
| 3284 | vkCmdResetEvent(command_buffer, event, |
| 3285 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 3286 | vkEndCommandBuffer(command_buffer); |
| 3287 | } |
| 3288 | { |
| 3289 | VkSubmitInfo submit_info{}; |
| 3290 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3291 | submit_info.commandBufferCount = 1; |
| 3292 | submit_info.pCommandBuffers = &command_buffer; |
| 3293 | submit_info.signalSemaphoreCount = 0; |
| 3294 | submit_info.pSignalSemaphores = nullptr; |
| 3295 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3296 | } |
| 3297 | { vkSetEvent(m_device->device(), event); } |
| 3298 | |
| 3299 | vkQueueWaitIdle(queue); |
| 3300 | |
| 3301 | vkDestroyEvent(m_device->device(), event, nullptr); |
| 3302 | vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer); |
| 3303 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3304 | |
| 3305 | m_errorMonitor->VerifyNotFound(); |
| 3306 | } |
Michael Lentine | 5627e69 | 2016-05-20 17:45:02 -0500 | [diff] [blame] | 3307 | // This is a positive test. No errors should be generated. |
| 3308 | TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) { |
| 3309 | TEST_DESCRIPTION( |
| 3310 | "Issue a query and copy from it on a second command buffer."); |
| 3311 | |
| 3312 | if ((m_device->queue_props.empty()) || |
| 3313 | (m_device->queue_props[0].queueCount < 2)) |
| 3314 | return; |
| 3315 | |
| 3316 | m_errorMonitor->ExpectSuccess(); |
| 3317 | |
| 3318 | VkQueryPool query_pool; |
| 3319 | VkQueryPoolCreateInfo query_pool_create_info{}; |
| 3320 | query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; |
| 3321 | query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP; |
| 3322 | query_pool_create_info.queryCount = 1; |
| 3323 | vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, |
| 3324 | &query_pool); |
| 3325 | |
| 3326 | VkCommandPool command_pool; |
| 3327 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3328 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3329 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3330 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3331 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3332 | &command_pool); |
| 3333 | |
| 3334 | VkCommandBuffer command_buffer[2]; |
| 3335 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3336 | command_buffer_allocate_info.sType = |
| 3337 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3338 | command_buffer_allocate_info.commandPool = command_pool; |
| 3339 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3340 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3341 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3342 | command_buffer); |
| 3343 | |
| 3344 | VkQueue queue = VK_NULL_HANDLE; |
| 3345 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3346 | 1, &queue); |
| 3347 | |
| 3348 | uint32_t qfi = 0; |
| 3349 | VkBufferCreateInfo buff_create_info = {}; |
| 3350 | buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 3351 | buff_create_info.size = 1024; |
| 3352 | buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT; |
| 3353 | buff_create_info.queueFamilyIndexCount = 1; |
| 3354 | buff_create_info.pQueueFamilyIndices = &qfi; |
| 3355 | |
| 3356 | VkResult err; |
| 3357 | VkBuffer buffer; |
| 3358 | err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer); |
| 3359 | ASSERT_VK_SUCCESS(err); |
| 3360 | VkMemoryAllocateInfo mem_alloc = {}; |
| 3361 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 3362 | mem_alloc.pNext = NULL; |
| 3363 | mem_alloc.allocationSize = 1024; |
| 3364 | mem_alloc.memoryTypeIndex = 0; |
| 3365 | |
| 3366 | VkMemoryRequirements memReqs; |
| 3367 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs); |
| 3368 | bool pass = |
| 3369 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0); |
| 3370 | if (!pass) { |
| 3371 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 3372 | return; |
| 3373 | } |
| 3374 | |
| 3375 | VkDeviceMemory mem; |
| 3376 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 3377 | ASSERT_VK_SUCCESS(err); |
| 3378 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 3379 | ASSERT_VK_SUCCESS(err); |
| 3380 | |
| 3381 | { |
| 3382 | VkCommandBufferBeginInfo begin_info{}; |
| 3383 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3384 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3385 | |
| 3386 | vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1); |
| 3387 | vkCmdWriteTimestamp(command_buffer[0], |
| 3388 | VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0); |
| 3389 | |
| 3390 | vkEndCommandBuffer(command_buffer[0]); |
| 3391 | |
| 3392 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3393 | |
| 3394 | vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, |
| 3395 | 0, 0, 0); |
| 3396 | |
| 3397 | vkEndCommandBuffer(command_buffer[1]); |
| 3398 | } |
| 3399 | { |
| 3400 | VkSubmitInfo submit_info{}; |
| 3401 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3402 | submit_info.commandBufferCount = 2; |
| 3403 | submit_info.pCommandBuffers = command_buffer; |
| 3404 | submit_info.signalSemaphoreCount = 0; |
| 3405 | submit_info.pSignalSemaphores = nullptr; |
| 3406 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3407 | } |
| 3408 | |
| 3409 | vkQueueWaitIdle(queue); |
| 3410 | |
| 3411 | vkDestroyQueryPool(m_device->device(), query_pool, nullptr); |
| 3412 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer); |
| 3413 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 3414 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 3415 | vkFreeMemory(m_device->device(), mem, NULL); |
Michael Lentine | 5627e69 | 2016-05-20 17:45:02 -0500 | [diff] [blame] | 3416 | |
| 3417 | m_errorMonitor->VerifyNotFound(); |
| 3418 | } |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3419 | |
| 3420 | TEST_F(VkLayerTest, ResetEventThenSet) { |
| 3421 | TEST_DESCRIPTION( |
| 3422 | "Reset an event then set it after the reset has been submitted."); |
| 3423 | |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3424 | m_errorMonitor->ExpectSuccess(); |
| 3425 | |
| 3426 | VkEvent event; |
| 3427 | VkEventCreateInfo event_create_info{}; |
| 3428 | event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 3429 | vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event); |
| 3430 | |
| 3431 | VkCommandPool command_pool; |
| 3432 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3433 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3434 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3435 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3436 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3437 | &command_pool); |
| 3438 | |
| 3439 | VkCommandBuffer command_buffer; |
| 3440 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3441 | command_buffer_allocate_info.sType = |
| 3442 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3443 | command_buffer_allocate_info.commandPool = command_pool; |
| 3444 | command_buffer_allocate_info.commandBufferCount = 1; |
| 3445 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3446 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3447 | &command_buffer); |
| 3448 | |
| 3449 | VkQueue queue = VK_NULL_HANDLE; |
| 3450 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
Tony Barbour | fe302c0 | 2016-06-06 13:05:19 -0600 | [diff] [blame] | 3451 | 0, &queue); |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3452 | |
| 3453 | { |
| 3454 | VkCommandBufferBeginInfo begin_info{}; |
| 3455 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3456 | vkBeginCommandBuffer(command_buffer, &begin_info); |
| 3457 | |
| 3458 | vkCmdResetEvent(command_buffer, event, |
| 3459 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 3460 | vkCmdWaitEvents(command_buffer, 1, &event, |
| 3461 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3462 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, |
| 3463 | nullptr, 0, nullptr); |
| 3464 | vkEndCommandBuffer(command_buffer); |
| 3465 | } |
| 3466 | { |
| 3467 | VkSubmitInfo submit_info{}; |
| 3468 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3469 | submit_info.commandBufferCount = 1; |
| 3470 | submit_info.pCommandBuffers = &command_buffer; |
| 3471 | submit_info.signalSemaphoreCount = 0; |
| 3472 | submit_info.pSignalSemaphores = nullptr; |
| 3473 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3474 | } |
| 3475 | { |
| 3476 | m_errorMonitor->SetDesiredFailureMsg( |
| 3477 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkSetEvent() on event " |
| 3478 | "0x1 that is already in use by a " |
| 3479 | "command buffer."); |
| 3480 | vkSetEvent(m_device->device(), event); |
| 3481 | m_errorMonitor->VerifyFound(); |
| 3482 | } |
| 3483 | |
| 3484 | vkQueueWaitIdle(queue); |
| 3485 | |
| 3486 | vkDestroyEvent(m_device->device(), event, nullptr); |
| 3487 | vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer); |
| 3488 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3489 | } |
| 3490 | |
| 3491 | // This is a positive test. No errors should be generated. |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3492 | TEST_F(VkLayerTest, TwoFencesThreeFrames) { |
| 3493 | TEST_DESCRIPTION("Two command buffers with two separate fences are each " |
| 3494 | "run through a Submit & WaitForFences cycle 3 times. This " |
| 3495 | "previously revealed a bug so running this positive test " |
| 3496 | "to prevent a regression."); |
| 3497 | m_errorMonitor->ExpectSuccess(); |
| 3498 | |
| 3499 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3500 | VkQueue queue = VK_NULL_HANDLE; |
| 3501 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3502 | 0, &queue); |
| 3503 | |
| 3504 | static const uint32_t NUM_OBJECTS = 2; |
| 3505 | static const uint32_t NUM_FRAMES = 3; |
| 3506 | VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {}; |
| 3507 | VkFence fences[NUM_OBJECTS] = {}; |
| 3508 | |
| 3509 | VkCommandPool cmd_pool; |
| 3510 | VkCommandPoolCreateInfo cmd_pool_ci = {}; |
| 3511 | cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3512 | cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3513 | cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3514 | VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, |
| 3515 | nullptr, &cmd_pool); |
| 3516 | ASSERT_VK_SUCCESS(err); |
| 3517 | |
| 3518 | VkCommandBufferAllocateInfo cmd_buf_info = {}; |
| 3519 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3520 | cmd_buf_info.commandPool = cmd_pool; |
| 3521 | cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3522 | cmd_buf_info.commandBufferCount = 1; |
| 3523 | |
| 3524 | VkFenceCreateInfo fence_ci = {}; |
| 3525 | fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3526 | fence_ci.pNext = nullptr; |
| 3527 | fence_ci.flags = 0; |
| 3528 | |
| 3529 | for (uint32_t i = 0; i < NUM_OBJECTS; ++i) { |
| 3530 | err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, |
| 3531 | &cmd_buffers[i]); |
| 3532 | ASSERT_VK_SUCCESS(err); |
| 3533 | err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]); |
| 3534 | ASSERT_VK_SUCCESS(err); |
| 3535 | } |
| 3536 | |
| 3537 | for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) { |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 3538 | for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) { |
| 3539 | // Create empty cmd buffer |
| 3540 | VkCommandBufferBeginInfo cmdBufBeginDesc = {}; |
| 3541 | cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3542 | |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 3543 | err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc); |
| 3544 | ASSERT_VK_SUCCESS(err); |
| 3545 | err = vkEndCommandBuffer(cmd_buffers[obj]); |
| 3546 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3547 | |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 3548 | VkSubmitInfo submit_info = {}; |
| 3549 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3550 | submit_info.commandBufferCount = 1; |
| 3551 | submit_info.pCommandBuffers = &cmd_buffers[obj]; |
| 3552 | // Submit cmd buffer and wait for fence |
| 3553 | err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]); |
| 3554 | ASSERT_VK_SUCCESS(err); |
| 3555 | err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, |
| 3556 | UINT64_MAX); |
| 3557 | ASSERT_VK_SUCCESS(err); |
| 3558 | err = vkResetFences(m_device->device(), 1, &fences[obj]); |
| 3559 | ASSERT_VK_SUCCESS(err); |
| 3560 | } |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3561 | } |
| 3562 | m_errorMonitor->VerifyNotFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 3563 | vkDestroyCommandPool(m_device->device(), cmd_pool, NULL); |
| 3564 | for (uint32_t i = 0; i < NUM_OBJECTS; ++i) { |
| 3565 | vkDestroyFence(m_device->device(), fences[i], nullptr); |
| 3566 | } |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3567 | } |
| 3568 | // This is a positive test. No errors should be generated. |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3569 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) { |
| 3570 | |
| 3571 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 3572 | "submitted on separate queues followed by a QueueWaitIdle."); |
| 3573 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 3574 | if ((m_device->queue_props.empty()) || |
| 3575 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 3576 | return; |
| 3577 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3578 | m_errorMonitor->ExpectSuccess(); |
| 3579 | |
| 3580 | VkSemaphore semaphore; |
| 3581 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 3582 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 3583 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 3584 | &semaphore); |
| 3585 | |
| 3586 | VkCommandPool command_pool; |
| 3587 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3588 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3589 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3590 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3591 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3592 | &command_pool); |
| 3593 | |
| 3594 | VkCommandBuffer command_buffer[2]; |
| 3595 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3596 | command_buffer_allocate_info.sType = |
| 3597 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3598 | command_buffer_allocate_info.commandPool = command_pool; |
| 3599 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3600 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3601 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3602 | command_buffer); |
| 3603 | |
| 3604 | VkQueue queue = VK_NULL_HANDLE; |
| 3605 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3606 | 1, &queue); |
| 3607 | |
| 3608 | { |
| 3609 | VkCommandBufferBeginInfo begin_info{}; |
| 3610 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3611 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3612 | |
| 3613 | vkCmdPipelineBarrier(command_buffer[0], |
| 3614 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3615 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 3616 | 0, nullptr, 0, nullptr); |
| 3617 | |
| 3618 | VkViewport viewport{}; |
| 3619 | viewport.maxDepth = 1.0f; |
| 3620 | viewport.minDepth = 0.0f; |
| 3621 | viewport.width = 512; |
| 3622 | viewport.height = 512; |
| 3623 | viewport.x = 0; |
| 3624 | viewport.y = 0; |
| 3625 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 3626 | vkEndCommandBuffer(command_buffer[0]); |
| 3627 | } |
| 3628 | { |
| 3629 | VkCommandBufferBeginInfo begin_info{}; |
| 3630 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3631 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3632 | |
| 3633 | VkViewport viewport{}; |
| 3634 | viewport.maxDepth = 1.0f; |
| 3635 | viewport.minDepth = 0.0f; |
| 3636 | viewport.width = 512; |
| 3637 | viewport.height = 512; |
| 3638 | viewport.x = 0; |
| 3639 | viewport.y = 0; |
| 3640 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 3641 | vkEndCommandBuffer(command_buffer[1]); |
| 3642 | } |
| 3643 | { |
| 3644 | VkSubmitInfo submit_info{}; |
| 3645 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3646 | submit_info.commandBufferCount = 1; |
| 3647 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 3648 | submit_info.signalSemaphoreCount = 1; |
| 3649 | submit_info.pSignalSemaphores = &semaphore; |
| 3650 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3651 | } |
| 3652 | { |
| 3653 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 3654 | VkSubmitInfo submit_info{}; |
| 3655 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3656 | submit_info.commandBufferCount = 1; |
| 3657 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 3658 | submit_info.waitSemaphoreCount = 1; |
| 3659 | submit_info.pWaitSemaphores = &semaphore; |
| 3660 | submit_info.pWaitDstStageMask = flags; |
| 3661 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3662 | } |
| 3663 | |
| 3664 | vkQueueWaitIdle(m_device->m_queue); |
| 3665 | |
| 3666 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 3667 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 3668 | &command_buffer[0]); |
| 3669 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3670 | |
| 3671 | m_errorMonitor->VerifyNotFound(); |
| 3672 | } |
| 3673 | |
| 3674 | // This is a positive test. No errors should be generated. |
| 3675 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) { |
| 3676 | |
| 3677 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 3678 | "submitted on separate queues, the second having a fence" |
| 3679 | "followed by a QueueWaitIdle."); |
| 3680 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 3681 | if ((m_device->queue_props.empty()) || |
| 3682 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 3683 | return; |
| 3684 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3685 | m_errorMonitor->ExpectSuccess(); |
| 3686 | |
| 3687 | VkFence fence; |
| 3688 | VkFenceCreateInfo fence_create_info{}; |
| 3689 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3690 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 3691 | |
| 3692 | VkSemaphore semaphore; |
| 3693 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 3694 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 3695 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 3696 | &semaphore); |
| 3697 | |
| 3698 | VkCommandPool command_pool; |
| 3699 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3700 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3701 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3702 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3703 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3704 | &command_pool); |
| 3705 | |
| 3706 | VkCommandBuffer command_buffer[2]; |
| 3707 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3708 | command_buffer_allocate_info.sType = |
| 3709 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3710 | command_buffer_allocate_info.commandPool = command_pool; |
| 3711 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3712 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3713 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3714 | command_buffer); |
| 3715 | |
| 3716 | VkQueue queue = VK_NULL_HANDLE; |
| 3717 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3718 | 1, &queue); |
| 3719 | |
| 3720 | { |
| 3721 | VkCommandBufferBeginInfo begin_info{}; |
| 3722 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3723 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3724 | |
| 3725 | vkCmdPipelineBarrier(command_buffer[0], |
| 3726 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3727 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 3728 | 0, nullptr, 0, nullptr); |
| 3729 | |
| 3730 | VkViewport viewport{}; |
| 3731 | viewport.maxDepth = 1.0f; |
| 3732 | viewport.minDepth = 0.0f; |
| 3733 | viewport.width = 512; |
| 3734 | viewport.height = 512; |
| 3735 | viewport.x = 0; |
| 3736 | viewport.y = 0; |
| 3737 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 3738 | vkEndCommandBuffer(command_buffer[0]); |
| 3739 | } |
| 3740 | { |
| 3741 | VkCommandBufferBeginInfo begin_info{}; |
| 3742 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3743 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3744 | |
| 3745 | VkViewport viewport{}; |
| 3746 | viewport.maxDepth = 1.0f; |
| 3747 | viewport.minDepth = 0.0f; |
| 3748 | viewport.width = 512; |
| 3749 | viewport.height = 512; |
| 3750 | viewport.x = 0; |
| 3751 | viewport.y = 0; |
| 3752 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 3753 | vkEndCommandBuffer(command_buffer[1]); |
| 3754 | } |
| 3755 | { |
| 3756 | VkSubmitInfo submit_info{}; |
| 3757 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3758 | submit_info.commandBufferCount = 1; |
| 3759 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 3760 | submit_info.signalSemaphoreCount = 1; |
| 3761 | submit_info.pSignalSemaphores = &semaphore; |
| 3762 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3763 | } |
| 3764 | { |
| 3765 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 3766 | VkSubmitInfo submit_info{}; |
| 3767 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3768 | submit_info.commandBufferCount = 1; |
| 3769 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 3770 | submit_info.waitSemaphoreCount = 1; |
| 3771 | submit_info.pWaitSemaphores = &semaphore; |
| 3772 | submit_info.pWaitDstStageMask = flags; |
| 3773 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 3774 | } |
| 3775 | |
| 3776 | vkQueueWaitIdle(m_device->m_queue); |
| 3777 | |
| 3778 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 3779 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 3780 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 3781 | &command_buffer[0]); |
| 3782 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3783 | |
| 3784 | m_errorMonitor->VerifyNotFound(); |
| 3785 | } |
| 3786 | |
| 3787 | // This is a positive test. No errors should be generated. |
| 3788 | TEST_F(VkLayerTest, |
| 3789 | TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) { |
| 3790 | |
| 3791 | TEST_DESCRIPTION( |
| 3792 | "Two command buffers, each in a separate QueueSubmit call " |
| 3793 | "submitted on separate queues, the second having a fence" |
| 3794 | "followed by two consecutive WaitForFences calls on the same fence."); |
| 3795 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 3796 | if ((m_device->queue_props.empty()) || |
| 3797 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 3798 | return; |
| 3799 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3800 | m_errorMonitor->ExpectSuccess(); |
| 3801 | |
| 3802 | VkFence fence; |
| 3803 | VkFenceCreateInfo fence_create_info{}; |
| 3804 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3805 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 3806 | |
| 3807 | VkSemaphore semaphore; |
| 3808 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 3809 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 3810 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 3811 | &semaphore); |
| 3812 | |
| 3813 | VkCommandPool command_pool; |
| 3814 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3815 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3816 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3817 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3818 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3819 | &command_pool); |
| 3820 | |
| 3821 | VkCommandBuffer command_buffer[2]; |
| 3822 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3823 | command_buffer_allocate_info.sType = |
| 3824 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3825 | command_buffer_allocate_info.commandPool = command_pool; |
| 3826 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3827 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3828 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3829 | command_buffer); |
| 3830 | |
| 3831 | VkQueue queue = VK_NULL_HANDLE; |
| 3832 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3833 | 1, &queue); |
| 3834 | |
| 3835 | { |
| 3836 | VkCommandBufferBeginInfo begin_info{}; |
| 3837 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3838 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3839 | |
| 3840 | vkCmdPipelineBarrier(command_buffer[0], |
| 3841 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3842 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 3843 | 0, nullptr, 0, nullptr); |
| 3844 | |
| 3845 | VkViewport viewport{}; |
| 3846 | viewport.maxDepth = 1.0f; |
| 3847 | viewport.minDepth = 0.0f; |
| 3848 | viewport.width = 512; |
| 3849 | viewport.height = 512; |
| 3850 | viewport.x = 0; |
| 3851 | viewport.y = 0; |
| 3852 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 3853 | vkEndCommandBuffer(command_buffer[0]); |
| 3854 | } |
| 3855 | { |
| 3856 | VkCommandBufferBeginInfo begin_info{}; |
| 3857 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3858 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3859 | |
| 3860 | VkViewport viewport{}; |
| 3861 | viewport.maxDepth = 1.0f; |
| 3862 | viewport.minDepth = 0.0f; |
| 3863 | viewport.width = 512; |
| 3864 | viewport.height = 512; |
| 3865 | viewport.x = 0; |
| 3866 | viewport.y = 0; |
| 3867 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 3868 | vkEndCommandBuffer(command_buffer[1]); |
| 3869 | } |
| 3870 | { |
| 3871 | VkSubmitInfo submit_info{}; |
| 3872 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3873 | submit_info.commandBufferCount = 1; |
| 3874 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 3875 | submit_info.signalSemaphoreCount = 1; |
| 3876 | submit_info.pSignalSemaphores = &semaphore; |
| 3877 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3878 | } |
| 3879 | { |
| 3880 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 3881 | VkSubmitInfo submit_info{}; |
| 3882 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3883 | submit_info.commandBufferCount = 1; |
| 3884 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 3885 | submit_info.waitSemaphoreCount = 1; |
| 3886 | submit_info.pWaitSemaphores = &semaphore; |
| 3887 | submit_info.pWaitDstStageMask = flags; |
| 3888 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 3889 | } |
| 3890 | |
| 3891 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 3892 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 3893 | |
| 3894 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 3895 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 3896 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 3897 | &command_buffer[0]); |
| 3898 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3899 | |
| 3900 | m_errorMonitor->VerifyNotFound(); |
| 3901 | } |
| 3902 | |
| 3903 | // This is a positive test. No errors should be generated. |
| 3904 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) { |
| 3905 | |
| 3906 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 3907 | "submitted on separate queues, the second having a fence, " |
| 3908 | "followed by a WaitForFences call."); |
| 3909 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 3910 | if ((m_device->queue_props.empty()) || |
| 3911 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 3912 | return; |
| 3913 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3914 | m_errorMonitor->ExpectSuccess(); |
| 3915 | |
| 3916 | VkFence fence; |
| 3917 | VkFenceCreateInfo fence_create_info{}; |
| 3918 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3919 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 3920 | |
| 3921 | VkSemaphore semaphore; |
| 3922 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 3923 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 3924 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 3925 | &semaphore); |
| 3926 | |
| 3927 | VkCommandPool command_pool; |
| 3928 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3929 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3930 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3931 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3932 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3933 | &command_pool); |
| 3934 | |
| 3935 | VkCommandBuffer command_buffer[2]; |
| 3936 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3937 | command_buffer_allocate_info.sType = |
| 3938 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3939 | command_buffer_allocate_info.commandPool = command_pool; |
| 3940 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3941 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3942 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3943 | command_buffer); |
| 3944 | |
| 3945 | VkQueue queue = VK_NULL_HANDLE; |
| 3946 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3947 | 1, &queue); |
| 3948 | |
| 3949 | |
| 3950 | { |
| 3951 | VkCommandBufferBeginInfo begin_info{}; |
| 3952 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3953 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3954 | |
| 3955 | vkCmdPipelineBarrier(command_buffer[0], |
| 3956 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3957 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 3958 | 0, nullptr, 0, nullptr); |
| 3959 | |
| 3960 | VkViewport viewport{}; |
| 3961 | viewport.maxDepth = 1.0f; |
| 3962 | viewport.minDepth = 0.0f; |
| 3963 | viewport.width = 512; |
| 3964 | viewport.height = 512; |
| 3965 | viewport.x = 0; |
| 3966 | viewport.y = 0; |
| 3967 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 3968 | vkEndCommandBuffer(command_buffer[0]); |
| 3969 | } |
| 3970 | { |
| 3971 | VkCommandBufferBeginInfo begin_info{}; |
| 3972 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3973 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3974 | |
| 3975 | VkViewport viewport{}; |
| 3976 | viewport.maxDepth = 1.0f; |
| 3977 | viewport.minDepth = 0.0f; |
| 3978 | viewport.width = 512; |
| 3979 | viewport.height = 512; |
| 3980 | viewport.x = 0; |
| 3981 | viewport.y = 0; |
| 3982 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 3983 | vkEndCommandBuffer(command_buffer[1]); |
| 3984 | } |
| 3985 | { |
| 3986 | VkSubmitInfo submit_info{}; |
| 3987 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3988 | submit_info.commandBufferCount = 1; |
| 3989 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 3990 | submit_info.signalSemaphoreCount = 1; |
| 3991 | submit_info.pSignalSemaphores = &semaphore; |
| 3992 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3993 | } |
| 3994 | { |
| 3995 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 3996 | VkSubmitInfo submit_info{}; |
| 3997 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3998 | submit_info.commandBufferCount = 1; |
| 3999 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4000 | submit_info.waitSemaphoreCount = 1; |
| 4001 | submit_info.pWaitSemaphores = &semaphore; |
| 4002 | submit_info.pWaitDstStageMask = flags; |
| 4003 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4004 | } |
| 4005 | |
| 4006 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4007 | |
| 4008 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4009 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4010 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4011 | &command_buffer[0]); |
| 4012 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4013 | |
| 4014 | m_errorMonitor->VerifyNotFound(); |
| 4015 | } |
| 4016 | |
| 4017 | // This is a positive test. No errors should be generated. |
| 4018 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) { |
| 4019 | |
| 4020 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4021 | "on the same queue, sharing a signal/wait semaphore, the " |
| 4022 | "second having a fence, " |
| 4023 | "followed by a WaitForFences call."); |
| 4024 | |
| 4025 | m_errorMonitor->ExpectSuccess(); |
| 4026 | |
| 4027 | VkFence fence; |
| 4028 | VkFenceCreateInfo fence_create_info{}; |
| 4029 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4030 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4031 | |
| 4032 | VkSemaphore semaphore; |
| 4033 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4034 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4035 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4036 | &semaphore); |
| 4037 | |
| 4038 | VkCommandPool command_pool; |
| 4039 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4040 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4041 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4042 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4043 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4044 | &command_pool); |
| 4045 | |
| 4046 | VkCommandBuffer command_buffer[2]; |
| 4047 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4048 | command_buffer_allocate_info.sType = |
| 4049 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4050 | command_buffer_allocate_info.commandPool = command_pool; |
| 4051 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4052 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4053 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4054 | command_buffer); |
| 4055 | |
| 4056 | { |
| 4057 | VkCommandBufferBeginInfo begin_info{}; |
| 4058 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4059 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4060 | |
| 4061 | vkCmdPipelineBarrier(command_buffer[0], |
| 4062 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4063 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4064 | 0, nullptr, 0, nullptr); |
| 4065 | |
| 4066 | VkViewport viewport{}; |
| 4067 | viewport.maxDepth = 1.0f; |
| 4068 | viewport.minDepth = 0.0f; |
| 4069 | viewport.width = 512; |
| 4070 | viewport.height = 512; |
| 4071 | viewport.x = 0; |
| 4072 | viewport.y = 0; |
| 4073 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4074 | vkEndCommandBuffer(command_buffer[0]); |
| 4075 | } |
| 4076 | { |
| 4077 | VkCommandBufferBeginInfo begin_info{}; |
| 4078 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4079 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4080 | |
| 4081 | VkViewport viewport{}; |
| 4082 | viewport.maxDepth = 1.0f; |
| 4083 | viewport.minDepth = 0.0f; |
| 4084 | viewport.width = 512; |
| 4085 | viewport.height = 512; |
| 4086 | viewport.x = 0; |
| 4087 | viewport.y = 0; |
| 4088 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4089 | vkEndCommandBuffer(command_buffer[1]); |
| 4090 | } |
| 4091 | { |
| 4092 | VkSubmitInfo submit_info{}; |
| 4093 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4094 | submit_info.commandBufferCount = 1; |
| 4095 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4096 | submit_info.signalSemaphoreCount = 1; |
| 4097 | submit_info.pSignalSemaphores = &semaphore; |
| 4098 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4099 | } |
| 4100 | { |
| 4101 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4102 | VkSubmitInfo submit_info{}; |
| 4103 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4104 | submit_info.commandBufferCount = 1; |
| 4105 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4106 | submit_info.waitSemaphoreCount = 1; |
| 4107 | submit_info.pWaitSemaphores = &semaphore; |
| 4108 | submit_info.pWaitDstStageMask = flags; |
| 4109 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4110 | } |
| 4111 | |
| 4112 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4113 | |
| 4114 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4115 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4116 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4117 | &command_buffer[0]); |
| 4118 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4119 | |
| 4120 | m_errorMonitor->VerifyNotFound(); |
| 4121 | } |
| 4122 | |
| 4123 | // This is a positive test. No errors should be generated. |
| 4124 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) { |
| 4125 | |
| 4126 | TEST_DESCRIPTION( |
| 4127 | "Two command buffers, each in a separate QueueSubmit call " |
| 4128 | "on the same queue, no fences, followed by a third QueueSubmit with NO " |
| 4129 | "SubmitInfos but with a fence, followed by a WaitForFences call."); |
| 4130 | |
| 4131 | m_errorMonitor->ExpectSuccess(); |
| 4132 | |
| 4133 | VkFence fence; |
| 4134 | VkFenceCreateInfo fence_create_info{}; |
| 4135 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4136 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4137 | |
| 4138 | VkCommandPool command_pool; |
| 4139 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4140 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4141 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4142 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4143 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4144 | &command_pool); |
| 4145 | |
| 4146 | VkCommandBuffer command_buffer[2]; |
| 4147 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4148 | command_buffer_allocate_info.sType = |
| 4149 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4150 | command_buffer_allocate_info.commandPool = command_pool; |
| 4151 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4152 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4153 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4154 | command_buffer); |
| 4155 | |
| 4156 | { |
| 4157 | VkCommandBufferBeginInfo begin_info{}; |
| 4158 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4159 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4160 | |
| 4161 | vkCmdPipelineBarrier(command_buffer[0], |
| 4162 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4163 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4164 | 0, nullptr, 0, nullptr); |
| 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[0], 0, 1, &viewport); |
| 4174 | vkEndCommandBuffer(command_buffer[0]); |
| 4175 | } |
| 4176 | { |
| 4177 | VkCommandBufferBeginInfo begin_info{}; |
| 4178 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4179 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4180 | |
| 4181 | VkViewport viewport{}; |
| 4182 | viewport.maxDepth = 1.0f; |
| 4183 | viewport.minDepth = 0.0f; |
| 4184 | viewport.width = 512; |
| 4185 | viewport.height = 512; |
| 4186 | viewport.x = 0; |
| 4187 | viewport.y = 0; |
| 4188 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4189 | vkEndCommandBuffer(command_buffer[1]); |
| 4190 | } |
| 4191 | { |
| 4192 | VkSubmitInfo submit_info{}; |
| 4193 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4194 | submit_info.commandBufferCount = 1; |
| 4195 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4196 | submit_info.signalSemaphoreCount = 0; |
| 4197 | submit_info.pSignalSemaphores = VK_NULL_HANDLE; |
| 4198 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4199 | } |
| 4200 | { |
| 4201 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4202 | VkSubmitInfo submit_info{}; |
| 4203 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4204 | submit_info.commandBufferCount = 1; |
| 4205 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4206 | submit_info.waitSemaphoreCount = 0; |
| 4207 | submit_info.pWaitSemaphores = VK_NULL_HANDLE; |
| 4208 | submit_info.pWaitDstStageMask = flags; |
| 4209 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4210 | } |
| 4211 | |
| 4212 | vkQueueSubmit(m_device->m_queue, 0, NULL, fence); |
| 4213 | |
| 4214 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4215 | |
| 4216 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4217 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4218 | &command_buffer[0]); |
| 4219 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4220 | |
| 4221 | m_errorMonitor->VerifyNotFound(); |
| 4222 | } |
| 4223 | |
| 4224 | // This is a positive test. No errors should be generated. |
| 4225 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) { |
| 4226 | |
| 4227 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4228 | "on the same queue, the second having a fence, followed " |
| 4229 | "by a WaitForFences call."); |
| 4230 | |
| 4231 | m_errorMonitor->ExpectSuccess(); |
| 4232 | |
| 4233 | VkFence fence; |
| 4234 | VkFenceCreateInfo fence_create_info{}; |
| 4235 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4236 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4237 | |
| 4238 | VkCommandPool command_pool; |
| 4239 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4240 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4241 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4242 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4243 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4244 | &command_pool); |
| 4245 | |
| 4246 | VkCommandBuffer command_buffer[2]; |
| 4247 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4248 | command_buffer_allocate_info.sType = |
| 4249 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4250 | command_buffer_allocate_info.commandPool = command_pool; |
| 4251 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4252 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4253 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4254 | command_buffer); |
| 4255 | |
| 4256 | { |
| 4257 | VkCommandBufferBeginInfo begin_info{}; |
| 4258 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4259 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4260 | |
| 4261 | vkCmdPipelineBarrier(command_buffer[0], |
| 4262 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4263 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4264 | 0, nullptr, 0, nullptr); |
| 4265 | |
| 4266 | VkViewport viewport{}; |
| 4267 | viewport.maxDepth = 1.0f; |
| 4268 | viewport.minDepth = 0.0f; |
| 4269 | viewport.width = 512; |
| 4270 | viewport.height = 512; |
| 4271 | viewport.x = 0; |
| 4272 | viewport.y = 0; |
| 4273 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4274 | vkEndCommandBuffer(command_buffer[0]); |
| 4275 | } |
| 4276 | { |
| 4277 | VkCommandBufferBeginInfo begin_info{}; |
| 4278 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4279 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4280 | |
| 4281 | VkViewport viewport{}; |
| 4282 | viewport.maxDepth = 1.0f; |
| 4283 | viewport.minDepth = 0.0f; |
| 4284 | viewport.width = 512; |
| 4285 | viewport.height = 512; |
| 4286 | viewport.x = 0; |
| 4287 | viewport.y = 0; |
| 4288 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4289 | vkEndCommandBuffer(command_buffer[1]); |
| 4290 | } |
| 4291 | { |
| 4292 | VkSubmitInfo submit_info{}; |
| 4293 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4294 | submit_info.commandBufferCount = 1; |
| 4295 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4296 | submit_info.signalSemaphoreCount = 0; |
| 4297 | submit_info.pSignalSemaphores = VK_NULL_HANDLE; |
| 4298 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4299 | } |
| 4300 | { |
| 4301 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4302 | VkSubmitInfo submit_info{}; |
| 4303 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4304 | submit_info.commandBufferCount = 1; |
| 4305 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4306 | submit_info.waitSemaphoreCount = 0; |
| 4307 | submit_info.pWaitSemaphores = VK_NULL_HANDLE; |
| 4308 | submit_info.pWaitDstStageMask = flags; |
| 4309 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4310 | } |
| 4311 | |
| 4312 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4313 | |
| 4314 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4315 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4316 | &command_buffer[0]); |
| 4317 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4318 | |
| 4319 | m_errorMonitor->VerifyNotFound(); |
| 4320 | } |
| 4321 | |
| 4322 | // This is a positive test. No errors should be generated. |
| 4323 | TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) { |
| 4324 | |
| 4325 | TEST_DESCRIPTION( |
| 4326 | "Two command buffers each in a separate SubmitInfo sent in a single " |
| 4327 | "QueueSubmit call followed by a WaitForFences call."); |
| 4328 | |
| 4329 | m_errorMonitor->ExpectSuccess(); |
| 4330 | |
| 4331 | VkFence fence; |
| 4332 | VkFenceCreateInfo fence_create_info{}; |
| 4333 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4334 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4335 | |
| 4336 | VkSemaphore semaphore; |
| 4337 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4338 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4339 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4340 | &semaphore); |
| 4341 | |
| 4342 | VkCommandPool command_pool; |
| 4343 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4344 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4345 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4346 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4347 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4348 | &command_pool); |
| 4349 | |
| 4350 | VkCommandBuffer command_buffer[2]; |
| 4351 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4352 | command_buffer_allocate_info.sType = |
| 4353 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4354 | command_buffer_allocate_info.commandPool = command_pool; |
| 4355 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4356 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4357 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4358 | command_buffer); |
| 4359 | |
| 4360 | { |
| 4361 | VkCommandBufferBeginInfo begin_info{}; |
| 4362 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4363 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4364 | |
| 4365 | vkCmdPipelineBarrier(command_buffer[0], |
| 4366 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4367 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4368 | 0, nullptr, 0, nullptr); |
| 4369 | |
| 4370 | VkViewport viewport{}; |
| 4371 | viewport.maxDepth = 1.0f; |
| 4372 | viewport.minDepth = 0.0f; |
| 4373 | viewport.width = 512; |
| 4374 | viewport.height = 512; |
| 4375 | viewport.x = 0; |
| 4376 | viewport.y = 0; |
| 4377 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4378 | vkEndCommandBuffer(command_buffer[0]); |
| 4379 | } |
| 4380 | { |
| 4381 | VkCommandBufferBeginInfo begin_info{}; |
| 4382 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4383 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4384 | |
| 4385 | VkViewport viewport{}; |
| 4386 | viewport.maxDepth = 1.0f; |
| 4387 | viewport.minDepth = 0.0f; |
| 4388 | viewport.width = 512; |
| 4389 | viewport.height = 512; |
| 4390 | viewport.x = 0; |
| 4391 | viewport.y = 0; |
| 4392 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4393 | vkEndCommandBuffer(command_buffer[1]); |
| 4394 | } |
| 4395 | { |
| 4396 | VkSubmitInfo submit_info[2]; |
| 4397 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4398 | |
| 4399 | submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4400 | submit_info[0].pNext = NULL; |
| 4401 | submit_info[0].commandBufferCount = 1; |
| 4402 | submit_info[0].pCommandBuffers = &command_buffer[0]; |
| 4403 | submit_info[0].signalSemaphoreCount = 1; |
| 4404 | submit_info[0].pSignalSemaphores = &semaphore; |
| 4405 | submit_info[0].waitSemaphoreCount = 0; |
| 4406 | submit_info[0].pWaitSemaphores = NULL; |
| 4407 | submit_info[0].pWaitDstStageMask = 0; |
| 4408 | |
| 4409 | submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4410 | submit_info[1].pNext = NULL; |
| 4411 | submit_info[1].commandBufferCount = 1; |
| 4412 | submit_info[1].pCommandBuffers = &command_buffer[1]; |
| 4413 | submit_info[1].waitSemaphoreCount = 1; |
| 4414 | submit_info[1].pWaitSemaphores = &semaphore; |
| 4415 | submit_info[1].pWaitDstStageMask = flags; |
| 4416 | submit_info[1].signalSemaphoreCount = 0; |
| 4417 | submit_info[1].pSignalSemaphores = NULL; |
| 4418 | vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence); |
| 4419 | } |
| 4420 | |
| 4421 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4422 | |
| 4423 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4424 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4425 | &command_buffer[0]); |
| 4426 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 4427 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4428 | |
| 4429 | m_errorMonitor->VerifyNotFound(); |
| 4430 | } |
| 4431 | |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4432 | TEST_F(VkLayerTest, DynamicDepthBiasNotBound) { |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4433 | TEST_DESCRIPTION( |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4434 | "Run a simple draw calls to validate failure when Depth Bias dynamic " |
| 4435 | "state is required but not correctly bound."); |
| 4436 | |
| 4437 | // Dynamic depth bias |
| 4438 | m_errorMonitor->SetDesiredFailureMsg( |
| 4439 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4440 | "Dynamic depth bias state not set for this command buffer"); |
| 4441 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4442 | BsoFailDepthBias); |
| 4443 | m_errorMonitor->VerifyFound(); |
| 4444 | } |
| 4445 | |
| 4446 | TEST_F(VkLayerTest, DynamicLineWidthNotBound) { |
| 4447 | TEST_DESCRIPTION( |
| 4448 | "Run a simple draw calls to validate failure when Line Width dynamic " |
| 4449 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4450 | |
| 4451 | // Dynamic line width |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4452 | m_errorMonitor->SetDesiredFailureMsg( |
| 4453 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4454 | "Dynamic line width state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4455 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4456 | BsoFailLineWidth); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4457 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4458 | } |
| 4459 | |
| 4460 | TEST_F(VkLayerTest, DynamicViewportNotBound) { |
| 4461 | TEST_DESCRIPTION( |
| 4462 | "Run a simple draw calls to validate failure when Viewport dynamic " |
| 4463 | "state is required but not correctly bound."); |
| 4464 | |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4465 | // Dynamic viewport state |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4466 | m_errorMonitor->SetDesiredFailureMsg( |
| 4467 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4468 | "Dynamic viewport state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4469 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4470 | BsoFailViewport); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4471 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4472 | } |
| 4473 | |
| 4474 | TEST_F(VkLayerTest, DynamicScissorNotBound) { |
| 4475 | TEST_DESCRIPTION( |
| 4476 | "Run a simple draw calls to validate failure when Scissor dynamic " |
| 4477 | "state is required but not correctly bound."); |
| 4478 | |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4479 | // Dynamic scissor state |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4480 | m_errorMonitor->SetDesiredFailureMsg( |
| 4481 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4482 | "Dynamic scissor state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4483 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4484 | BsoFailScissor); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4485 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4486 | } |
| 4487 | |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 4488 | TEST_F(VkLayerTest, DynamiBlendConstantsNotBound) { |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4489 | TEST_DESCRIPTION( |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 4490 | "Run a simple draw calls to validate failure when Blend Constants " |
| 4491 | "dynamic state is required but not correctly bound."); |
| 4492 | // Dynamic blend constant state |
| 4493 | m_errorMonitor->SetDesiredFailureMsg( |
| 4494 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4495 | "Dynamic blend constants state not set for this command buffer"); |
| 4496 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4497 | BsoFailBlend); |
| 4498 | m_errorMonitor->VerifyFound(); |
| 4499 | } |
| 4500 | |
| 4501 | TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) { |
| 4502 | TEST_DESCRIPTION( |
| 4503 | "Run a simple draw calls to validate failure when Depth Bounds dynamic " |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4504 | "state is required but not correctly bound."); |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 4505 | if (!m_device->phy().features().depthBounds) { |
| 4506 | printf("Device does not support depthBounds test; skipped.\n"); |
| 4507 | return; |
| 4508 | } |
| 4509 | // Dynamic depth bounds |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4510 | m_errorMonitor->SetDesiredFailureMsg( |
| 4511 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4512 | "Dynamic depth bounds state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4513 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4514 | BsoFailDepthBounds); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4515 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4516 | } |
| 4517 | |
| 4518 | TEST_F(VkLayerTest, DynamicStencilReadNotBound) { |
| 4519 | TEST_DESCRIPTION( |
| 4520 | "Run a simple draw calls to validate failure when Stencil Read dynamic " |
| 4521 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4522 | // Dynamic stencil read mask |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4523 | m_errorMonitor->SetDesiredFailureMsg( |
| 4524 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4525 | "Dynamic stencil read mask state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4526 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4527 | BsoFailStencilReadMask); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4528 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4529 | } |
| 4530 | |
| 4531 | TEST_F(VkLayerTest, DynamicStencilWriteNotBound) { |
| 4532 | TEST_DESCRIPTION( |
| 4533 | "Run a simple draw calls to validate failure when Stencil Write dynamic" |
| 4534 | " state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4535 | // Dynamic stencil write mask |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4536 | m_errorMonitor->SetDesiredFailureMsg( |
| 4537 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4538 | "Dynamic stencil write mask state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4539 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4540 | BsoFailStencilWriteMask); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4541 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4542 | } |
| 4543 | |
| 4544 | TEST_F(VkLayerTest, DynamicStencilRefNotBound) { |
| 4545 | TEST_DESCRIPTION( |
| 4546 | "Run a simple draw calls to validate failure when Stencil Ref dynamic " |
| 4547 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4548 | // Dynamic stencil reference |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4549 | m_errorMonitor->SetDesiredFailureMsg( |
| 4550 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4551 | "Dynamic stencil reference state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4552 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4553 | BsoFailStencilReference); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4554 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 963a404 | 2015-09-29 08:18:34 -0600 | [diff] [blame] | 4555 | } |
| 4556 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4557 | TEST_F(VkLayerTest, CommandBufferTwoSubmits) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4558 | m_errorMonitor->SetDesiredFailureMsg( |
| 4559 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4560 | "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has " |
| 4561 | "been submitted"); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4562 | |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4563 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4564 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 4565 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 4566 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4567 | // We luck out b/c by default the framework creates CB w/ the |
| 4568 | // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4569 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4570 | m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 4571 | m_stencil_clear_color, NULL); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4572 | EndCommandBuffer(); |
| 4573 | |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4574 | // Bypass framework since it does the waits automatically |
| 4575 | VkResult err = VK_SUCCESS; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 4576 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 4577 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4578 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 4579 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 4580 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 4581 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 4582 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 4583 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 4584 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 4585 | submit_info.pSignalSemaphores = NULL; |
| 4586 | |
Chris Forbes | 40028e2 | 2016-06-13 09:59:34 +1200 | [diff] [blame] | 4587 | err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4588 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4589 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4590 | // Cause validation error by re-submitting cmd buffer that should only be |
| 4591 | // submitted once |
Chris Forbes | 40028e2 | 2016-06-13 09:59:34 +1200 | [diff] [blame] | 4592 | err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4593 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4594 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4595 | } |
| 4596 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4597 | TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) { |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4598 | // Initiate Draw w/o a PSO bound |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4599 | VkResult err; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4600 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 4601 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4602 | "Unable to allocate 1 descriptors of " |
| 4603 | "type " |
| 4604 | "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4605 | |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4606 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4607 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4608 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4609 | // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer |
| 4610 | // descriptor from it |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 4611 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4612 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 4613 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4614 | |
| 4615 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4616 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 4617 | ds_pool_ci.pNext = NULL; |
| 4618 | ds_pool_ci.flags = 0; |
| 4619 | ds_pool_ci.maxSets = 1; |
| 4620 | ds_pool_ci.poolSizeCount = 1; |
| 4621 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4622 | |
| 4623 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4624 | err = |
| 4625 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4626 | ASSERT_VK_SUCCESS(err); |
| 4627 | |
| 4628 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4629 | dsl_binding.binding = 0; |
| 4630 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4631 | dsl_binding.descriptorCount = 1; |
| 4632 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 4633 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4634 | |
| 4635 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4636 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4637 | ds_layout_ci.pNext = NULL; |
| 4638 | ds_layout_ci.bindingCount = 1; |
| 4639 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4640 | |
| 4641 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4642 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 4643 | &ds_layout); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4644 | ASSERT_VK_SUCCESS(err); |
| 4645 | |
| 4646 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 4647 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 4648 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4649 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 4650 | alloc_info.descriptorPool = ds_pool; |
| 4651 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4652 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 4653 | &descriptorSet); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4654 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4655 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4656 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 4657 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 4658 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4659 | } |
| 4660 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4661 | TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) { |
| 4662 | VkResult err; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4663 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4664 | m_errorMonitor->SetDesiredFailureMsg( |
| 4665 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4666 | "It is invalid to call vkFreeDescriptorSets() with a pool created " |
| 4667 | "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4668 | |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4669 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4670 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4671 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 4672 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4673 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4674 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4675 | |
| 4676 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4677 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 4678 | ds_pool_ci.pNext = NULL; |
| 4679 | ds_pool_ci.maxSets = 1; |
| 4680 | ds_pool_ci.poolSizeCount = 1; |
| 4681 | ds_pool_ci.flags = 0; |
| 4682 | // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means |
| 4683 | // app can only call vkResetDescriptorPool on this pool.; |
| 4684 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4685 | |
| 4686 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4687 | err = |
| 4688 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4689 | ASSERT_VK_SUCCESS(err); |
| 4690 | |
| 4691 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4692 | dsl_binding.binding = 0; |
| 4693 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4694 | dsl_binding.descriptorCount = 1; |
| 4695 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 4696 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4697 | |
| 4698 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4699 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4700 | ds_layout_ci.pNext = NULL; |
| 4701 | ds_layout_ci.bindingCount = 1; |
| 4702 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4703 | |
| 4704 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4705 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 4706 | &ds_layout); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4707 | ASSERT_VK_SUCCESS(err); |
| 4708 | |
| 4709 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 4710 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 4711 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4712 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 4713 | alloc_info.descriptorPool = ds_pool; |
| 4714 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4715 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 4716 | &descriptorSet); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4717 | ASSERT_VK_SUCCESS(err); |
| 4718 | |
| 4719 | err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4720 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4721 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 4722 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 4723 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4724 | } |
| 4725 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4726 | TEST_F(VkLayerTest, InvalidDescriptorPool) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4727 | // Attempt to clear Descriptor Pool with bad object. |
| 4728 | // ObjectTracker should catch this. |
| 4729 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4730 | "Invalid VkDescriptorPool Object 0xbaad6001"); |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4731 | uint64_t fake_pool_handle = 0xbaad6001; |
| 4732 | VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle); |
| 4733 | vkResetDescriptorPool(device(), bad_pool, 0); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4734 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4735 | } |
| 4736 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4737 | TEST_F(VkLayerTest, InvalidDescriptorSet) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4738 | // Attempt to bind an invalid Descriptor Set to a valid Command Buffer |
| 4739 | // ObjectTracker should catch this. |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4740 | // Create a valid cmd buffer |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4741 | // call vkCmdBindDescriptorSets w/ false Descriptor Set |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4742 | |
| 4743 | uint64_t fake_set_handle = 0xbaad6001; |
| 4744 | VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4745 | VkResult err; |
| 4746 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4747 | "Invalid VkDescriptorSet Object 0xbaad6001"); |
| 4748 | |
| 4749 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4750 | |
| 4751 | VkDescriptorSetLayoutBinding layout_bindings[1] = {}; |
| 4752 | layout_bindings[0].binding = 0; |
| 4753 | layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4754 | layout_bindings[0].descriptorCount = 1; |
| 4755 | layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; |
| 4756 | layout_bindings[0].pImmutableSamplers = NULL; |
| 4757 | |
| 4758 | VkDescriptorSetLayout descriptor_set_layout; |
| 4759 | VkDescriptorSetLayoutCreateInfo dslci = {}; |
| 4760 | dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4761 | dslci.pNext = NULL; |
| 4762 | dslci.bindingCount = 1; |
| 4763 | dslci.pBindings = layout_bindings; |
| 4764 | err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout); |
Karl Schultz | 5cb2111 | 2016-04-21 17:17:40 -0600 | [diff] [blame] | 4765 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4766 | |
| 4767 | VkPipelineLayout pipeline_layout; |
| 4768 | VkPipelineLayoutCreateInfo plci = {}; |
| 4769 | plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 4770 | plci.pNext = NULL; |
| 4771 | plci.setLayoutCount = 1; |
| 4772 | plci.pSetLayouts = &descriptor_set_layout; |
| 4773 | err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout); |
Karl Schultz | 5cb2111 | 2016-04-21 17:17:40 -0600 | [diff] [blame] | 4774 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4775 | |
| 4776 | BeginCommandBuffer(); |
| 4777 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4778 | pipeline_layout, 0, 1, &bad_set, 0, NULL); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4779 | m_errorMonitor->VerifyFound(); |
| 4780 | EndCommandBuffer(); |
| 4781 | vkDestroyPipelineLayout(device(), pipeline_layout, NULL); |
| 4782 | vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4783 | } |
| 4784 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4785 | TEST_F(VkLayerTest, InvalidDescriptorSetLayout) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4786 | // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout. |
| 4787 | // ObjectTracker should catch this. |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4788 | uint64_t fake_layout_handle = 0xbaad6001; |
| 4789 | VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4790 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4791 | "Invalid VkDescriptorSetLayout Object 0xbaad6001"); |
| 4792 | |
| 4793 | VkPipelineLayout pipeline_layout; |
| 4794 | VkPipelineLayoutCreateInfo plci = {}; |
| 4795 | plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 4796 | plci.pNext = NULL; |
| 4797 | plci.setLayoutCount = 1; |
| 4798 | plci.pSetLayouts = &bad_layout; |
| 4799 | vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout); |
| 4800 | |
| 4801 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4802 | } |
| 4803 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4804 | TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) { |
| 4805 | TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec " |
| 4806 | "1) A uniform buffer update must have a valid buffer index." |
| 4807 | "2) When using an array of descriptors in a single WriteDescriptor," |
| 4808 | " the descriptor types and stageflags must all be the same." |
| 4809 | "3) Immutable Sampler state must match across descriptors"); |
| 4810 | |
| 4811 | const char *invalid_BufferInfo_ErrorMessage = |
| 4812 | "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, " |
| 4813 | "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or " |
| 4814 | "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL"; |
| 4815 | const char *stateFlag_ErrorMessage = |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 4816 | "Attempting write update to descriptor set "; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4817 | const char *immutable_ErrorMessage = |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 4818 | "Attempting write update to descriptor set "; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4819 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4820 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage); |
| 4821 | |
| 4822 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4823 | VkDescriptorPoolSize ds_type_count[4] = {}; |
| 4824 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4825 | ds_type_count[0].descriptorCount = 1; |
| 4826 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 4827 | ds_type_count[1].descriptorCount = 1; |
| 4828 | ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 4829 | ds_type_count[2].descriptorCount = 1; |
| 4830 | ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 4831 | ds_type_count[3].descriptorCount = 1; |
| 4832 | |
| 4833 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 4834 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 4835 | ds_pool_ci.maxSets = 1; |
| 4836 | ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize); |
| 4837 | ds_pool_ci.pPoolSizes = ds_type_count; |
| 4838 | |
| 4839 | VkDescriptorPool ds_pool; |
| 4840 | VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 4841 | ASSERT_VK_SUCCESS(err); |
| 4842 | |
Mark Mueller | b989672 | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 4843 | VkDescriptorSetLayoutBinding layout_binding[3] = {}; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4844 | layout_binding[0].binding = 0; |
| 4845 | layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4846 | layout_binding[0].descriptorCount = 1; |
| 4847 | layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 4848 | layout_binding[0].pImmutableSamplers = NULL; |
| 4849 | |
| 4850 | layout_binding[1].binding = 1; |
| 4851 | layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 4852 | layout_binding[1].descriptorCount = 1; |
| 4853 | layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; |
| 4854 | layout_binding[1].pImmutableSamplers = NULL; |
| 4855 | |
| 4856 | VkSamplerCreateInfo sampler_ci = {}; |
| 4857 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 4858 | sampler_ci.pNext = NULL; |
| 4859 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 4860 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 4861 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 4862 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 4863 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 4864 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 4865 | sampler_ci.mipLodBias = 1.0; |
| 4866 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 4867 | sampler_ci.maxAnisotropy = 1; |
| 4868 | sampler_ci.compareEnable = VK_FALSE; |
| 4869 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 4870 | sampler_ci.minLod = 1.0; |
| 4871 | sampler_ci.maxLod = 1.0; |
| 4872 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 4873 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
| 4874 | VkSampler sampler; |
| 4875 | |
| 4876 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
| 4877 | ASSERT_VK_SUCCESS(err); |
| 4878 | |
| 4879 | layout_binding[2].binding = 2; |
| 4880 | layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 4881 | layout_binding[2].descriptorCount = 1; |
| 4882 | layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; |
| 4883 | layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler); |
| 4884 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4885 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 4886 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4887 | ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding); |
| 4888 | ds_layout_ci.pBindings = layout_binding; |
| 4889 | VkDescriptorSetLayout ds_layout; |
| 4890 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout); |
| 4891 | ASSERT_VK_SUCCESS(err); |
| 4892 | |
| 4893 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 4894 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 4895 | alloc_info.descriptorSetCount = 1; |
| 4896 | alloc_info.descriptorPool = ds_pool; |
| 4897 | alloc_info.pSetLayouts = &ds_layout; |
| 4898 | VkDescriptorSet descriptorSet; |
| 4899 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet); |
| 4900 | ASSERT_VK_SUCCESS(err); |
| 4901 | |
| 4902 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 4903 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 4904 | pipeline_layout_ci.pNext = NULL; |
| 4905 | pipeline_layout_ci.setLayoutCount = 1; |
| 4906 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 4907 | |
| 4908 | VkPipelineLayout pipeline_layout; |
| 4909 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout); |
| 4910 | ASSERT_VK_SUCCESS(err); |
| 4911 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 4912 | VkWriteDescriptorSet descriptor_write = {}; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4913 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 4914 | descriptor_write.dstSet = descriptorSet; |
| 4915 | descriptor_write.dstBinding = 0; |
| 4916 | descriptor_write.descriptorCount = 1; |
| 4917 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4918 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 4919 | // 1) The uniform buffer is intentionally invalid here |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4920 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 4921 | m_errorMonitor->VerifyFound(); |
| 4922 | |
| 4923 | // Create a buffer to update the descriptor with |
| 4924 | uint32_t qfi = 0; |
| 4925 | VkBufferCreateInfo buffCI = {}; |
| 4926 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 4927 | buffCI.size = 1024; |
| 4928 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 4929 | buffCI.queueFamilyIndexCount = 1; |
| 4930 | buffCI.pQueueFamilyIndices = &qfi; |
| 4931 | |
| 4932 | VkBuffer dyub; |
| 4933 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 4934 | ASSERT_VK_SUCCESS(err); |
| 4935 | VkDescriptorBufferInfo buffInfo = {}; |
| 4936 | buffInfo.buffer = dyub; |
| 4937 | buffInfo.offset = 0; |
| 4938 | buffInfo.range = 1024; |
| 4939 | |
| 4940 | descriptor_write.pBufferInfo = &buffInfo; |
| 4941 | descriptor_write.descriptorCount = 2; |
| 4942 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 4943 | // 2) The stateFlags don't match between the first and second descriptor |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4944 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage); |
| 4945 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 4946 | m_errorMonitor->VerifyFound(); |
| 4947 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 4948 | // 3) The second descriptor has a null_ptr pImmutableSamplers and |
| 4949 | // the third descriptor contains an immutable sampler |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4950 | descriptor_write.dstBinding = 1; |
| 4951 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 4952 | |
| 4953 | |
| 4954 | // Make pImageInfo index non-null to avoid complaints of it missing |
| 4955 | VkDescriptorImageInfo imageInfo = {}; |
| 4956 | imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 4957 | descriptor_write.pImageInfo = &imageInfo; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4958 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage); |
| 4959 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 4960 | m_errorMonitor->VerifyFound(); |
| 4961 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4962 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
| 4963 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 4964 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 4965 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 4966 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 4967 | } |
| 4968 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4969 | TEST_F(VkLayerTest, InvalidPipeline) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4970 | // Attempt to bind an invalid Pipeline to a valid Command Buffer |
| 4971 | // ObjectTracker should catch this. |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4972 | // Create a valid cmd buffer |
| 4973 | // call vkCmdBindPipeline w/ false Pipeline |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4974 | uint64_t fake_pipeline_handle = 0xbaad6001; |
| 4975 | VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4976 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4977 | "Invalid VkPipeline Object 0xbaad6001"); |
| 4978 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4979 | BeginCommandBuffer(); |
| 4980 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 4981 | VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline); |
| 4982 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 4983 | // Now issue a draw call with no pipeline bound |
| 4984 | m_errorMonitor->SetDesiredFailureMsg( |
| 4985 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4986 | "At Draw/Dispatch time no valid VkPipeline is bound!"); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 4987 | |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 4988 | BeginCommandBuffer(); |
| 4989 | Draw(1, 0, 0, 0); |
| 4990 | m_errorMonitor->VerifyFound(); |
| 4991 | // Finally same check once more but with Dispatch/Compute |
| 4992 | m_errorMonitor->SetDesiredFailureMsg( |
| 4993 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4994 | "At Draw/Dispatch time no valid VkPipeline is bound!"); |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 4995 | BeginCommandBuffer(); |
| 4996 | vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0); |
| 4997 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4998 | } |
| 4999 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5000 | TEST_F(VkLayerTest, DescriptorSetNotUpdated) { |
| 5001 | // Create and update CommandBuffer then call QueueSubmit w/o calling End on |
| 5002 | // CommandBuffer |
| 5003 | VkResult err; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5004 | |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 5005 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5006 | " bound but it was never updated. "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5007 | |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5008 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 5009 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5010 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 5011 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5012 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5013 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5014 | |
| 5015 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5016 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5017 | ds_pool_ci.pNext = NULL; |
| 5018 | ds_pool_ci.maxSets = 1; |
| 5019 | ds_pool_ci.poolSizeCount = 1; |
| 5020 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 5021 | |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5022 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5023 | err = |
| 5024 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5025 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5026 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5027 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5028 | dsl_binding.binding = 0; |
| 5029 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5030 | dsl_binding.descriptorCount = 1; |
| 5031 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5032 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5033 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5034 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5035 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5036 | ds_layout_ci.pNext = NULL; |
| 5037 | ds_layout_ci.bindingCount = 1; |
| 5038 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5039 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5040 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5041 | &ds_layout); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5042 | ASSERT_VK_SUCCESS(err); |
| 5043 | |
| 5044 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5045 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5046 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5047 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 5048 | alloc_info.descriptorPool = ds_pool; |
| 5049 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5050 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5051 | &descriptorSet); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5052 | ASSERT_VK_SUCCESS(err); |
| 5053 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5054 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5055 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5056 | pipeline_layout_ci.pNext = NULL; |
| 5057 | pipeline_layout_ci.setLayoutCount = 1; |
| 5058 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5059 | |
| 5060 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5061 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5062 | &pipeline_layout); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5063 | ASSERT_VK_SUCCESS(err); |
| 5064 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5065 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 5066 | VK_SHADER_STAGE_VERTEX_BIT, this); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5067 | // 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] | 5068 | // on more devices |
| 5069 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 5070 | VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5071 | |
Tony Barbour | c95e4ac | 2015-08-04 17:05:26 -0600 | [diff] [blame] | 5072 | VkPipelineObj pipe(m_device); |
| 5073 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 5074 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 5075 | pipe.AddColorAttachment(); |
Tony Barbour | c95e4ac | 2015-08-04 17:05:26 -0600 | [diff] [blame] | 5076 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 5077 | |
| 5078 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5079 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 5080 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 5081 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5082 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5083 | 1, &descriptorSet, 0, NULL); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5084 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5085 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 5086 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 5087 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5088 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5089 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 5090 | } |
| 5091 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5092 | TEST_F(VkLayerTest, InvalidBufferViewObject) { |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5093 | // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5094 | VkResult err; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5095 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5096 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5097 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer " |
| 5098 | "descriptor with invalid buffer view"); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5099 | |
| 5100 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5101 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5102 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5103 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5104 | |
| 5105 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5106 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5107 | ds_pool_ci.pNext = NULL; |
| 5108 | ds_pool_ci.maxSets = 1; |
| 5109 | ds_pool_ci.poolSizeCount = 1; |
| 5110 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5111 | |
| 5112 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5113 | err = |
| 5114 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5115 | ASSERT_VK_SUCCESS(err); |
| 5116 | |
| 5117 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5118 | dsl_binding.binding = 0; |
| 5119 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5120 | dsl_binding.descriptorCount = 1; |
| 5121 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5122 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5123 | |
| 5124 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5125 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5126 | ds_layout_ci.pNext = NULL; |
| 5127 | ds_layout_ci.bindingCount = 1; |
| 5128 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5129 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5130 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5131 | &ds_layout); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5132 | ASSERT_VK_SUCCESS(err); |
| 5133 | |
| 5134 | VkDescriptorSet descriptorSet; |
| 5135 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5136 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5137 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5138 | alloc_info.descriptorPool = ds_pool; |
| 5139 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5140 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5141 | &descriptorSet); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5142 | ASSERT_VK_SUCCESS(err); |
| 5143 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5144 | VkBufferView view = |
| 5145 | (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5146 | VkWriteDescriptorSet descriptor_write; |
| 5147 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 5148 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5149 | descriptor_write.dstSet = descriptorSet; |
| 5150 | descriptor_write.dstBinding = 0; |
| 5151 | descriptor_write.descriptorCount = 1; |
| 5152 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5153 | descriptor_write.pTexelBufferView = &view; |
| 5154 | |
| 5155 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5156 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5157 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5158 | |
| 5159 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5160 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 5161 | } |
| 5162 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5163 | TEST_F(VkLayerTest, InvalidDynamicOffsetCases) { |
| 5164 | // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error |
| 5165 | // cases: |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5166 | // 1. No dynamicOffset supplied |
| 5167 | // 2. Too many dynamicOffsets supplied |
| 5168 | // 3. Dynamic offset oversteps buffer being updated |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5169 | VkResult err; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 5170 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5171 | " requires 1 dynamicOffsets, but only " |
| 5172 | "0 dynamicOffsets are left in " |
| 5173 | "pDynamicOffsets "); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5174 | |
| 5175 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5176 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5177 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5178 | |
| 5179 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5180 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 5181 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5182 | |
| 5183 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5184 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5185 | ds_pool_ci.pNext = NULL; |
| 5186 | ds_pool_ci.maxSets = 1; |
| 5187 | ds_pool_ci.poolSizeCount = 1; |
| 5188 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5189 | |
| 5190 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5191 | err = |
| 5192 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5193 | ASSERT_VK_SUCCESS(err); |
| 5194 | |
| 5195 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5196 | dsl_binding.binding = 0; |
| 5197 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 5198 | dsl_binding.descriptorCount = 1; |
| 5199 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5200 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5201 | |
| 5202 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5203 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5204 | ds_layout_ci.pNext = NULL; |
| 5205 | ds_layout_ci.bindingCount = 1; |
| 5206 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5207 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5208 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5209 | &ds_layout); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5210 | ASSERT_VK_SUCCESS(err); |
| 5211 | |
| 5212 | VkDescriptorSet descriptorSet; |
| 5213 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5214 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5215 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5216 | alloc_info.descriptorPool = ds_pool; |
| 5217 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5218 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5219 | &descriptorSet); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5220 | ASSERT_VK_SUCCESS(err); |
| 5221 | |
| 5222 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5223 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5224 | pipeline_layout_ci.pNext = NULL; |
| 5225 | pipeline_layout_ci.setLayoutCount = 1; |
| 5226 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5227 | |
| 5228 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5229 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5230 | &pipeline_layout); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5231 | ASSERT_VK_SUCCESS(err); |
| 5232 | |
| 5233 | // Create a buffer to update the descriptor with |
| 5234 | uint32_t qfi = 0; |
| 5235 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5236 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 5237 | buffCI.size = 1024; |
| 5238 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 5239 | buffCI.queueFamilyIndexCount = 1; |
| 5240 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5241 | |
| 5242 | VkBuffer dyub; |
| 5243 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 5244 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5245 | // Allocate memory and bind to buffer so we can make it to the appropriate |
| 5246 | // error |
| 5247 | VkMemoryAllocateInfo mem_alloc = {}; |
| 5248 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 5249 | mem_alloc.pNext = NULL; |
| 5250 | mem_alloc.allocationSize = 1024; |
Chris Forbes | b6116cc | 2016-05-08 11:39:59 +1200 | [diff] [blame] | 5251 | mem_alloc.memoryTypeIndex = 0; |
| 5252 | |
| 5253 | VkMemoryRequirements memReqs; |
| 5254 | vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs); |
| 5255 | bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, |
| 5256 | 0); |
| 5257 | if (!pass) { |
| 5258 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
| 5259 | return; |
| 5260 | } |
| 5261 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5262 | VkDeviceMemory mem; |
| 5263 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 5264 | ASSERT_VK_SUCCESS(err); |
| 5265 | err = vkBindBufferMemory(m_device->device(), dyub, mem, 0); |
| 5266 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5267 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 5268 | VkDescriptorBufferInfo buffInfo = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5269 | buffInfo.buffer = dyub; |
| 5270 | buffInfo.offset = 0; |
| 5271 | buffInfo.range = 1024; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5272 | |
| 5273 | VkWriteDescriptorSet descriptor_write; |
| 5274 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 5275 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5276 | descriptor_write.dstSet = descriptorSet; |
| 5277 | descriptor_write.dstBinding = 0; |
| 5278 | descriptor_write.descriptorCount = 1; |
| 5279 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 5280 | descriptor_write.pBufferInfo = &buffInfo; |
| 5281 | |
| 5282 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5283 | |
| 5284 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5285 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5286 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5287 | 1, &descriptorSet, 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5288 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5289 | uint32_t pDynOff[2] = {512, 756}; |
| 5290 | // 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] | 5291 | m_errorMonitor->SetDesiredFailureMsg( |
| 5292 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5293 | "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5294 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5295 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5296 | 1, &descriptorSet, 2, pDynOff); |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5297 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5298 | // Finally cause error due to dynamicOffset being too big |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5299 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5300 | " dynamic offset 512 combined with " |
| 5301 | "offset 0 and range 1024 that " |
| 5302 | "oversteps the buffer size of 1024"); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5303 | // Create PSO to be used for draw-time errors below |
| 5304 | char const *vsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5305 | "#version 450\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5306 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 5307 | "out gl_PerVertex { \n" |
| 5308 | " vec4 gl_Position;\n" |
| 5309 | "};\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5310 | "void main(){\n" |
| 5311 | " gl_Position = vec4(1);\n" |
| 5312 | "}\n"; |
| 5313 | char const *fsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5314 | "#version 450\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5315 | "\n" |
| 5316 | "layout(location=0) out vec4 x;\n" |
| 5317 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 5318 | "void main(){\n" |
| 5319 | " x = vec4(bar.y);\n" |
| 5320 | "}\n"; |
| 5321 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 5322 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 5323 | VkPipelineObj pipe(m_device); |
| 5324 | pipe.AddShader(&vs); |
| 5325 | pipe.AddShader(&fs); |
| 5326 | pipe.AddColorAttachment(); |
| 5327 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 5328 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5329 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 5330 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 5331 | // This update should succeed, but offset size of 512 will overstep buffer |
| 5332 | // /w range 1024 & size 1024 |
| 5333 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5334 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5335 | 1, &descriptorSet, 1, pDynOff); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5336 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5337 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5338 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5339 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
Tobin Ehlis | 512098e | 2016-05-05 09:06:12 -0600 | [diff] [blame] | 5340 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5341 | |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5342 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 5343 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5344 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 5345 | } |
| 5346 | |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5347 | TEST_F(VkLayerTest, InvalidPushConstants) { |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5348 | VkResult err; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5349 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5350 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5351 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5352 | |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5353 | VkPipelineLayout pipeline_layout; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5354 | VkPushConstantRange pc_range = {}; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5355 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 5356 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5357 | pipeline_layout_ci.pushConstantRangeCount = 1; |
| 5358 | pipeline_layout_ci.pPushConstantRanges = &pc_range; |
| 5359 | |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5360 | // |
| 5361 | // Check for invalid push constant ranges in pipeline layouts. |
| 5362 | // |
| 5363 | struct PipelineLayoutTestCase { |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5364 | VkPushConstantRange const range; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5365 | char const *msg; |
| 5366 | }; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5367 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5368 | const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4; |
| 5369 | const std::array<PipelineLayoutTestCase, 10> range_tests = {{ |
| 5370 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, |
| 5371 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5372 | "size 0."}, |
| 5373 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1}, |
| 5374 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5375 | "size 1."}, |
| 5376 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1}, |
| 5377 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5378 | "size 1."}, |
| 5379 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0}, |
| 5380 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5381 | "size 0."}, |
| 5382 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4}, |
| 5383 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5384 | "offset 1. Offset must"}, |
| 5385 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big}, |
| 5386 | "vkCreatePipelineLayout() call has push constants index 0 " |
| 5387 | "with offset "}, |
| 5388 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big}, |
| 5389 | "vkCreatePipelineLayout() call has push constants " |
| 5390 | "index 0 with offset "}, |
| 5391 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0}, |
| 5392 | "vkCreatePipelineLayout() call has push constants index 0 " |
| 5393 | "with offset "}, |
| 5394 | {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020}, |
| 5395 | "vkCreatePipelineLayout() call has push " |
| 5396 | "constants index 0 with offset "}, |
| 5397 | {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0}, |
| 5398 | "vkCreatePipelineLayout() call has push " |
| 5399 | "constants index 0 with offset "}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5400 | }}; |
| 5401 | |
| 5402 | // Check for invalid offset and size |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5403 | for (const auto &iter : range_tests) { |
| 5404 | pc_range = iter.range; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5405 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5406 | iter.msg); |
| 5407 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 5408 | NULL, &pipeline_layout); |
| 5409 | m_errorMonitor->VerifyFound(); |
| 5410 | if (VK_SUCCESS == err) { |
| 5411 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5412 | } |
| 5413 | } |
| 5414 | |
| 5415 | // Check for invalid stage flag |
| 5416 | pc_range.offset = 0; |
| 5417 | pc_range.size = 16; |
| 5418 | pc_range.stageFlags = 0; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5419 | m_errorMonitor->SetDesiredFailureMsg( |
| 5420 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5421 | "vkCreatePipelineLayout() call has no stageFlags set."); |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5422 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5423 | &pipeline_layout); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5424 | m_errorMonitor->VerifyFound(); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5425 | if (VK_SUCCESS == err) { |
| 5426 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5427 | } |
| 5428 | |
| 5429 | // Check for overlapping ranges |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5430 | const uint32_t ranges_per_test = 5; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5431 | struct OverlappingRangeTestCase { |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5432 | VkPushConstantRange const ranges[ranges_per_test]; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5433 | char const *msg; |
| 5434 | }; |
| 5435 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5436 | const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5437 | {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5438 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5439 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5440 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5441 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5442 | "vkCreatePipelineLayout() call has push constants with overlapping " |
| 5443 | "ranges: 0:[0, 4), 1:[0, 4)"}, |
| 5444 | { |
| 5445 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5446 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5447 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5448 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 5449 | {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}}, |
| 5450 | "vkCreatePipelineLayout() call has push constants with " |
| 5451 | "overlapping " |
| 5452 | "ranges: 3:[12, 20), 4:[16, 20)", |
| 5453 | }, |
| 5454 | { |
| 5455 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5456 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 5457 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5458 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5459 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5460 | "vkCreatePipelineLayout() call has push constants with " |
| 5461 | "overlapping " |
| 5462 | "ranges: 0:[16, 20), 1:[12, 20)", |
| 5463 | }, |
| 5464 | { |
| 5465 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5466 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5467 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5468 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 5469 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5470 | "vkCreatePipelineLayout() call has push constants with " |
| 5471 | "overlapping " |
| 5472 | "ranges: 0:[16, 20), 3:[12, 20)", |
| 5473 | }, |
| 5474 | { |
| 5475 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5476 | {VK_SHADER_STAGE_VERTEX_BIT, 32, 4}, |
| 5477 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 96}, |
| 5478 | {VK_SHADER_STAGE_VERTEX_BIT, 40, 8}, |
| 5479 | {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}}, |
| 5480 | "vkCreatePipelineLayout() call has push constants with " |
| 5481 | "overlapping " |
| 5482 | "ranges: 0:[16, 20), 2:[4, 100)", |
| 5483 | }}}; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5484 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5485 | for (const auto &iter : overlapping_range_tests) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5486 | pipeline_layout_ci.pPushConstantRanges = iter.ranges; |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5487 | pipeline_layout_ci.pushConstantRangeCount = ranges_per_test; |
| 5488 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5489 | iter.msg); |
| 5490 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 5491 | NULL, &pipeline_layout); |
| 5492 | m_errorMonitor->VerifyFound(); |
| 5493 | if (VK_SUCCESS == err) { |
| 5494 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5495 | } |
| 5496 | } |
| 5497 | |
| 5498 | // 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] | 5499 | const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = |
| 5500 | {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5501 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5502 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5503 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 4}, |
| 5504 | {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}}, |
| 5505 | ""}, |
| 5506 | {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24}, |
| 5507 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 4}, |
| 5508 | {VK_SHADER_STAGE_VERTEX_BIT, 64, 8}, |
| 5509 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 16}, |
| 5510 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5511 | ""}}}; |
| 5512 | for (const auto &iter : overlapping_range_tests_pos) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5513 | pipeline_layout_ci.pPushConstantRanges = iter.ranges; |
| 5514 | m_errorMonitor->ExpectSuccess(); |
| 5515 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 5516 | NULL, &pipeline_layout); |
| 5517 | m_errorMonitor->VerifyNotFound(); |
| 5518 | if (VK_SUCCESS == err) { |
| 5519 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5520 | } |
| 5521 | } |
| 5522 | |
| 5523 | // |
| 5524 | // CmdPushConstants tests |
| 5525 | // |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5526 | const uint8_t dummy_values[100] = {}; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5527 | |
| 5528 | // 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] | 5529 | const std::array<PipelineLayoutTestCase, 16> cmd_range_tests = {{ |
| 5530 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, |
| 5531 | "vkCmdPushConstants() call has push constants with size 0. Size " |
| 5532 | "must be greater than zero and a multiple of 4."}, |
| 5533 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1}, |
| 5534 | "vkCmdPushConstants() call has push constants with size 1. Size " |
| 5535 | "must be greater than zero and a multiple of 4."}, |
| 5536 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1}, |
| 5537 | "vkCmdPushConstants() call has push constants with size 1. Size " |
| 5538 | "must be greater than zero and a multiple of 4."}, |
| 5539 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0}, |
| 5540 | "vkCmdPushConstants() call has push constants with offset 1. " |
| 5541 | "Offset must be a multiple of 4."}, |
| 5542 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4}, |
| 5543 | "vkCmdPushConstants() call has push constants with offset 1. " |
| 5544 | "Offset must be a multiple of 4."}, |
| 5545 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20}, |
| 5546 | "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = " |
| 5547 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5548 | {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8}, |
| 5549 | "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = " |
| 5550 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5551 | {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8}, |
| 5552 | "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = " |
| 5553 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5554 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80}, |
| 5555 | "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = " |
| 5556 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5557 | {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4}, |
| 5558 | "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in " |
| 5559 | "any of the ranges in pipeline layout"}, |
| 5560 | {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, |
| 5561 | 0, 16}, |
| 5562 | "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in " |
| 5563 | "any of the ranges in pipeline layout"}, |
| 5564 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5565 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5566 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5567 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5568 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5569 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5570 | {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5571 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5572 | {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5573 | "vkCmdPushConstants() call has push constants with offset "}, |
| 5574 | }}; |
| 5575 | |
| 5576 | // Two ranges for testing robustness |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5577 | const VkPushConstantRange pc_range2[] = { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5578 | {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5579 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5580 | }; |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5581 | pipeline_layout_ci.pushConstantRangeCount = |
| 5582 | sizeof(pc_range2) / sizeof(VkPushConstantRange); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5583 | pipeline_layout_ci.pPushConstantRanges = pc_range2; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5584 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5585 | &pipeline_layout); |
| 5586 | ASSERT_VK_SUCCESS(err); |
| 5587 | BeginCommandBuffer(); |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5588 | for (const auto &iter : cmd_range_tests) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5589 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5590 | iter.msg); |
| 5591 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5592 | iter.range.stageFlags, iter.range.offset, |
| 5593 | iter.range.size, dummy_values); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5594 | m_errorMonitor->VerifyFound(); |
| 5595 | } |
| 5596 | |
| 5597 | // Check for invalid stage flag |
| 5598 | m_errorMonitor->SetDesiredFailureMsg( |
| 5599 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5600 | "vkCmdPushConstants() call has no stageFlags set."); |
| 5601 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5602 | 0, 16, dummy_values); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5603 | m_errorMonitor->VerifyFound(); |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5604 | EndCommandBuffer(); |
| 5605 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
| 5606 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5607 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5608 | // overlapping range tests with cmd |
| 5609 | const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{ |
| 5610 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20}, |
| 5611 | "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = " |
| 5612 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5613 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5614 | "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = " |
| 5615 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5616 | {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16}, |
| 5617 | "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = " |
| 5618 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5619 | }}; |
| 5620 | const VkPushConstantRange pc_range3[] = { |
| 5621 | {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, |
| 5622 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
| 5623 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5624 | {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, |
| 5625 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, |
| 5626 | {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, |
| 5627 | {VK_SHADER_STAGE_VERTEX_BIT, 56, 28}, |
| 5628 | }; |
| 5629 | pipeline_layout_ci.pushConstantRangeCount = |
| 5630 | sizeof(pc_range3) / sizeof(VkPushConstantRange); |
| 5631 | pipeline_layout_ci.pPushConstantRanges = pc_range3; |
| 5632 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5633 | &pipeline_layout); |
| 5634 | ASSERT_VK_SUCCESS(err); |
| 5635 | BeginCommandBuffer(); |
| 5636 | for (const auto &iter : cmd_overlap_tests) { |
| 5637 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5638 | iter.msg); |
| 5639 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
| 5640 | iter.range.stageFlags, iter.range.offset, |
| 5641 | iter.range.size, dummy_values); |
| 5642 | m_errorMonitor->VerifyFound(); |
| 5643 | } |
| 5644 | EndCommandBuffer(); |
| 5645 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
| 5646 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5647 | |
| 5648 | // positive overlapping range tests with cmd |
| 5649 | const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{ |
| 5650 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""}, |
| 5651 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""}, |
| 5652 | {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""}, |
| 5653 | {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""}, |
| 5654 | }}; |
| 5655 | const VkPushConstantRange pc_range4[] = { |
| 5656 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 64}, |
| 5657 | {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, |
| 5658 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
| 5659 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5660 | {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, |
| 5661 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, |
| 5662 | {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, |
| 5663 | {VK_SHADER_STAGE_VERTEX_BIT, 56, 28}, |
| 5664 | }; |
| 5665 | pipeline_layout_ci.pushConstantRangeCount = |
| 5666 | sizeof(pc_range4) / sizeof(VkPushConstantRange); |
| 5667 | pipeline_layout_ci.pPushConstantRanges = pc_range4; |
| 5668 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5669 | &pipeline_layout); |
| 5670 | ASSERT_VK_SUCCESS(err); |
| 5671 | BeginCommandBuffer(); |
| 5672 | for (const auto &iter : cmd_overlap_tests_pos) { |
| 5673 | m_errorMonitor->ExpectSuccess(); |
| 5674 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
| 5675 | iter.range.stageFlags, iter.range.offset, |
| 5676 | iter.range.size, dummy_values); |
| 5677 | m_errorMonitor->VerifyNotFound(); |
| 5678 | } |
| 5679 | EndCommandBuffer(); |
| 5680 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5681 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5682 | } |
| 5683 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5684 | TEST_F(VkLayerTest, DescriptorSetCompatibility) { |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5685 | // Test various desriptorSet errors with bad binding combinations |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5686 | VkResult err; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5687 | |
| 5688 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5689 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5690 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5691 | |
| 5692 | static const uint32_t NUM_DESCRIPTOR_TYPES = 5; |
| 5693 | VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5694 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5695 | ds_type_count[0].descriptorCount = 10; |
| 5696 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 5697 | ds_type_count[1].descriptorCount = 2; |
| 5698 | ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
| 5699 | ds_type_count[2].descriptorCount = 2; |
| 5700 | ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 5701 | ds_type_count[3].descriptorCount = 5; |
| 5702 | // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT |
| 5703 | // type |
| 5704 | // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 5705 | ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
| 5706 | ds_type_count[4].descriptorCount = 2; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5707 | |
| 5708 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5709 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5710 | ds_pool_ci.pNext = NULL; |
| 5711 | ds_pool_ci.maxSets = 5; |
| 5712 | ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES; |
| 5713 | ds_pool_ci.pPoolSizes = ds_type_count; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5714 | |
| 5715 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5716 | err = |
| 5717 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5718 | ASSERT_VK_SUCCESS(err); |
| 5719 | |
| 5720 | static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2; |
| 5721 | VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5722 | dsl_binding[0].binding = 0; |
| 5723 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5724 | dsl_binding[0].descriptorCount = 5; |
| 5725 | dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 5726 | dsl_binding[0].pImmutableSamplers = NULL; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5727 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5728 | // Create layout identical to set0 layout but w/ different stageFlags |
| 5729 | VkDescriptorSetLayoutBinding dsl_fs_stage_only = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5730 | dsl_fs_stage_only.binding = 0; |
| 5731 | dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5732 | dsl_fs_stage_only.descriptorCount = 5; |
| 5733 | dsl_fs_stage_only.stageFlags = |
| 5734 | VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at |
| 5735 | // bind time |
| 5736 | dsl_fs_stage_only.pImmutableSamplers = NULL; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5737 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5738 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5739 | ds_layout_ci.pNext = NULL; |
| 5740 | ds_layout_ci.bindingCount = 1; |
| 5741 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5742 | static const uint32_t NUM_LAYOUTS = 4; |
| 5743 | VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5744 | VkDescriptorSetLayout ds_layout_fs_only = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5745 | // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only |
| 5746 | // layout for error case |
| 5747 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5748 | &ds_layout[0]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5749 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 5750 | ds_layout_ci.pBindings = &dsl_fs_stage_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5751 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5752 | &ds_layout_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5753 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5754 | dsl_binding[0].binding = 0; |
| 5755 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5756 | dsl_binding[0].descriptorCount = 2; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 5757 | dsl_binding[1].binding = 1; |
| 5758 | dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
| 5759 | dsl_binding[1].descriptorCount = 2; |
| 5760 | dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL; |
| 5761 | dsl_binding[1].pImmutableSamplers = NULL; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 5762 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5763 | ds_layout_ci.bindingCount = 2; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5764 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5765 | &ds_layout[1]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5766 | ASSERT_VK_SUCCESS(err); |
| 5767 | dsl_binding[0].binding = 0; |
| 5768 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5769 | dsl_binding[0].descriptorCount = 5; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5770 | ds_layout_ci.bindingCount = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5771 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5772 | &ds_layout[2]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5773 | ASSERT_VK_SUCCESS(err); |
| 5774 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5775 | dsl_binding[0].descriptorCount = 2; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5776 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5777 | &ds_layout[3]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5778 | ASSERT_VK_SUCCESS(err); |
| 5779 | |
| 5780 | static const uint32_t NUM_SETS = 4; |
| 5781 | VkDescriptorSet descriptorSet[NUM_SETS] = {}; |
| 5782 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5783 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5784 | alloc_info.descriptorSetCount = NUM_LAYOUTS; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5785 | alloc_info.descriptorPool = ds_pool; |
| 5786 | alloc_info.pSetLayouts = ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5787 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5788 | descriptorSet); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5789 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5790 | VkDescriptorSet ds0_fs_only = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5791 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5792 | alloc_info.pSetLayouts = &ds_layout_fs_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5793 | err = |
| 5794 | vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5795 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5796 | |
| 5797 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5798 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5799 | pipeline_layout_ci.pNext = NULL; |
| 5800 | pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS; |
| 5801 | pipeline_layout_ci.pSetLayouts = ds_layout; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5802 | |
| 5803 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5804 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5805 | &pipeline_layout); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5806 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5807 | // Create pipelineLayout with only one setLayout |
| 5808 | pipeline_layout_ci.setLayoutCount = 1; |
| 5809 | VkPipelineLayout single_pipe_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5810 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5811 | &single_pipe_layout); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5812 | ASSERT_VK_SUCCESS(err); |
| 5813 | // Create pipelineLayout with 2 descriptor setLayout at index 0 |
| 5814 | pipeline_layout_ci.pSetLayouts = &ds_layout[3]; |
| 5815 | VkPipelineLayout pipe_layout_one_desc; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5816 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5817 | &pipe_layout_one_desc); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5818 | ASSERT_VK_SUCCESS(err); |
| 5819 | // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0 |
| 5820 | pipeline_layout_ci.pSetLayouts = &ds_layout[2]; |
| 5821 | VkPipelineLayout pipe_layout_five_samp; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5822 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5823 | &pipe_layout_five_samp); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5824 | ASSERT_VK_SUCCESS(err); |
| 5825 | // Create pipelineLayout with UB type, but stageFlags for FS only |
| 5826 | pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only; |
| 5827 | VkPipelineLayout pipe_layout_fs_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5828 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5829 | &pipe_layout_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5830 | ASSERT_VK_SUCCESS(err); |
| 5831 | // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine |
| 5832 | VkDescriptorSetLayout pl_bad_s0[2] = {}; |
| 5833 | pl_bad_s0[0] = ds_layout_fs_only; |
| 5834 | pl_bad_s0[1] = ds_layout[1]; |
| 5835 | pipeline_layout_ci.setLayoutCount = 2; |
| 5836 | pipeline_layout_ci.pSetLayouts = pl_bad_s0; |
| 5837 | VkPipelineLayout pipe_layout_bad_set0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5838 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5839 | &pipe_layout_bad_set0); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5840 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5841 | |
| 5842 | // Create a buffer to update the descriptor with |
| 5843 | uint32_t qfi = 0; |
| 5844 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5845 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 5846 | buffCI.size = 1024; |
| 5847 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 5848 | buffCI.queueFamilyIndexCount = 1; |
| 5849 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5850 | |
| 5851 | VkBuffer dyub; |
| 5852 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 5853 | ASSERT_VK_SUCCESS(err); |
| 5854 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 5855 | static const uint32_t NUM_BUFFS = 5; |
| 5856 | VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5857 | for (uint32_t i = 0; i < NUM_BUFFS; ++i) { |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5858 | buffInfo[i].buffer = dyub; |
| 5859 | buffInfo[i].offset = 0; |
| 5860 | buffInfo[i].range = 1024; |
| 5861 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5862 | VkImage image; |
| 5863 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 5864 | const int32_t tex_width = 32; |
| 5865 | const int32_t tex_height = 32; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5866 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5867 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 5868 | image_create_info.pNext = NULL; |
| 5869 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 5870 | image_create_info.format = tex_format; |
| 5871 | image_create_info.extent.width = tex_width; |
| 5872 | image_create_info.extent.height = tex_height; |
| 5873 | image_create_info.extent.depth = 1; |
| 5874 | image_create_info.mipLevels = 1; |
| 5875 | image_create_info.arrayLayers = 1; |
| 5876 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 5877 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 5878 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 5879 | image_create_info.flags = 0; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5880 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 5881 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5882 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5883 | VkMemoryRequirements memReqs; |
| 5884 | VkDeviceMemory imageMem; |
| 5885 | bool pass; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 5886 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5887 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 5888 | memAlloc.pNext = NULL; |
| 5889 | memAlloc.allocationSize = 0; |
| 5890 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 5891 | vkGetImageMemoryRequirements(m_device->device(), image, &memReqs); |
| 5892 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5893 | pass = |
| 5894 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 5895 | ASSERT_TRUE(pass); |
| 5896 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem); |
| 5897 | ASSERT_VK_SUCCESS(err); |
| 5898 | err = vkBindImageMemory(m_device->device(), image, imageMem, 0); |
| 5899 | ASSERT_VK_SUCCESS(err); |
| 5900 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5901 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5902 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 5903 | image_view_create_info.image = image; |
| 5904 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 5905 | image_view_create_info.format = tex_format; |
| 5906 | image_view_create_info.subresourceRange.layerCount = 1; |
| 5907 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 5908 | image_view_create_info.subresourceRange.levelCount = 1; |
| 5909 | image_view_create_info.subresourceRange.aspectMask = |
| 5910 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5911 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5912 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5913 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 5914 | &view); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5915 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 5916 | VkDescriptorImageInfo imageInfo[4] = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5917 | imageInfo[0].imageView = view; |
| 5918 | imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 5919 | imageInfo[1].imageView = view; |
| 5920 | imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 5921 | imageInfo[2].imageView = view; |
| 5922 | imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 5923 | imageInfo[3].imageView = view; |
| 5924 | imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5925 | |
| 5926 | static const uint32_t NUM_SET_UPDATES = 3; |
| 5927 | VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {}; |
| 5928 | descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5929 | descriptor_write[0].dstSet = descriptorSet[0]; |
| 5930 | descriptor_write[0].dstBinding = 0; |
| 5931 | descriptor_write[0].descriptorCount = 5; |
| 5932 | descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5933 | descriptor_write[0].pBufferInfo = buffInfo; |
| 5934 | descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5935 | descriptor_write[1].dstSet = descriptorSet[1]; |
| 5936 | descriptor_write[1].dstBinding = 0; |
| 5937 | descriptor_write[1].descriptorCount = 2; |
| 5938 | descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 5939 | descriptor_write[1].pImageInfo = imageInfo; |
| 5940 | descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5941 | descriptor_write[2].dstSet = descriptorSet[1]; |
| 5942 | descriptor_write[2].dstBinding = 1; |
| 5943 | descriptor_write[2].descriptorCount = 2; |
| 5944 | descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 5945 | descriptor_write[2].pImageInfo = &imageInfo[2]; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5946 | |
| 5947 | vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5948 | |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 5949 | // Create PSO to be used for draw-time errors below |
| 5950 | char const *vsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5951 | "#version 450\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 5952 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 5953 | "out gl_PerVertex {\n" |
| 5954 | " vec4 gl_Position;\n" |
| 5955 | "};\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 5956 | "void main(){\n" |
| 5957 | " gl_Position = vec4(1);\n" |
| 5958 | "}\n"; |
| 5959 | char const *fsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5960 | "#version 450\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 5961 | "\n" |
| 5962 | "layout(location=0) out vec4 x;\n" |
| 5963 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 5964 | "void main(){\n" |
| 5965 | " x = vec4(bar.y);\n" |
| 5966 | "}\n"; |
| 5967 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 5968 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5969 | VkPipelineObj pipe(m_device); |
| 5970 | pipe.AddShader(&vs); |
| 5971 | pipe.AddShader(&fs); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 5972 | pipe.AddColorAttachment(); |
| 5973 | pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass()); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5974 | |
| 5975 | BeginCommandBuffer(); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 5976 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5977 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 5978 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 5979 | // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding |
| 5980 | // of PSO |
| 5981 | // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of |
| 5982 | // cmd_pipeline.c |
| 5983 | // due to the fact that cmd_alloc_dset_data() has not been called in |
| 5984 | // cmd_bind_graphics_pipeline() |
| 5985 | // TODO : Want to cause various binding incompatibility issues here to test |
| 5986 | // DrawState |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5987 | // First cause various verify_layout_compatibility() fails |
| 5988 | // Second disturb early and late sets and verify INFO msgs |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5989 | // verify_set_layout_compatibility fail cases: |
| 5990 | // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5991 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5992 | " due to: invalid VkPipelineLayout "); |
| 5993 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5994 | VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 5995 | (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, |
| 5996 | &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5997 | m_errorMonitor->VerifyFound(); |
| 5998 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5999 | // 2. layoutIndex exceeds # of layouts in layout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6000 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6001 | " attempting to bind set to index 1"); |
| 6002 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6003 | VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, |
| 6004 | 0, 2, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6005 | m_errorMonitor->VerifyFound(); |
| 6006 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6007 | vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6008 | // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5 |
| 6009 | // descriptors |
| 6010 | m_errorMonitor->SetDesiredFailureMsg( |
| 6011 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 6012 | " has 2 descriptors, but DescriptorSetLayout "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6013 | vkCmdBindDescriptorSets( |
| 6014 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6015 | pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6016 | m_errorMonitor->VerifyFound(); |
| 6017 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6018 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL); |
| 6019 | // 4. same # of descriptors but mismatch in type |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6020 | m_errorMonitor->SetDesiredFailureMsg( |
| 6021 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 6022 | " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6023 | vkCmdBindDescriptorSets( |
| 6024 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6025 | pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6026 | m_errorMonitor->VerifyFound(); |
| 6027 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6028 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL); |
| 6029 | // 5. same # of descriptors but mismatch in stageFlags |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6030 | m_errorMonitor->SetDesiredFailureMsg( |
| 6031 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 6032 | " has stageFlags 16 but binding 0 for DescriptorSetLayout "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6033 | vkCmdBindDescriptorSets( |
| 6034 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6035 | pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6036 | m_errorMonitor->VerifyFound(); |
| 6037 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6038 | // Cause INFO messages due to disturbing previously bound Sets |
| 6039 | // First bind sets 0 & 1 |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6040 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6041 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6042 | 2, &descriptorSet[0], 0, NULL); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6043 | // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6044 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 6045 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6046 | " previously bound as set #0 was disturbed "); |
| 6047 | vkCmdBindDescriptorSets( |
| 6048 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6049 | pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6050 | m_errorMonitor->VerifyFound(); |
| 6051 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6052 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6053 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6054 | 2, &descriptorSet[0], 0, NULL); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6055 | // 2. Disturb set after last bound set |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 6056 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6057 | " newly bound as set #0 so set #1 and " |
| 6058 | "any subsequent sets were disturbed "); |
| 6059 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6060 | VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6061 | pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6062 | m_errorMonitor->VerifyFound(); |
| 6063 | |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6064 | // Cause draw-time errors due to PSO incompatibilities |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6065 | // 1. Error due to not binding required set (we actually use same code as |
| 6066 | // above to disturb set0) |
| 6067 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6068 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6069 | 2, &descriptorSet[0], 0, NULL); |
| 6070 | vkCmdBindDescriptorSets( |
| 6071 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6072 | pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL); |
| 6073 | m_errorMonitor->SetDesiredFailureMsg( |
| 6074 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6075 | " uses set #0 but that set is not bound."); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6076 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6077 | m_errorMonitor->VerifyFound(); |
| 6078 | |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6079 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6080 | // 2. Error due to bound set not being compatible with PSO's |
| 6081 | // VkPipelineLayout (diff stageFlags in this case) |
| 6082 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6083 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6084 | 2, &descriptorSet[0], 0, NULL); |
| 6085 | m_errorMonitor->SetDesiredFailureMsg( |
| 6086 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6087 | " bound as set #0 is not compatible with "); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6088 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6089 | m_errorMonitor->VerifyFound(); |
| 6090 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6091 | // Remaining clean-up |
| 6092 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6093 | for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) { |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6094 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL); |
| 6095 | } |
| 6096 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL); |
Tobin Ehlis | 9bfd449 | 2016-05-05 15:09:11 -0600 | [diff] [blame] | 6097 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only); |
| 6098 | vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6099 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6100 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6101 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 6102 | vkFreeMemory(m_device->device(), imageMem, NULL); |
| 6103 | vkDestroyImage(m_device->device(), image, NULL); |
| 6104 | vkDestroyImageView(m_device->device(), view, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6105 | } |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6106 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6107 | TEST_F(VkLayerTest, NoBeginCommandBuffer) { |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6108 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6109 | m_errorMonitor->SetDesiredFailureMsg( |
| 6110 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6111 | "You must call vkBeginCommandBuffer() before this call to "); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6112 | |
| 6113 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6114 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6115 | // Call EndCommandBuffer() w/o calling BeginCommandBuffer() |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6116 | vkEndCommandBuffer(commandBuffer.GetBufferHandle()); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6117 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6118 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6119 | } |
| 6120 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6121 | TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) { |
| 6122 | VkResult err; |
| 6123 | VkCommandBuffer draw_cmd; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6124 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6125 | m_errorMonitor->SetDesiredFailureMsg( |
| 6126 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 61b36f3 | 2015-12-16 08:19:42 -0700 | [diff] [blame] | 6127 | " must specify a valid renderpass parameter."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6128 | |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6129 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6130 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6131 | VkCommandBufferAllocateInfo cmd = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6132 | cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6133 | cmd.pNext = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6134 | cmd.commandPool = m_commandPool; |
| 6135 | cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6136 | cmd.commandBufferCount = 1; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6137 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6138 | err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 6139 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6140 | |
| 6141 | // Force the failure by not setting the Renderpass and Framebuffer fields |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6142 | VkCommandBufferBeginInfo cmd_buf_info = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6143 | VkCommandBufferInheritanceInfo cmd_buf_hinfo = {}; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6144 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6145 | cmd_buf_info.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6146 | cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | |
| 6147 | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6148 | cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo; |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6149 | |
| 6150 | // The error should be caught by validation of the BeginCommandBuffer call |
| 6151 | vkBeginCommandBuffer(draw_cmd, &cmd_buf_info); |
| 6152 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6153 | m_errorMonitor->VerifyFound(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6154 | vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6155 | } |
| 6156 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6157 | TEST_F(VkLayerTest, CommandBufferResetErrors) { |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6158 | // Cause error due to Begin while recording CB |
| 6159 | // Then cause 2 errors for attempting to reset CB w/o having |
| 6160 | // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from |
| 6161 | // which CBs were allocated. Note that this bit is off by default. |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 6162 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6163 | "Cannot call Begin on CB"); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6164 | |
| 6165 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6166 | |
| 6167 | // Calls AllocateCommandBuffers |
| 6168 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
| 6169 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6170 | // Force the failure by setting the Renderpass and Framebuffer fields with |
| 6171 | // (fake) data |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6172 | VkCommandBufferBeginInfo cmd_buf_info = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6173 | VkCommandBufferInheritanceInfo cmd_buf_hinfo = {}; |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6174 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 6175 | cmd_buf_info.pNext = NULL; |
| 6176 | cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6177 | cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo; |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6178 | |
| 6179 | // Begin CB to transition to recording state |
| 6180 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
| 6181 | // Can't re-begin. This should trigger error |
| 6182 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6183 | m_errorMonitor->VerifyFound(); |
| 6184 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6185 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6186 | "Attempt to reset command buffer "); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6187 | VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test |
| 6188 | // Reset attempt will trigger error due to incorrect CommandPool state |
| 6189 | vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6190 | m_errorMonitor->VerifyFound(); |
| 6191 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6192 | m_errorMonitor->SetDesiredFailureMsg( |
| 6193 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6194 | " attempts to implicitly reset cmdBuffer created from "); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6195 | // Transition CB to RECORDED state |
| 6196 | vkEndCommandBuffer(commandBuffer.GetBufferHandle()); |
| 6197 | // Now attempting to Begin will implicitly reset, which triggers error |
| 6198 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6199 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6200 | } |
| 6201 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6202 | TEST_F(VkLayerTest, InvalidPipelineCreateState) { |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6203 | // Attempt to Create Gfx Pipeline w/o a VS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6204 | VkResult err; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6205 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6206 | m_errorMonitor->SetDesiredFailureMsg( |
| 6207 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6208 | "Invalid Pipeline CreateInfo State: Vtx Shader required"); |
| 6209 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6210 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 6211 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 6212 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6213 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6214 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6215 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6216 | |
| 6217 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6218 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6219 | ds_pool_ci.pNext = NULL; |
| 6220 | ds_pool_ci.maxSets = 1; |
| 6221 | ds_pool_ci.poolSizeCount = 1; |
| 6222 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 6223 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6224 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6225 | err = |
| 6226 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6227 | ASSERT_VK_SUCCESS(err); |
| 6228 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6229 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6230 | dsl_binding.binding = 0; |
| 6231 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6232 | dsl_binding.descriptorCount = 1; |
| 6233 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 6234 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6235 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6236 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6237 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6238 | ds_layout_ci.pNext = NULL; |
| 6239 | ds_layout_ci.bindingCount = 1; |
| 6240 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6241 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6242 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6243 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6244 | &ds_layout); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6245 | ASSERT_VK_SUCCESS(err); |
| 6246 | |
| 6247 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6248 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6249 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6250 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6251 | alloc_info.descriptorPool = ds_pool; |
| 6252 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6253 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6254 | &descriptorSet); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6255 | ASSERT_VK_SUCCESS(err); |
| 6256 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6257 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6258 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6259 | pipeline_layout_ci.setLayoutCount = 1; |
| 6260 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6261 | |
| 6262 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6263 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6264 | &pipeline_layout); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6265 | ASSERT_VK_SUCCESS(err); |
| 6266 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6267 | VkViewport vp = {}; // Just need dummy vp to point to |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6268 | VkRect2D sc = {}; // dummy scissor to point to |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6269 | |
| 6270 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6271 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 6272 | vp_state_ci.scissorCount = 1; |
| 6273 | vp_state_ci.pScissors = ≻ |
| 6274 | vp_state_ci.viewportCount = 1; |
| 6275 | vp_state_ci.pViewports = &vp; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6276 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6277 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 6278 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 6279 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 6280 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 6281 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 6282 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 6283 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 6284 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 6285 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6286 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6287 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6288 | gp_ci.pViewportState = &vp_state_ci; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6289 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6290 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6291 | gp_ci.layout = pipeline_layout; |
| 6292 | gp_ci.renderPass = renderPass(); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6293 | |
| 6294 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6295 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 6296 | pc_ci.initialDataSize = 0; |
| 6297 | pc_ci.pInitialData = 0; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6298 | |
| 6299 | VkPipeline pipeline; |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 6300 | VkPipelineCache pipelineCache; |
| 6301 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6302 | err = |
| 6303 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 6304 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6305 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6306 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6307 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6308 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 6309 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6310 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6311 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6312 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6313 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6314 | } |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6315 | /*// TODO : This test should be good, but needs Tess support in compiler to run |
| 6316 | TEST_F(VkLayerTest, InvalidPatchControlPoints) |
| 6317 | { |
| 6318 | // Attempt to Create Gfx Pipeline w/o a VS |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6319 | VkResult err; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6320 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 6321 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6322 | "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH |
| 6323 | primitive "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6324 | |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6325 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6326 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6327 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6328 | VkDescriptorPoolSize ds_type_count = {}; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6329 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6330 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6331 | |
| 6332 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 6333 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6334 | ds_pool_ci.pNext = NULL; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6335 | ds_pool_ci.poolSizeCount = 1; |
| 6336 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6337 | |
| 6338 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6339 | err = vkCreateDescriptorPool(m_device->device(), |
| 6340 | 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] | 6341 | ASSERT_VK_SUCCESS(err); |
| 6342 | |
| 6343 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6344 | dsl_binding.binding = 0; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6345 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | 0212448 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 6346 | dsl_binding.descriptorCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6347 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 6348 | dsl_binding.pImmutableSamplers = NULL; |
| 6349 | |
| 6350 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6351 | ds_layout_ci.sType = |
| 6352 | VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6353 | ds_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6354 | ds_layout_ci.bindingCount = 1; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 6355 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6356 | |
| 6357 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6358 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6359 | &ds_layout); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6360 | ASSERT_VK_SUCCESS(err); |
| 6361 | |
| 6362 | VkDescriptorSet descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6363 | err = vkAllocateDescriptorSets(m_device->device(), ds_pool, |
| 6364 | VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6365 | ASSERT_VK_SUCCESS(err); |
| 6366 | |
| 6367 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6368 | pipeline_layout_ci.sType = |
| 6369 | VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6370 | pipeline_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6371 | pipeline_layout_ci.setLayoutCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6372 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 6373 | |
| 6374 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6375 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6376 | &pipeline_layout); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6377 | ASSERT_VK_SUCCESS(err); |
| 6378 | |
| 6379 | VkPipelineShaderStageCreateInfo shaderStages[3]; |
| 6380 | memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 6381 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6382 | VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, |
| 6383 | this); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6384 | // 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] | 6385 | VkShaderObj |
| 6386 | tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, |
| 6387 | this); |
| 6388 | VkShaderObj |
| 6389 | te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, |
| 6390 | this); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6391 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6392 | shaderStages[0].sType = |
| 6393 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 6394 | shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6395 | shaderStages[0].shader = vs.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6396 | shaderStages[1].sType = |
| 6397 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 6398 | shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6399 | shaderStages[1].shader = tc.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6400 | shaderStages[2].sType = |
| 6401 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 6402 | shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6403 | shaderStages[2].shader = te.handle(); |
| 6404 | |
| 6405 | VkPipelineInputAssemblyStateCreateInfo iaCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6406 | iaCI.sType = |
| 6407 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
Chia-I Wu | 515eb8f | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6408 | iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6409 | |
| 6410 | VkPipelineTessellationStateCreateInfo tsCI = {}; |
| 6411 | tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO; |
| 6412 | tsCI.patchControlPoints = 0; // This will cause an error |
| 6413 | |
| 6414 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 6415 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6416 | gp_ci.pNext = NULL; |
| 6417 | gp_ci.stageCount = 3; |
| 6418 | gp_ci.pStages = shaderStages; |
| 6419 | gp_ci.pVertexInputState = NULL; |
| 6420 | gp_ci.pInputAssemblyState = &iaCI; |
| 6421 | gp_ci.pTessellationState = &tsCI; |
| 6422 | gp_ci.pViewportState = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6423 | gp_ci.pRasterizationState = NULL; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6424 | gp_ci.pMultisampleState = NULL; |
| 6425 | gp_ci.pDepthStencilState = NULL; |
| 6426 | gp_ci.pColorBlendState = NULL; |
| 6427 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6428 | gp_ci.layout = pipeline_layout; |
| 6429 | gp_ci.renderPass = renderPass(); |
| 6430 | |
| 6431 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 6432 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 6433 | pc_ci.pNext = NULL; |
| 6434 | pc_ci.initialSize = 0; |
| 6435 | pc_ci.initialData = 0; |
| 6436 | pc_ci.maxSize = 0; |
| 6437 | |
| 6438 | VkPipeline pipeline; |
| 6439 | VkPipelineCache pipelineCache; |
| 6440 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6441 | err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, |
| 6442 | &pipelineCache); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6443 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6444 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6445 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6446 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6447 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 6448 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6449 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6450 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6451 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6452 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6453 | } |
| 6454 | */ |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6455 | // Set scissor and viewport counts to different numbers |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6456 | TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6457 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6458 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6459 | m_errorMonitor->SetDesiredFailureMsg( |
| 6460 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6461 | "Gfx Pipeline viewport count (1) must match scissor count (0)."); |
| 6462 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6463 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6464 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6465 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6466 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6467 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6468 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6469 | |
| 6470 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6471 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6472 | ds_pool_ci.maxSets = 1; |
| 6473 | ds_pool_ci.poolSizeCount = 1; |
| 6474 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6475 | |
| 6476 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6477 | err = |
| 6478 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6479 | ASSERT_VK_SUCCESS(err); |
| 6480 | |
| 6481 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6482 | dsl_binding.binding = 0; |
| 6483 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6484 | dsl_binding.descriptorCount = 1; |
| 6485 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6486 | |
| 6487 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6488 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6489 | ds_layout_ci.bindingCount = 1; |
| 6490 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6491 | |
| 6492 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6493 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6494 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6495 | ASSERT_VK_SUCCESS(err); |
| 6496 | |
| 6497 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6498 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6499 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6500 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6501 | alloc_info.descriptorPool = ds_pool; |
| 6502 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6503 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6504 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6505 | ASSERT_VK_SUCCESS(err); |
| 6506 | |
| 6507 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6508 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6509 | pipeline_layout_ci.setLayoutCount = 1; |
| 6510 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6511 | |
| 6512 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6513 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6514 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6515 | ASSERT_VK_SUCCESS(err); |
| 6516 | |
| 6517 | VkViewport vp = {}; // Just need dummy vp to point to |
| 6518 | |
| 6519 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6520 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 6521 | vp_state_ci.scissorCount = 0; |
| 6522 | vp_state_ci.viewportCount = 1; // Count mismatch should cause error |
| 6523 | vp_state_ci.pViewports = &vp; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6524 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6525 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 6526 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 6527 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 6528 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 6529 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 6530 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 6531 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 6532 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 6533 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 6534 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6535 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6536 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6537 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 6538 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6539 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 6540 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6541 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6542 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6543 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 6544 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6545 | |
| 6546 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6547 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6548 | gp_ci.stageCount = 2; |
| 6549 | gp_ci.pStages = shaderStages; |
| 6550 | gp_ci.pViewportState = &vp_state_ci; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6551 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6552 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6553 | gp_ci.layout = pipeline_layout; |
| 6554 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6555 | |
| 6556 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6557 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6558 | |
| 6559 | VkPipeline pipeline; |
| 6560 | VkPipelineCache pipelineCache; |
| 6561 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6562 | err = |
| 6563 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6564 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6565 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6566 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6567 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6568 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6569 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6570 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6571 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6572 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6573 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6574 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6575 | // Don't set viewport state in PSO. This is an error b/c we always need this |
| 6576 | // state |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 6577 | // 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] | 6578 | TEST_F(VkLayerTest, PSOViewportStateNotSet) { |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6579 | // Attempt to Create Gfx Pipeline w/o a VS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6580 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6581 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6582 | m_errorMonitor->SetDesiredFailureMsg( |
| 6583 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6584 | "Gfx Pipeline pViewportState is null. Even if "); |
| 6585 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6586 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6587 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6588 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6589 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6590 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6591 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6592 | |
| 6593 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6594 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6595 | ds_pool_ci.maxSets = 1; |
| 6596 | ds_pool_ci.poolSizeCount = 1; |
| 6597 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6598 | |
| 6599 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6600 | err = |
| 6601 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6602 | ASSERT_VK_SUCCESS(err); |
| 6603 | |
| 6604 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6605 | dsl_binding.binding = 0; |
| 6606 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6607 | dsl_binding.descriptorCount = 1; |
| 6608 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6609 | |
| 6610 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6611 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6612 | ds_layout_ci.bindingCount = 1; |
| 6613 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6614 | |
| 6615 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6616 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6617 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6618 | ASSERT_VK_SUCCESS(err); |
| 6619 | |
| 6620 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6621 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6622 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6623 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6624 | alloc_info.descriptorPool = ds_pool; |
| 6625 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6626 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6627 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6628 | ASSERT_VK_SUCCESS(err); |
| 6629 | |
| 6630 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6631 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6632 | pipeline_layout_ci.setLayoutCount = 1; |
| 6633 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6634 | |
| 6635 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6636 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6637 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6638 | ASSERT_VK_SUCCESS(err); |
| 6639 | |
| 6640 | VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR; |
| 6641 | // Set scissor as dynamic to avoid second error |
| 6642 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6643 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 6644 | dyn_state_ci.dynamicStateCount = 1; |
| 6645 | dyn_state_ci.pDynamicStates = &sc_state; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6646 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 6647 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6648 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
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 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 6651 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6652 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 6653 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6654 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6655 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6656 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 6657 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6658 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6659 | |
| 6660 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 6661 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 6662 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 6663 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 6664 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 6665 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 6666 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 6667 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 6668 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6669 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6670 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6671 | gp_ci.stageCount = 2; |
| 6672 | gp_ci.pStages = shaderStages; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6673 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6674 | gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state |
| 6675 | // should cause validation error |
| 6676 | gp_ci.pDynamicState = &dyn_state_ci; |
| 6677 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6678 | gp_ci.layout = pipeline_layout; |
| 6679 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6680 | |
| 6681 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6682 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6683 | |
| 6684 | VkPipeline pipeline; |
| 6685 | VkPipelineCache pipelineCache; |
| 6686 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6687 | err = |
| 6688 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6689 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6690 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6691 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6692 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6693 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6694 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6695 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6696 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6697 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6698 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6699 | } |
| 6700 | // Create PSO w/o non-zero viewportCount but no viewport data |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6701 | // Then run second test where dynamic scissor count doesn't match PSO scissor |
| 6702 | // count |
| 6703 | TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) { |
| 6704 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6705 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6706 | m_errorMonitor->SetDesiredFailureMsg( |
| 6707 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6708 | "Gfx Pipeline viewportCount is 1, but pViewports is NULL. "); |
| 6709 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6710 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6711 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6712 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6713 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6714 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6715 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6716 | |
| 6717 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6718 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6719 | ds_pool_ci.maxSets = 1; |
| 6720 | ds_pool_ci.poolSizeCount = 1; |
| 6721 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6722 | |
| 6723 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6724 | err = |
| 6725 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6726 | ASSERT_VK_SUCCESS(err); |
| 6727 | |
| 6728 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6729 | dsl_binding.binding = 0; |
| 6730 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6731 | dsl_binding.descriptorCount = 1; |
| 6732 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6733 | |
| 6734 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6735 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6736 | ds_layout_ci.bindingCount = 1; |
| 6737 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6738 | |
| 6739 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6740 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6741 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6742 | ASSERT_VK_SUCCESS(err); |
| 6743 | |
| 6744 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6745 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6746 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6747 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6748 | alloc_info.descriptorPool = ds_pool; |
| 6749 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6750 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6751 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6752 | ASSERT_VK_SUCCESS(err); |
| 6753 | |
| 6754 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6755 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6756 | pipeline_layout_ci.setLayoutCount = 1; |
| 6757 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6758 | |
| 6759 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6760 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6761 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6762 | ASSERT_VK_SUCCESS(err); |
| 6763 | |
| 6764 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6765 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 6766 | vp_state_ci.viewportCount = 1; |
| 6767 | vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error |
| 6768 | vp_state_ci.scissorCount = 1; |
| 6769 | vp_state_ci.pScissors = |
| 6770 | NULL; // Scissor is dynamic (below) so this won't cause error |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6771 | |
| 6772 | VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR; |
| 6773 | // Set scissor as dynamic to avoid that error |
| 6774 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6775 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 6776 | dyn_state_ci.dynamicStateCount = 1; |
| 6777 | dyn_state_ci.pDynamicStates = &sc_state; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6778 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 6779 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6780 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6781 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6782 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 6783 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6784 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 6785 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6786 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6787 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6788 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 6789 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6790 | |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6791 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 6792 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 6793 | vi_ci.pNext = nullptr; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6794 | vi_ci.vertexBindingDescriptionCount = 0; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6795 | vi_ci.pVertexBindingDescriptions = nullptr; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6796 | vi_ci.vertexAttributeDescriptionCount = 0; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6797 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 6798 | |
| 6799 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 6800 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 6801 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 6802 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6803 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6804 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6805 | rs_ci.pNext = nullptr; |
| 6806 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 6807 | VkPipelineColorBlendAttachmentState att = {}; |
| 6808 | att.blendEnable = VK_FALSE; |
| 6809 | att.colorWriteMask = 0xf; |
| 6810 | |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6811 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 6812 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 6813 | cb_ci.pNext = nullptr; |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 6814 | cb_ci.attachmentCount = 1; |
| 6815 | cb_ci.pAttachments = &att; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6816 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6817 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6818 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6819 | gp_ci.stageCount = 2; |
| 6820 | gp_ci.pStages = shaderStages; |
| 6821 | gp_ci.pVertexInputState = &vi_ci; |
| 6822 | gp_ci.pInputAssemblyState = &ia_ci; |
| 6823 | gp_ci.pViewportState = &vp_state_ci; |
| 6824 | gp_ci.pRasterizationState = &rs_ci; |
| 6825 | gp_ci.pColorBlendState = &cb_ci; |
| 6826 | gp_ci.pDynamicState = &dyn_state_ci; |
| 6827 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6828 | gp_ci.layout = pipeline_layout; |
| 6829 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6830 | |
| 6831 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6832 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6833 | |
| 6834 | VkPipeline pipeline; |
| 6835 | VkPipelineCache pipelineCache; |
| 6836 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6837 | err = |
| 6838 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6839 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6840 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6841 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6842 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6843 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6844 | |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 6845 | // 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] | 6846 | // First need to successfully create the PSO from above by setting |
| 6847 | // pViewports |
| 6848 | m_errorMonitor->SetDesiredFailureMsg( |
| 6849 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6850 | "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO " |
| 6851 | "scissorCount is 1. These counts must match."); |
| 6852 | |
| 6853 | VkViewport vp = {}; // Just need dummy vp to point to |
| 6854 | vp_state_ci.pViewports = &vp; |
| 6855 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6856 | &gp_ci, NULL, &pipeline); |
| 6857 | ASSERT_VK_SUCCESS(err); |
| 6858 | BeginCommandBuffer(); |
| 6859 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 6860 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 6861 | VkRect2D scissors[2] = {}; // don't care about data |
| 6862 | // Count of 2 doesn't match PSO count of 1 |
| 6863 | vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors); |
| 6864 | Draw(1, 0, 0, 0); |
| 6865 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6866 | m_errorMonitor->VerifyFound(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6867 | |
| 6868 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6869 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6870 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6871 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 6872 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6873 | } |
| 6874 | // Create PSO w/o non-zero scissorCount but no scissor data |
| 6875 | // Then run second test where dynamic viewportCount doesn't match PSO |
| 6876 | // viewportCount |
| 6877 | TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) { |
| 6878 | VkResult err; |
| 6879 | |
| 6880 | m_errorMonitor->SetDesiredFailureMsg( |
| 6881 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6882 | "Gfx Pipeline scissorCount is 1, but pScissors is NULL. "); |
| 6883 | |
| 6884 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6885 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 6886 | |
| 6887 | VkDescriptorPoolSize ds_type_count = {}; |
| 6888 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6889 | ds_type_count.descriptorCount = 1; |
| 6890 | |
| 6891 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 6892 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6893 | ds_pool_ci.maxSets = 1; |
| 6894 | ds_pool_ci.poolSizeCount = 1; |
| 6895 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 6896 | |
| 6897 | VkDescriptorPool ds_pool; |
| 6898 | err = |
| 6899 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 6900 | ASSERT_VK_SUCCESS(err); |
| 6901 | |
| 6902 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 6903 | dsl_binding.binding = 0; |
| 6904 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6905 | dsl_binding.descriptorCount = 1; |
| 6906 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 6907 | |
| 6908 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 6909 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6910 | ds_layout_ci.bindingCount = 1; |
| 6911 | ds_layout_ci.pBindings = &dsl_binding; |
| 6912 | |
| 6913 | VkDescriptorSetLayout ds_layout; |
| 6914 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6915 | &ds_layout); |
| 6916 | ASSERT_VK_SUCCESS(err); |
| 6917 | |
| 6918 | VkDescriptorSet descriptorSet; |
| 6919 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 6920 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 6921 | alloc_info.descriptorSetCount = 1; |
| 6922 | alloc_info.descriptorPool = ds_pool; |
| 6923 | alloc_info.pSetLayouts = &ds_layout; |
| 6924 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6925 | &descriptorSet); |
| 6926 | ASSERT_VK_SUCCESS(err); |
| 6927 | |
| 6928 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 6929 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6930 | pipeline_layout_ci.setLayoutCount = 1; |
| 6931 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 6932 | |
| 6933 | VkPipelineLayout pipeline_layout; |
| 6934 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6935 | &pipeline_layout); |
| 6936 | ASSERT_VK_SUCCESS(err); |
| 6937 | |
| 6938 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 6939 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 6940 | vp_state_ci.scissorCount = 1; |
| 6941 | vp_state_ci.pScissors = |
| 6942 | NULL; // Null scissor w/ count of 1 should cause error |
| 6943 | vp_state_ci.viewportCount = 1; |
| 6944 | vp_state_ci.pViewports = |
| 6945 | NULL; // vp is dynamic (below) so this won't cause error |
| 6946 | |
| 6947 | VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT; |
| 6948 | // Set scissor as dynamic to avoid that error |
| 6949 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
| 6950 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 6951 | dyn_state_ci.dynamicStateCount = 1; |
| 6952 | dyn_state_ci.pDynamicStates = &vp_state; |
| 6953 | |
| 6954 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
| 6955 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 6956 | |
| 6957 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 6958 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6959 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 6960 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6961 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6962 | // but add it to be able to run on more devices |
| 6963 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 6964 | shaderStages[1] = fs.GetStageCreateInfo(); |
| 6965 | |
| 6966 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 6967 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 6968 | vi_ci.pNext = nullptr; |
| 6969 | vi_ci.vertexBindingDescriptionCount = 0; |
| 6970 | vi_ci.pVertexBindingDescriptions = nullptr; |
| 6971 | vi_ci.vertexAttributeDescriptionCount = 0; |
| 6972 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 6973 | |
| 6974 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 6975 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 6976 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 6977 | |
| 6978 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
| 6979 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 6980 | rs_ci.pNext = nullptr; |
| 6981 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 6982 | VkPipelineColorBlendAttachmentState att = {}; |
| 6983 | att.blendEnable = VK_FALSE; |
| 6984 | att.colorWriteMask = 0xf; |
| 6985 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6986 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 6987 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 6988 | cb_ci.pNext = nullptr; |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 6989 | cb_ci.attachmentCount = 1; |
| 6990 | cb_ci.pAttachments = &att; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6991 | |
| 6992 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 6993 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6994 | gp_ci.stageCount = 2; |
| 6995 | gp_ci.pStages = shaderStages; |
| 6996 | gp_ci.pVertexInputState = &vi_ci; |
| 6997 | gp_ci.pInputAssemblyState = &ia_ci; |
| 6998 | gp_ci.pViewportState = &vp_state_ci; |
| 6999 | gp_ci.pRasterizationState = &rs_ci; |
| 7000 | gp_ci.pColorBlendState = &cb_ci; |
| 7001 | gp_ci.pDynamicState = &dyn_state_ci; |
| 7002 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7003 | gp_ci.layout = pipeline_layout; |
| 7004 | gp_ci.renderPass = renderPass(); |
| 7005 | |
| 7006 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 7007 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 7008 | |
| 7009 | VkPipeline pipeline; |
| 7010 | VkPipelineCache pipelineCache; |
| 7011 | |
| 7012 | err = |
| 7013 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7014 | ASSERT_VK_SUCCESS(err); |
| 7015 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7016 | &gp_ci, NULL, &pipeline); |
| 7017 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7018 | m_errorMonitor->VerifyFound(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7019 | |
| 7020 | // Now hit second fail case where we set scissor w/ different count than PSO |
| 7021 | // First need to successfully create the PSO from above by setting |
| 7022 | // pViewports |
| 7023 | m_errorMonitor->SetDesiredFailureMsg( |
| 7024 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7025 | "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO " |
| 7026 | "viewportCount is 1. These counts must match."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7027 | |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7028 | VkRect2D sc = {}; // Just need dummy vp to point to |
| 7029 | vp_state_ci.pScissors = ≻ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7030 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7031 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7032 | ASSERT_VK_SUCCESS(err); |
| 7033 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7034 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7035 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7036 | VkViewport viewports[2] = {}; // don't care about data |
| 7037 | // Count of 2 doesn't match PSO count of 1 |
Jon Ashburn | 19d3bf1 | 2015-12-30 14:06:55 -0700 | [diff] [blame] | 7038 | vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7039 | Draw(1, 0, 0, 0); |
| 7040 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7041 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7042 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7043 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7044 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7045 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7046 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7047 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7048 | } |
| 7049 | |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7050 | TEST_F(VkLayerTest, PSOLineWidthInvalid) { |
| 7051 | VkResult err; |
| 7052 | |
| 7053 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7054 | "Attempt to set lineWidth to -1"); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7055 | |
| 7056 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7057 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7058 | |
| 7059 | VkDescriptorPoolSize ds_type_count = {}; |
| 7060 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7061 | ds_type_count.descriptorCount = 1; |
| 7062 | |
| 7063 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 7064 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7065 | ds_pool_ci.maxSets = 1; |
| 7066 | ds_pool_ci.poolSizeCount = 1; |
| 7067 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 7068 | |
| 7069 | VkDescriptorPool ds_pool; |
| 7070 | err = |
| 7071 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 7072 | ASSERT_VK_SUCCESS(err); |
| 7073 | |
| 7074 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 7075 | dsl_binding.binding = 0; |
| 7076 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7077 | dsl_binding.descriptorCount = 1; |
| 7078 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7079 | |
| 7080 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 7081 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7082 | ds_layout_ci.bindingCount = 1; |
| 7083 | ds_layout_ci.pBindings = &dsl_binding; |
| 7084 | |
| 7085 | VkDescriptorSetLayout ds_layout; |
| 7086 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7087 | &ds_layout); |
| 7088 | ASSERT_VK_SUCCESS(err); |
| 7089 | |
| 7090 | VkDescriptorSet descriptorSet; |
| 7091 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 7092 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 7093 | alloc_info.descriptorSetCount = 1; |
| 7094 | alloc_info.descriptorPool = ds_pool; |
| 7095 | alloc_info.pSetLayouts = &ds_layout; |
| 7096 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7097 | &descriptorSet); |
| 7098 | ASSERT_VK_SUCCESS(err); |
| 7099 | |
| 7100 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 7101 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7102 | pipeline_layout_ci.setLayoutCount = 1; |
| 7103 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 7104 | |
| 7105 | VkPipelineLayout pipeline_layout; |
| 7106 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7107 | &pipeline_layout); |
| 7108 | ASSERT_VK_SUCCESS(err); |
| 7109 | |
| 7110 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 7111 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7112 | vp_state_ci.scissorCount = 1; |
| 7113 | vp_state_ci.pScissors = NULL; |
| 7114 | vp_state_ci.viewportCount = 1; |
| 7115 | vp_state_ci.pViewports = NULL; |
| 7116 | |
| 7117 | VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, |
| 7118 | VK_DYNAMIC_STATE_SCISSOR, |
| 7119 | VK_DYNAMIC_STATE_LINE_WIDTH}; |
| 7120 | // Set scissor as dynamic to avoid that error |
| 7121 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
| 7122 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 7123 | dyn_state_ci.dynamicStateCount = 2; |
| 7124 | dyn_state_ci.pDynamicStates = dynamic_states; |
| 7125 | |
| 7126 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
| 7127 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 7128 | |
| 7129 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7130 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7131 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7132 | VK_SHADER_STAGE_FRAGMENT_BIT, |
| 7133 | this); // TODO - We shouldn't need a fragment shader |
| 7134 | // but add it to be able to run on more devices |
| 7135 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 7136 | shaderStages[1] = fs.GetStageCreateInfo(); |
| 7137 | |
| 7138 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 7139 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 7140 | vi_ci.pNext = nullptr; |
| 7141 | vi_ci.vertexBindingDescriptionCount = 0; |
| 7142 | vi_ci.pVertexBindingDescriptions = nullptr; |
| 7143 | vi_ci.vertexAttributeDescriptionCount = 0; |
| 7144 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 7145 | |
| 7146 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 7147 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 7148 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 7149 | |
| 7150 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
| 7151 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7152 | rs_ci.pNext = nullptr; |
| 7153 | |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7154 | // Check too low (line width of -1.0f). |
| 7155 | rs_ci.lineWidth = -1.0f; |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7156 | |
| 7157 | VkPipelineColorBlendAttachmentState att = {}; |
| 7158 | att.blendEnable = VK_FALSE; |
| 7159 | att.colorWriteMask = 0xf; |
| 7160 | |
| 7161 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 7162 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 7163 | cb_ci.pNext = nullptr; |
| 7164 | cb_ci.attachmentCount = 1; |
| 7165 | cb_ci.pAttachments = &att; |
| 7166 | |
| 7167 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 7168 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7169 | gp_ci.stageCount = 2; |
| 7170 | gp_ci.pStages = shaderStages; |
| 7171 | gp_ci.pVertexInputState = &vi_ci; |
| 7172 | gp_ci.pInputAssemblyState = &ia_ci; |
| 7173 | gp_ci.pViewportState = &vp_state_ci; |
| 7174 | gp_ci.pRasterizationState = &rs_ci; |
| 7175 | gp_ci.pColorBlendState = &cb_ci; |
| 7176 | gp_ci.pDynamicState = &dyn_state_ci; |
| 7177 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7178 | gp_ci.layout = pipeline_layout; |
| 7179 | gp_ci.renderPass = renderPass(); |
| 7180 | |
| 7181 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 7182 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 7183 | |
| 7184 | VkPipeline pipeline; |
| 7185 | VkPipelineCache pipelineCache; |
| 7186 | |
| 7187 | err = |
| 7188 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7189 | ASSERT_VK_SUCCESS(err); |
| 7190 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7191 | &gp_ci, NULL, &pipeline); |
| 7192 | |
| 7193 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7194 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7195 | |
| 7196 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7197 | "Attempt to set lineWidth to 65536"); |
| 7198 | |
| 7199 | // Check too high (line width of 65536.0f). |
| 7200 | rs_ci.lineWidth = 65536.0f; |
| 7201 | |
| 7202 | err = |
| 7203 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7204 | ASSERT_VK_SUCCESS(err); |
| 7205 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7206 | &gp_ci, NULL, &pipeline); |
| 7207 | |
| 7208 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7209 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7210 | |
| 7211 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7212 | "Attempt to set lineWidth to -1"); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7213 | |
| 7214 | dyn_state_ci.dynamicStateCount = 3; |
| 7215 | |
| 7216 | rs_ci.lineWidth = 1.0f; |
| 7217 | |
| 7218 | err = |
| 7219 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7220 | ASSERT_VK_SUCCESS(err); |
| 7221 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7222 | &gp_ci, NULL, &pipeline); |
| 7223 | BeginCommandBuffer(); |
| 7224 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7225 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 7226 | |
| 7227 | // Check too low with dynamic setting. |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7228 | vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7229 | m_errorMonitor->VerifyFound(); |
| 7230 | |
| 7231 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7232 | "Attempt to set lineWidth to 65536"); |
| 7233 | |
| 7234 | // Check too high with dynamic setting. |
| 7235 | vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f); |
| 7236 | m_errorMonitor->VerifyFound(); |
| 7237 | EndCommandBuffer(); |
| 7238 | |
| 7239 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7240 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7241 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7242 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7243 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7244 | } |
| 7245 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7246 | TEST_F(VkLayerTest, NullRenderPass) { |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7247 | // Bind a NULL RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7248 | m_errorMonitor->SetDesiredFailureMsg( |
| 7249 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7250 | "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()"); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7251 | |
| 7252 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7253 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7254 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 7255 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7256 | // Don't care about RenderPass handle b/c error should be flagged before |
| 7257 | // that |
| 7258 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, |
| 7259 | VK_SUBPASS_CONTENTS_INLINE); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7260 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7261 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7262 | } |
| 7263 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7264 | TEST_F(VkLayerTest, RenderPassWithinRenderPass) { |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7265 | // Bind a BeginRenderPass within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7266 | m_errorMonitor->SetDesiredFailureMsg( |
| 7267 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7268 | "It is invalid to issue this call inside an active render pass"); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7269 | |
| 7270 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7271 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7272 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 7273 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7274 | // Just create a dummy Renderpass that's non-NULL so we can get to the |
| 7275 | // proper error |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7276 | VkRenderPassBeginInfo rp_begin = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7277 | rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 7278 | rp_begin.pNext = NULL; |
| 7279 | rp_begin.renderPass = renderPass(); |
| 7280 | rp_begin.framebuffer = framebuffer(); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 7281 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7282 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, |
| 7283 | VK_SUBPASS_CONTENTS_INLINE); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7284 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7285 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 7286 | } |
| 7287 | |
Tobin Ehlis | 5a1c033 | 2016-05-31 13:59:26 -0600 | [diff] [blame] | 7288 | TEST_F(VkLayerTest, RenderPassClearOpMismatch) { |
| 7289 | TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than" |
| 7290 | "the number of renderPass attachments that use loadOp" |
| 7291 | "VK_ATTACHMENT_LOAD_OP_CLEAR."); |
| 7292 | |
| 7293 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7294 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7295 | |
| 7296 | // Create a renderPass with a single attachment that uses loadOp CLEAR |
| 7297 | VkAttachmentReference attach = {}; |
| 7298 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 7299 | VkSubpassDescription subpass = {}; |
| 7300 | subpass.inputAttachmentCount = 1; |
| 7301 | subpass.pInputAttachments = &attach; |
| 7302 | VkRenderPassCreateInfo rpci = {}; |
| 7303 | rpci.subpassCount = 1; |
| 7304 | rpci.pSubpasses = &subpass; |
| 7305 | rpci.attachmentCount = 1; |
| 7306 | VkAttachmentDescription attach_desc = {}; |
| 7307 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 7308 | // Set loadOp to CLEAR |
| 7309 | attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 7310 | rpci.pAttachments = &attach_desc; |
| 7311 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 7312 | VkRenderPass rp; |
| 7313 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 7314 | |
| 7315 | VkCommandBufferInheritanceInfo hinfo = {}; |
| 7316 | hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; |
| 7317 | hinfo.renderPass = VK_NULL_HANDLE; |
| 7318 | hinfo.subpass = 0; |
| 7319 | hinfo.framebuffer = VK_NULL_HANDLE; |
| 7320 | hinfo.occlusionQueryEnable = VK_FALSE; |
| 7321 | hinfo.queryFlags = 0; |
| 7322 | hinfo.pipelineStatistics = 0; |
| 7323 | VkCommandBufferBeginInfo info = {}; |
| 7324 | info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
| 7325 | info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 7326 | info.pInheritanceInfo = &hinfo; |
| 7327 | |
| 7328 | vkBeginCommandBuffer(m_commandBuffer->handle(), &info); |
| 7329 | VkRenderPassBeginInfo rp_begin = {}; |
| 7330 | rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 7331 | rp_begin.pNext = NULL; |
| 7332 | rp_begin.renderPass = renderPass(); |
| 7333 | rp_begin.framebuffer = framebuffer(); |
| 7334 | rp_begin.clearValueCount = 0; // Should be 1 |
| 7335 | |
| 7336 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7337 | " has a clearValueCount of 0 but the " |
| 7338 | "actual number of attachments in " |
| 7339 | "renderPass "); |
| 7340 | |
| 7341 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, |
| 7342 | VK_SUBPASS_CONTENTS_INLINE); |
| 7343 | |
| 7344 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 5c70ebd | 2016-06-09 13:45:00 -0600 | [diff] [blame] | 7345 | |
| 7346 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 5a1c033 | 2016-05-31 13:59:26 -0600 | [diff] [blame] | 7347 | } |
| 7348 | |
Cody Northrop | 3bb4d96 | 2016-05-09 16:15:57 -0600 | [diff] [blame] | 7349 | TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) { |
| 7350 | |
| 7351 | TEST_DESCRIPTION("End a command buffer with an active render pass"); |
| 7352 | |
| 7353 | m_errorMonitor->SetDesiredFailureMsg( |
| 7354 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7355 | "It is invalid to issue this call inside an active render pass"); |
| 7356 | |
| 7357 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7358 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7359 | |
| 7360 | // The framework's BeginCommandBuffer calls CreateRenderPass |
| 7361 | BeginCommandBuffer(); |
| 7362 | |
| 7363 | // Call directly into vkEndCommandBuffer instead of the |
| 7364 | // the framework's EndCommandBuffer, which inserts a |
| 7365 | // vkEndRenderPass |
| 7366 | vkEndCommandBuffer(m_commandBuffer->GetBufferHandle()); |
| 7367 | |
| 7368 | m_errorMonitor->VerifyFound(); |
| 7369 | |
| 7370 | // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY |
| 7371 | // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT |
| 7372 | } |
| 7373 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7374 | TEST_F(VkLayerTest, FillBufferWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7375 | // Call CmdFillBuffer within an active renderpass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7376 | m_errorMonitor->SetDesiredFailureMsg( |
| 7377 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7378 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7379 | |
| 7380 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7381 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7382 | |
| 7383 | // Renderpass is started here |
| 7384 | BeginCommandBuffer(); |
| 7385 | |
| 7386 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7387 | vk_testing::Buffer dstBuffer; |
| 7388 | dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7389 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7390 | m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7391 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7392 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7393 | } |
| 7394 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7395 | TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7396 | // Call CmdUpdateBuffer within an active renderpass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7397 | m_errorMonitor->SetDesiredFailureMsg( |
| 7398 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7399 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7400 | |
| 7401 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7402 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7403 | |
| 7404 | // Renderpass is started here |
| 7405 | BeginCommandBuffer(); |
| 7406 | |
| 7407 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7408 | vk_testing::Buffer dstBuffer; |
| 7409 | dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7410 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7411 | VkDeviceSize dstOffset = 0; |
| 7412 | VkDeviceSize dataSize = 1024; |
| 7413 | const uint32_t *pData = NULL; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7414 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7415 | vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), |
| 7416 | dstOffset, dataSize, pData); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7417 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7418 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7419 | } |
| 7420 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7421 | TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7422 | // Call CmdClearColorImage within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7423 | m_errorMonitor->SetDesiredFailureMsg( |
| 7424 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7425 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7426 | |
| 7427 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7428 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7429 | |
| 7430 | // Renderpass is started here |
| 7431 | BeginCommandBuffer(); |
| 7432 | |
Michael Lentine | 0a369f6 | 2016-02-03 16:51:46 -0600 | [diff] [blame] | 7433 | VkClearColorValue clear_color; |
| 7434 | memset(clear_color.uint32, 0, sizeof(uint32_t) * 4); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7435 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 7436 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 7437 | const int32_t tex_width = 32; |
| 7438 | const int32_t tex_height = 32; |
| 7439 | VkImageCreateInfo image_create_info = {}; |
| 7440 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 7441 | image_create_info.pNext = NULL; |
| 7442 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 7443 | image_create_info.format = tex_format; |
| 7444 | image_create_info.extent.width = tex_width; |
| 7445 | image_create_info.extent.height = tex_height; |
| 7446 | image_create_info.extent.depth = 1; |
| 7447 | image_create_info.mipLevels = 1; |
| 7448 | image_create_info.arrayLayers = 1; |
| 7449 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 7450 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 7451 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7452 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7453 | vk_testing::Image dstImage; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7454 | dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 7455 | reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7456 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7457 | const VkImageSubresourceRange range = vk_testing::Image::subresource_range( |
| 7458 | image_create_info, VK_IMAGE_ASPECT_COLOR_BIT); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7459 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7460 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), |
| 7461 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7462 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7463 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7464 | } |
| 7465 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7466 | TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7467 | // Call CmdClearDepthStencilImage within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7468 | m_errorMonitor->SetDesiredFailureMsg( |
| 7469 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7470 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7471 | |
| 7472 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7473 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7474 | |
| 7475 | // Renderpass is started here |
| 7476 | BeginCommandBuffer(); |
| 7477 | |
| 7478 | VkClearDepthStencilValue clear_value = {0}; |
Dustin Graves | a2e5c94 | 2016-02-11 18:28:06 -0700 | [diff] [blame] | 7479 | VkMemoryPropertyFlags reqs = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7480 | VkImageCreateInfo image_create_info = vk_testing::Image::create_info(); |
| 7481 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 7482 | image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 7483 | image_create_info.extent.width = 64; |
| 7484 | image_create_info.extent.height = 64; |
| 7485 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 7486 | image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7487 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7488 | vk_testing::Image dstImage; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7489 | dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 7490 | reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7491 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7492 | const VkImageSubresourceRange range = vk_testing::Image::subresource_range( |
| 7493 | image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7494 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7495 | vkCmdClearDepthStencilImage( |
| 7496 | m_commandBuffer->GetBufferHandle(), dstImage.handle(), |
| 7497 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, |
| 7498 | &range); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7499 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7500 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7501 | } |
| 7502 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7503 | TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) { |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 7504 | // Call CmdClearAttachmentss outside of an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7505 | VkResult err; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7506 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 7507 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7508 | "vkCmdClearAttachments: This call " |
| 7509 | "must be issued inside an active " |
| 7510 | "render pass"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7511 | |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7512 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7513 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7514 | |
| 7515 | // Start no RenderPass |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7516 | err = m_commandBuffer->BeginCommandBuffer(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7517 | ASSERT_VK_SUCCESS(err); |
| 7518 | |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 7519 | VkClearAttachment color_attachment; |
| 7520 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 7521 | color_attachment.clearValue.color.float32[0] = 0; |
| 7522 | color_attachment.clearValue.color.float32[1] = 0; |
| 7523 | color_attachment.clearValue.color.float32[2] = 0; |
| 7524 | color_attachment.clearValue.color.float32[3] = 0; |
| 7525 | color_attachment.colorAttachment = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7526 | VkClearRect clear_rect = {{{0, 0}, {32, 32}}}; |
| 7527 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 7528 | &color_attachment, 1, &clear_rect); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7529 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7530 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7531 | } |
| 7532 | |
Karl Schultz | 9e66a29 | 2016-04-21 15:57:51 -0600 | [diff] [blame] | 7533 | TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) { |
| 7534 | // Try to add a buffer memory barrier with no buffer. |
| 7535 | m_errorMonitor->SetDesiredFailureMsg( |
| 7536 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7537 | "required parameter pBufferMemoryBarriers[i].buffer specified as VK_NULL_HANDLE"); |
| 7538 | |
| 7539 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7540 | BeginCommandBuffer(); |
| 7541 | |
| 7542 | VkBufferMemoryBarrier buf_barrier = {}; |
| 7543 | buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; |
| 7544 | buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 7545 | buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 7546 | buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7547 | buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7548 | buf_barrier.buffer = VK_NULL_HANDLE; |
| 7549 | buf_barrier.offset = 0; |
| 7550 | buf_barrier.size = VK_WHOLE_SIZE; |
| 7551 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7552 | VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, |
| 7553 | 0, 0, nullptr, 1, &buf_barrier, 0, nullptr); |
| 7554 | |
| 7555 | m_errorMonitor->VerifyFound(); |
| 7556 | } |
| 7557 | |
Tony Barbour | 7fd5c0f | 2016-05-03 16:11:53 -0600 | [diff] [blame] | 7558 | TEST_F(VkLayerTest, InvalidBarriers) { |
| 7559 | TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER "); |
| 7560 | |
| 7561 | m_errorMonitor->SetDesiredFailureMsg( |
| 7562 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass"); |
| 7563 | |
| 7564 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7565 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7566 | |
| 7567 | VkMemoryBarrier mem_barrier = {}; |
| 7568 | mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER; |
| 7569 | mem_barrier.pNext = NULL; |
| 7570 | mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 7571 | mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 7572 | BeginCommandBuffer(); |
| 7573 | // BeginCommandBuffer() starts a render pass |
| 7574 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7575 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7576 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1, |
| 7577 | &mem_barrier, 0, nullptr, 0, nullptr); |
| 7578 | m_errorMonitor->VerifyFound(); |
| 7579 | |
| 7580 | m_errorMonitor->SetDesiredFailureMsg( |
| 7581 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7582 | "Image Layout cannot be transitioned to UNDEFINED"); |
| 7583 | VkImageObj image(m_device); |
| 7584 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 7585 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 7586 | ASSERT_TRUE(image.initialized()); |
| 7587 | VkImageMemoryBarrier img_barrier = {}; |
| 7588 | img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 7589 | img_barrier.pNext = NULL; |
| 7590 | img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 7591 | img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 7592 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 7593 | // New layout can't be UNDEFINED |
| 7594 | img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 7595 | img_barrier.image = image.handle(); |
| 7596 | img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7597 | img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7598 | img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 7599 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 7600 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 7601 | img_barrier.subresourceRange.layerCount = 1; |
| 7602 | img_barrier.subresourceRange.levelCount = 1; |
| 7603 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7604 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7605 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 7606 | nullptr, 1, &img_barrier); |
| 7607 | m_errorMonitor->VerifyFound(); |
| 7608 | img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 7609 | |
| 7610 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7611 | "Subresource must have the sum of the " |
| 7612 | "baseArrayLayer"); |
| 7613 | // baseArrayLayer + layerCount must be <= image's arrayLayers |
| 7614 | img_barrier.subresourceRange.baseArrayLayer = 1; |
| 7615 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7616 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7617 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 7618 | nullptr, 1, &img_barrier); |
| 7619 | m_errorMonitor->VerifyFound(); |
| 7620 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 7621 | |
| 7622 | m_errorMonitor->SetDesiredFailureMsg( |
| 7623 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7624 | "Subresource must have the sum of the baseMipLevel"); |
| 7625 | // baseMipLevel + levelCount must be <= image's mipLevels |
| 7626 | img_barrier.subresourceRange.baseMipLevel = 1; |
| 7627 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7628 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7629 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 7630 | nullptr, 1, &img_barrier); |
| 7631 | m_errorMonitor->VerifyFound(); |
| 7632 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 7633 | |
| 7634 | m_errorMonitor->SetDesiredFailureMsg( |
| 7635 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7636 | "Buffer Barriers cannot be used during a render pass"); |
| 7637 | vk_testing::Buffer buffer; |
| 7638 | buffer.init(*m_device, 256); |
| 7639 | VkBufferMemoryBarrier buf_barrier = {}; |
| 7640 | buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; |
| 7641 | buf_barrier.pNext = NULL; |
| 7642 | buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 7643 | buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 7644 | buf_barrier.buffer = buffer.handle(); |
| 7645 | buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7646 | buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7647 | buf_barrier.offset = 0; |
| 7648 | buf_barrier.size = VK_WHOLE_SIZE; |
| 7649 | // Can't send buffer barrier during a render pass |
| 7650 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7651 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7652 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 7653 | &buf_barrier, 0, nullptr); |
| 7654 | m_errorMonitor->VerifyFound(); |
| 7655 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 7656 | |
| 7657 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7658 | "which is not less than total size"); |
| 7659 | buf_barrier.offset = 257; |
| 7660 | // Offset greater than total size |
| 7661 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7662 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7663 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 7664 | &buf_barrier, 0, nullptr); |
| 7665 | m_errorMonitor->VerifyFound(); |
| 7666 | buf_barrier.offset = 0; |
| 7667 | |
| 7668 | m_errorMonitor->SetDesiredFailureMsg( |
| 7669 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size"); |
| 7670 | buf_barrier.size = 257; |
| 7671 | // Size greater than total size |
| 7672 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7673 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7674 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 7675 | &buf_barrier, 0, nullptr); |
| 7676 | m_errorMonitor->VerifyFound(); |
| 7677 | buf_barrier.size = VK_WHOLE_SIZE; |
| 7678 | |
| 7679 | m_errorMonitor->SetDesiredFailureMsg( |
| 7680 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7681 | "Image is a depth and stencil format and thus must " |
| 7682 | "have both VK_IMAGE_ASPECT_DEPTH_BIT and " |
| 7683 | "VK_IMAGE_ASPECT_STENCIL_BIT set."); |
| 7684 | VkDepthStencilObj ds_image(m_device); |
| 7685 | ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT); |
| 7686 | ASSERT_TRUE(ds_image.initialized()); |
| 7687 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 7688 | img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 7689 | img_barrier.image = ds_image.handle(); |
| 7690 | // Leave aspectMask at COLOR on purpose |
| 7691 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7692 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7693 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 7694 | nullptr, 1, &img_barrier); |
| 7695 | m_errorMonitor->VerifyFound(); |
| 7696 | } |
| 7697 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7698 | TEST_F(VkLayerTest, IdxBufferAlignmentError) { |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7699 | // Bind a BeginRenderPass within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7700 | VkResult err; |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7701 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7702 | m_errorMonitor->SetDesiredFailureMsg( |
| 7703 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7704 | "vkCmdBindIndexBuffer() offset (0x7) does not fall on "); |
| 7705 | |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7706 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7707 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7708 | uint32_t qfi = 0; |
| 7709 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7710 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 7711 | buffCI.size = 1024; |
| 7712 | buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; |
| 7713 | buffCI.queueFamilyIndexCount = 1; |
| 7714 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7715 | |
| 7716 | VkBuffer ib; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7717 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7718 | ASSERT_VK_SUCCESS(err); |
| 7719 | |
| 7720 | BeginCommandBuffer(); |
| 7721 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7722 | // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7723 | // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7724 | // 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] | 7725 | vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, |
| 7726 | VK_INDEX_TYPE_UINT16); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7727 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7728 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 7729 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7730 | vkDestroyBuffer(m_device->device(), ib, NULL); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7731 | } |
| 7732 | |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 7733 | TEST_F(VkLayerTest, InvalidQueueFamilyIndex) { |
| 7734 | // Create an out-of-range queueFamilyIndex |
| 7735 | m_errorMonitor->SetDesiredFailureMsg( |
| 7736 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Dustin Graves | de62853 | 2016-04-21 16:30:17 -0600 | [diff] [blame] | 7737 | "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one " |
| 7738 | "of the indices specified when the device was created, via the " |
| 7739 | "VkDeviceQueueCreateInfo structure."); |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 7740 | |
| 7741 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7742 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7743 | VkBufferCreateInfo buffCI = {}; |
| 7744 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 7745 | buffCI.size = 1024; |
| 7746 | buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; |
| 7747 | buffCI.queueFamilyIndexCount = 1; |
| 7748 | // Introduce failure by specifying invalid queue_family_index |
| 7749 | uint32_t qfi = 777; |
| 7750 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 24aab04 | 2016-03-24 10:54:18 -0600 | [diff] [blame] | 7751 | buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 7752 | |
| 7753 | VkBuffer ib; |
| 7754 | vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib); |
| 7755 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7756 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7757 | vkDestroyBuffer(m_device->device(), ib, NULL); |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 7758 | } |
| 7759 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7760 | TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) { |
| 7761 | // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be |
| 7762 | // secondary) |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7763 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7764 | m_errorMonitor->SetDesiredFailureMsg( |
| 7765 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7766 | "vkCmdExecuteCommands() called w/ Primary Cmd Buffer "); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 7767 | |
| 7768 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7769 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 7770 | |
| 7771 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7772 | // ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7773 | VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle(); |
| 7774 | vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 7775 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7776 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 7777 | } |
| 7778 | |
Tobin Ehlis | 17826bd | 2016-05-25 11:12:50 -0600 | [diff] [blame] | 7779 | TEST_F(VkLayerTest, DSUsageBitsErrors) { |
| 7780 | TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers " |
| 7781 | "that do not have correct usage bits sets."); |
| 7782 | VkResult err; |
| 7783 | |
| 7784 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7785 | VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {}; |
| 7786 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 7787 | ds_type_count[i].type = VkDescriptorType(i); |
| 7788 | ds_type_count[i].descriptorCount = 1; |
| 7789 | } |
| 7790 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 7791 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7792 | ds_pool_ci.pNext = NULL; |
| 7793 | ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 7794 | ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 7795 | ds_pool_ci.pPoolSizes = ds_type_count; |
| 7796 | |
| 7797 | VkDescriptorPool ds_pool; |
| 7798 | err = |
| 7799 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 7800 | ASSERT_VK_SUCCESS(err); |
| 7801 | |
| 7802 | // Create 10 layouts where each has a single descriptor of different type |
| 7803 | VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = |
| 7804 | {}; |
| 7805 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 7806 | dsl_binding[i].binding = 0; |
| 7807 | dsl_binding[i].descriptorType = VkDescriptorType(i); |
| 7808 | dsl_binding[i].descriptorCount = 1; |
| 7809 | dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL; |
| 7810 | dsl_binding[i].pImmutableSamplers = NULL; |
| 7811 | } |
| 7812 | |
| 7813 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 7814 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7815 | ds_layout_ci.pNext = NULL; |
| 7816 | ds_layout_ci.bindingCount = 1; |
| 7817 | VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE]; |
| 7818 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 7819 | ds_layout_ci.pBindings = dsl_binding + i; |
| 7820 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, |
| 7821 | NULL, ds_layouts + i); |
| 7822 | ASSERT_VK_SUCCESS(err); |
| 7823 | } |
| 7824 | VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {}; |
| 7825 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 7826 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 7827 | alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 7828 | alloc_info.descriptorPool = ds_pool; |
| 7829 | alloc_info.pSetLayouts = ds_layouts; |
| 7830 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7831 | descriptor_sets); |
| 7832 | ASSERT_VK_SUCCESS(err); |
| 7833 | |
| 7834 | // Create a buffer & bufferView to be used for invalid updates |
| 7835 | VkBufferCreateInfo buff_ci = {}; |
| 7836 | buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 7837 | // This usage is not valid for any descriptor type |
| 7838 | buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; |
| 7839 | buff_ci.size = 256; |
| 7840 | buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 7841 | VkBuffer buffer; |
| 7842 | err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer); |
| 7843 | ASSERT_VK_SUCCESS(err); |
| 7844 | |
| 7845 | VkBufferViewCreateInfo buff_view_ci = {}; |
| 7846 | buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; |
| 7847 | buff_view_ci.buffer = buffer; |
| 7848 | buff_view_ci.format = VK_FORMAT_R8_UNORM; |
| 7849 | buff_view_ci.range = VK_WHOLE_SIZE; |
| 7850 | VkBufferView buff_view; |
| 7851 | err = |
| 7852 | vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view); |
| 7853 | ASSERT_VK_SUCCESS(err); |
| 7854 | |
| 7855 | // Create an image to be used for invalid updates |
| 7856 | VkImageCreateInfo image_ci = {}; |
| 7857 | image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 7858 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 7859 | image_ci.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 7860 | image_ci.extent.width = 64; |
| 7861 | image_ci.extent.height = 64; |
| 7862 | image_ci.extent.depth = 1; |
| 7863 | image_ci.mipLevels = 1; |
| 7864 | image_ci.arrayLayers = 1; |
| 7865 | image_ci.samples = VK_SAMPLE_COUNT_1_BIT; |
| 7866 | image_ci.tiling = VK_IMAGE_TILING_LINEAR; |
| 7867 | image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 7868 | // This usage is not valid for any descriptor type |
| 7869 | image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 7870 | image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 7871 | VkImage image; |
| 7872 | err = vkCreateImage(m_device->device(), &image_ci, NULL, &image); |
| 7873 | ASSERT_VK_SUCCESS(err); |
| 7874 | // Bind memory to image |
| 7875 | VkMemoryRequirements mem_reqs; |
| 7876 | VkDeviceMemory image_mem; |
| 7877 | bool pass; |
| 7878 | VkMemoryAllocateInfo mem_alloc = {}; |
| 7879 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 7880 | mem_alloc.pNext = NULL; |
| 7881 | mem_alloc.allocationSize = 0; |
| 7882 | mem_alloc.memoryTypeIndex = 0; |
| 7883 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 7884 | mem_alloc.allocationSize = mem_reqs.size; |
| 7885 | pass = |
| 7886 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 7887 | ASSERT_TRUE(pass); |
| 7888 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem); |
| 7889 | ASSERT_VK_SUCCESS(err); |
| 7890 | err = vkBindImageMemory(m_device->device(), image, image_mem, 0); |
| 7891 | ASSERT_VK_SUCCESS(err); |
| 7892 | // Now create view for image |
| 7893 | VkImageViewCreateInfo image_view_ci = {}; |
| 7894 | image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 7895 | image_view_ci.image = image; |
| 7896 | image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 7897 | image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 7898 | image_view_ci.subresourceRange.layerCount = 1; |
| 7899 | image_view_ci.subresourceRange.baseArrayLayer = 0; |
| 7900 | image_view_ci.subresourceRange.levelCount = 1; |
| 7901 | image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 7902 | VkImageView image_view; |
| 7903 | err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, |
| 7904 | &image_view); |
| 7905 | ASSERT_VK_SUCCESS(err); |
| 7906 | |
| 7907 | VkDescriptorBufferInfo buff_info = {}; |
| 7908 | buff_info.buffer = buffer; |
| 7909 | VkDescriptorImageInfo img_info = {}; |
| 7910 | img_info.imageView = image_view; |
| 7911 | VkWriteDescriptorSet descriptor_write = {}; |
| 7912 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 7913 | descriptor_write.dstBinding = 0; |
| 7914 | descriptor_write.descriptorCount = 1; |
| 7915 | descriptor_write.pTexelBufferView = &buff_view; |
| 7916 | descriptor_write.pBufferInfo = &buff_info; |
| 7917 | descriptor_write.pImageInfo = &img_info; |
| 7918 | |
| 7919 | // These error messages align with VkDescriptorType struct |
| 7920 | const char *error_msgs[] = { |
| 7921 | "", // placeholder, no error for SAMPLER descriptor |
| 7922 | " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.", |
| 7923 | " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.", |
| 7924 | " does not have VK_IMAGE_USAGE_STORAGE_BIT set.", |
| 7925 | " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.", |
| 7926 | " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.", |
| 7927 | " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.", |
| 7928 | " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.", |
| 7929 | " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.", |
| 7930 | " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.", |
| 7931 | " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."}; |
| 7932 | // Start loop at 1 as SAMPLER desc type has no usage bit error |
| 7933 | for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 7934 | descriptor_write.descriptorType = VkDescriptorType(i); |
| 7935 | descriptor_write.dstSet = descriptor_sets[i]; |
| 7936 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7937 | error_msgs[i]); |
| 7938 | |
| 7939 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, |
| 7940 | NULL); |
| 7941 | |
| 7942 | m_errorMonitor->VerifyFound(); |
| 7943 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL); |
| 7944 | } |
| 7945 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL); |
| 7946 | vkDestroyImage(m_device->device(), image, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7947 | vkFreeMemory(m_device->device(), image_mem, NULL); |
Tobin Ehlis | 17826bd | 2016-05-25 11:12:50 -0600 | [diff] [blame] | 7948 | vkDestroyImageView(m_device->device(), image_view, NULL); |
| 7949 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 7950 | vkDestroyBufferView(m_device->device(), buff_view, NULL); |
| 7951 | vkFreeDescriptorSets(m_device->device(), ds_pool, |
| 7952 | VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets); |
| 7953 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 7954 | } |
| 7955 | |
Tobin Ehlis | 2fc296b | 2016-06-15 14:05:27 -0600 | [diff] [blame] | 7956 | TEST_F(VkLayerTest, DSAspectBitsErrors) { |
| 7957 | // TODO : Initially only catching case where DEPTH & STENCIL aspect bits |
| 7958 | // are set, but could expand this test to hit more cases. |
| 7959 | TEST_DESCRIPTION("Attempt to update descriptor sets for images " |
| 7960 | "that do not have correct aspect bits sets."); |
| 7961 | VkResult err; |
| 7962 | |
| 7963 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7964 | VkDescriptorPoolSize ds_type_count = {}; |
| 7965 | ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 7966 | ds_type_count.descriptorCount = 1; |
| 7967 | |
| 7968 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 7969 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7970 | ds_pool_ci.pNext = NULL; |
| 7971 | ds_pool_ci.maxSets = 5; |
| 7972 | ds_pool_ci.poolSizeCount = 1; |
| 7973 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 7974 | |
| 7975 | VkDescriptorPool ds_pool; |
| 7976 | err = |
| 7977 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 7978 | ASSERT_VK_SUCCESS(err); |
| 7979 | |
| 7980 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 7981 | dsl_binding.binding = 0; |
| 7982 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 7983 | dsl_binding.descriptorCount = 1; |
| 7984 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7985 | dsl_binding.pImmutableSamplers = NULL; |
| 7986 | |
| 7987 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 7988 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7989 | ds_layout_ci.pNext = NULL; |
| 7990 | ds_layout_ci.bindingCount = 1; |
| 7991 | ds_layout_ci.pBindings = &dsl_binding; |
| 7992 | VkDescriptorSetLayout ds_layout; |
| 7993 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7994 | &ds_layout); |
| 7995 | ASSERT_VK_SUCCESS(err); |
| 7996 | |
| 7997 | VkDescriptorSet descriptor_set = {}; |
| 7998 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 7999 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 8000 | alloc_info.descriptorSetCount = 1; |
| 8001 | alloc_info.descriptorPool = ds_pool; |
| 8002 | alloc_info.pSetLayouts = &ds_layout; |
| 8003 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8004 | &descriptor_set); |
| 8005 | ASSERT_VK_SUCCESS(err); |
| 8006 | |
| 8007 | // Create an image to be used for invalid updates |
| 8008 | VkImageCreateInfo image_ci = {}; |
| 8009 | image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 8010 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 8011 | image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 8012 | image_ci.extent.width = 64; |
| 8013 | image_ci.extent.height = 64; |
| 8014 | image_ci.extent.depth = 1; |
| 8015 | image_ci.mipLevels = 1; |
| 8016 | image_ci.arrayLayers = 1; |
| 8017 | image_ci.samples = VK_SAMPLE_COUNT_1_BIT; |
| 8018 | image_ci.tiling = VK_IMAGE_TILING_LINEAR; |
| 8019 | image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 8020 | image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 8021 | image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 8022 | VkImage image; |
| 8023 | err = vkCreateImage(m_device->device(), &image_ci, NULL, &image); |
| 8024 | ASSERT_VK_SUCCESS(err); |
| 8025 | // Bind memory to image |
| 8026 | VkMemoryRequirements mem_reqs; |
| 8027 | VkDeviceMemory image_mem; |
| 8028 | bool pass; |
| 8029 | VkMemoryAllocateInfo mem_alloc = {}; |
| 8030 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 8031 | mem_alloc.pNext = NULL; |
| 8032 | mem_alloc.allocationSize = 0; |
| 8033 | mem_alloc.memoryTypeIndex = 0; |
| 8034 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 8035 | mem_alloc.allocationSize = mem_reqs.size; |
| 8036 | pass = |
| 8037 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 8038 | ASSERT_TRUE(pass); |
| 8039 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem); |
| 8040 | ASSERT_VK_SUCCESS(err); |
| 8041 | err = vkBindImageMemory(m_device->device(), image, image_mem, 0); |
| 8042 | ASSERT_VK_SUCCESS(err); |
| 8043 | // Now create view for image |
| 8044 | VkImageViewCreateInfo image_view_ci = {}; |
| 8045 | image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 8046 | image_view_ci.image = image; |
| 8047 | image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 8048 | image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 8049 | image_view_ci.subresourceRange.layerCount = 1; |
| 8050 | image_view_ci.subresourceRange.baseArrayLayer = 0; |
| 8051 | image_view_ci.subresourceRange.levelCount = 1; |
| 8052 | // Setting both depth & stencil aspect bits is illegal for descriptor |
| 8053 | image_view_ci.subresourceRange.aspectMask = |
| 8054 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 8055 | |
| 8056 | VkImageView image_view; |
| 8057 | err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, |
| 8058 | &image_view); |
| 8059 | ASSERT_VK_SUCCESS(err); |
| 8060 | |
| 8061 | VkDescriptorImageInfo img_info = {}; |
| 8062 | img_info.imageView = image_view; |
| 8063 | VkWriteDescriptorSet descriptor_write = {}; |
| 8064 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 8065 | descriptor_write.dstBinding = 0; |
| 8066 | descriptor_write.descriptorCount = 1; |
| 8067 | descriptor_write.pTexelBufferView = NULL; |
| 8068 | descriptor_write.pBufferInfo = NULL; |
| 8069 | descriptor_write.pImageInfo = &img_info; |
| 8070 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 8071 | descriptor_write.dstSet = descriptor_set; |
| 8072 | const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT " |
| 8073 | "or VK_IMAGE_ASPECT_STENCIL_BIT "; |
| 8074 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8075 | error_msg); |
| 8076 | |
| 8077 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8078 | |
| 8079 | m_errorMonitor->VerifyFound(); |
| 8080 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8081 | vkDestroyImage(m_device->device(), image, NULL); |
| 8082 | vkFreeMemory(m_device->device(), image_mem, NULL); |
| 8083 | vkDestroyImageView(m_device->device(), image_view, NULL); |
| 8084 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set); |
| 8085 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 8086 | } |
| 8087 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8088 | TEST_F(VkLayerTest, DSTypeMismatch) { |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8089 | // 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] | 8090 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8091 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8092 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8093 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8094 | " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update " |
| 8095 | "type is VK_DESCRIPTOR_TYPE_SAMPLER"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8096 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8097 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8098 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8099 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8100 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8101 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8102 | |
| 8103 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8104 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8105 | ds_pool_ci.pNext = NULL; |
| 8106 | ds_pool_ci.maxSets = 1; |
| 8107 | ds_pool_ci.poolSizeCount = 1; |
| 8108 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8109 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8110 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8111 | err = |
| 8112 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8113 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8114 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8115 | dsl_binding.binding = 0; |
| 8116 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8117 | dsl_binding.descriptorCount = 1; |
| 8118 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8119 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8120 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8121 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8122 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8123 | ds_layout_ci.pNext = NULL; |
| 8124 | ds_layout_ci.bindingCount = 1; |
| 8125 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8126 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8127 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8128 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8129 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8130 | ASSERT_VK_SUCCESS(err); |
| 8131 | |
| 8132 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8133 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8134 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8135 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8136 | alloc_info.descriptorPool = ds_pool; |
| 8137 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8138 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8139 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8140 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8141 | |
Tobin Ehlis | 30db8f8 | 2016-05-05 08:19:48 -0600 | [diff] [blame] | 8142 | VkSamplerCreateInfo sampler_ci = {}; |
| 8143 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8144 | sampler_ci.pNext = NULL; |
| 8145 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8146 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8147 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8148 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8149 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8150 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8151 | sampler_ci.mipLodBias = 1.0; |
| 8152 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8153 | sampler_ci.maxAnisotropy = 1; |
| 8154 | sampler_ci.compareEnable = VK_FALSE; |
| 8155 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8156 | sampler_ci.minLod = 1.0; |
| 8157 | sampler_ci.maxLod = 1.0; |
| 8158 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8159 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
| 8160 | VkSampler sampler; |
| 8161 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
| 8162 | ASSERT_VK_SUCCESS(err); |
| 8163 | |
| 8164 | VkDescriptorImageInfo info = {}; |
| 8165 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8166 | |
| 8167 | VkWriteDescriptorSet descriptor_write; |
| 8168 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8169 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8170 | descriptor_write.dstSet = descriptorSet; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8171 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8172 | // This is a mismatched type for the layout which expects BUFFER |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8173 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8174 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8175 | |
| 8176 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8177 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8178 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8179 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8180 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8181 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8182 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8183 | } |
| 8184 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8185 | TEST_F(VkLayerTest, DSUpdateOutOfBounds) { |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8186 | // For overlapping Update, have arrayIndex exceed that of layout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8187 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8188 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8189 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8190 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8191 | " binding #0 with 1 total descriptors but update of 1 descriptors " |
| 8192 | "starting at binding offset of 0 combined with update array element " |
| 8193 | "offset of 1 oversteps the size of this descriptor set."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8194 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8195 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8196 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8197 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8198 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8199 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8200 | |
| 8201 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8202 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8203 | ds_pool_ci.pNext = NULL; |
| 8204 | ds_pool_ci.maxSets = 1; |
| 8205 | ds_pool_ci.poolSizeCount = 1; |
| 8206 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8207 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8208 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8209 | err = |
| 8210 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8211 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8212 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8213 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8214 | dsl_binding.binding = 0; |
| 8215 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8216 | dsl_binding.descriptorCount = 1; |
| 8217 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8218 | dsl_binding.pImmutableSamplers = NULL; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8219 | |
| 8220 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8221 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8222 | ds_layout_ci.pNext = NULL; |
| 8223 | ds_layout_ci.bindingCount = 1; |
| 8224 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8225 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8226 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8227 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8228 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8229 | ASSERT_VK_SUCCESS(err); |
| 8230 | |
| 8231 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8232 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8233 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8234 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8235 | alloc_info.descriptorPool = ds_pool; |
| 8236 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8237 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8238 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8239 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8240 | |
Tobin Ehlis | 30db8f8 | 2016-05-05 08:19:48 -0600 | [diff] [blame] | 8241 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 8242 | VkDescriptorBufferInfo buff_info = {}; |
| 8243 | buff_info.buffer = |
| 8244 | VkBuffer(0); // Don't care about buffer handle for this test |
| 8245 | buff_info.offset = 0; |
| 8246 | buff_info.range = 1024; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8247 | |
| 8248 | VkWriteDescriptorSet descriptor_write; |
| 8249 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8250 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8251 | descriptor_write.dstSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8252 | descriptor_write.dstArrayElement = |
| 8253 | 1; /* This index out of bounds for the update */ |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8254 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8255 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8256 | descriptor_write.pBufferInfo = &buff_info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8257 | |
| 8258 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8259 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8260 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8261 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8262 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8263 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8264 | } |
| 8265 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8266 | TEST_F(VkLayerTest, InvalidDSUpdateIndex) { |
| 8267 | // Create layout w/ count of 1 and attempt update to that layout w/ binding |
| 8268 | // index 2 |
| 8269 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8270 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8271 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8272 | " does not have binding 2."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8273 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8274 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8275 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8276 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8277 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8278 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8279 | |
| 8280 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8281 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8282 | ds_pool_ci.pNext = NULL; |
| 8283 | ds_pool_ci.maxSets = 1; |
| 8284 | ds_pool_ci.poolSizeCount = 1; |
| 8285 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 8286 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8287 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8288 | err = |
| 8289 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8290 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8291 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8292 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8293 | dsl_binding.binding = 0; |
| 8294 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8295 | dsl_binding.descriptorCount = 1; |
| 8296 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8297 | dsl_binding.pImmutableSamplers = NULL; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8298 | |
| 8299 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8300 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8301 | ds_layout_ci.pNext = NULL; |
| 8302 | ds_layout_ci.bindingCount = 1; |
| 8303 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8304 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8305 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8306 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8307 | ASSERT_VK_SUCCESS(err); |
| 8308 | |
| 8309 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8310 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8311 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8312 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8313 | alloc_info.descriptorPool = ds_pool; |
| 8314 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8315 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8316 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8317 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8318 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8319 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8320 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8321 | sampler_ci.pNext = NULL; |
| 8322 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8323 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8324 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8325 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8326 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8327 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8328 | sampler_ci.mipLodBias = 1.0; |
| 8329 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8330 | sampler_ci.maxAnisotropy = 1; |
| 8331 | sampler_ci.compareEnable = VK_FALSE; |
| 8332 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8333 | sampler_ci.minLod = 1.0; |
| 8334 | sampler_ci.maxLod = 1.0; |
| 8335 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8336 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8337 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8338 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8339 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8340 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8341 | |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8342 | VkDescriptorImageInfo info = {}; |
| 8343 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8344 | |
| 8345 | VkWriteDescriptorSet descriptor_write; |
| 8346 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8347 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8348 | descriptor_write.dstSet = descriptorSet; |
| 8349 | descriptor_write.dstBinding = 2; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8350 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8351 | // 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] | 8352 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8353 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8354 | |
| 8355 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8356 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8357 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8358 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8359 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8360 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8361 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8362 | } |
| 8363 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8364 | TEST_F(VkLayerTest, InvalidDSUpdateStruct) { |
| 8365 | // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* |
| 8366 | // types |
| 8367 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8368 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 8369 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 660bcdc | 2016-05-17 10:39:46 -0600 | [diff] [blame] | 8370 | ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8371 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8372 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 8373 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8374 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8375 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8376 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8377 | |
| 8378 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8379 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8380 | ds_pool_ci.pNext = NULL; |
| 8381 | ds_pool_ci.maxSets = 1; |
| 8382 | ds_pool_ci.poolSizeCount = 1; |
| 8383 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 8384 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8385 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8386 | err = |
| 8387 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8388 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8389 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8390 | dsl_binding.binding = 0; |
| 8391 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8392 | dsl_binding.descriptorCount = 1; |
| 8393 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8394 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8395 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8396 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8397 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8398 | ds_layout_ci.pNext = NULL; |
| 8399 | ds_layout_ci.bindingCount = 1; |
| 8400 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8401 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8402 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8403 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8404 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8405 | ASSERT_VK_SUCCESS(err); |
| 8406 | |
| 8407 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8408 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8409 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8410 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8411 | alloc_info.descriptorPool = ds_pool; |
| 8412 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8413 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8414 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8415 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8416 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8417 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8418 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8419 | sampler_ci.pNext = NULL; |
| 8420 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8421 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8422 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8423 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8424 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8425 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8426 | sampler_ci.mipLodBias = 1.0; |
| 8427 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8428 | sampler_ci.maxAnisotropy = 1; |
| 8429 | sampler_ci.compareEnable = VK_FALSE; |
| 8430 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8431 | sampler_ci.minLod = 1.0; |
| 8432 | sampler_ci.maxLod = 1.0; |
| 8433 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8434 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8435 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8436 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8437 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8438 | |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8439 | VkDescriptorImageInfo info = {}; |
| 8440 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8441 | |
| 8442 | VkWriteDescriptorSet descriptor_write; |
| 8443 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8444 | descriptor_write.sType = |
| 8445 | (VkStructureType)0x99999999; /* Intentionally broken struct type */ |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8446 | descriptor_write.dstSet = descriptorSet; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8447 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8448 | // 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] | 8449 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8450 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8451 | |
| 8452 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8453 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8454 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8455 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8456 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8457 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8458 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8459 | } |
| 8460 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8461 | TEST_F(VkLayerTest, SampleDescriptorUpdateError) { |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8462 | // Create a single Sampler descriptor and send it an invalid Sampler |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8463 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8464 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8465 | m_errorMonitor->SetDesiredFailureMsg( |
| 8466 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8467 | "Attempted write update to sampler descriptor with invalid sampler"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8468 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8469 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8470 | // TODO : Farm Descriptor setup code to helper function(s) to reduce copied |
| 8471 | // code |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8472 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8473 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8474 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8475 | |
| 8476 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8477 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8478 | ds_pool_ci.pNext = NULL; |
| 8479 | ds_pool_ci.maxSets = 1; |
| 8480 | ds_pool_ci.poolSizeCount = 1; |
| 8481 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8482 | |
| 8483 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8484 | err = |
| 8485 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8486 | ASSERT_VK_SUCCESS(err); |
| 8487 | |
| 8488 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8489 | dsl_binding.binding = 0; |
| 8490 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8491 | dsl_binding.descriptorCount = 1; |
| 8492 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8493 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8494 | |
| 8495 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8496 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8497 | ds_layout_ci.pNext = NULL; |
| 8498 | ds_layout_ci.bindingCount = 1; |
| 8499 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8500 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8501 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8502 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8503 | ASSERT_VK_SUCCESS(err); |
| 8504 | |
| 8505 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8506 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8507 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8508 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8509 | alloc_info.descriptorPool = ds_pool; |
| 8510 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8511 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8512 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8513 | ASSERT_VK_SUCCESS(err); |
| 8514 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8515 | VkSampler sampler = |
| 8516 | (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8517 | |
| 8518 | VkDescriptorImageInfo descriptor_info; |
| 8519 | memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo)); |
| 8520 | descriptor_info.sampler = sampler; |
| 8521 | |
| 8522 | VkWriteDescriptorSet descriptor_write; |
| 8523 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8524 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8525 | descriptor_write.dstSet = descriptorSet; |
| 8526 | descriptor_write.dstBinding = 0; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8527 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8528 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8529 | descriptor_write.pImageInfo = &descriptor_info; |
| 8530 | |
| 8531 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8532 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8533 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8534 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8535 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8536 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8537 | } |
| 8538 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8539 | TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) { |
| 8540 | // Create a single combined Image/Sampler descriptor and send it an invalid |
| 8541 | // imageView |
| 8542 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8543 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8544 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8545 | "Attempted write update to combined " |
| 8546 | "image sampler descriptor failed due " |
Tobin Ehlis | 63c4b8a | 2016-05-09 10:29:34 -0600 | [diff] [blame] | 8547 | "to: Invalid VkImageView:"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8548 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8549 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8550 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8551 | ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 8552 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8553 | |
| 8554 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8555 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8556 | ds_pool_ci.pNext = NULL; |
| 8557 | ds_pool_ci.maxSets = 1; |
| 8558 | ds_pool_ci.poolSizeCount = 1; |
| 8559 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8560 | |
| 8561 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8562 | err = |
| 8563 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8564 | ASSERT_VK_SUCCESS(err); |
| 8565 | |
| 8566 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8567 | dsl_binding.binding = 0; |
| 8568 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 8569 | dsl_binding.descriptorCount = 1; |
| 8570 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8571 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8572 | |
| 8573 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8574 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8575 | ds_layout_ci.pNext = NULL; |
| 8576 | ds_layout_ci.bindingCount = 1; |
| 8577 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8578 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8579 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8580 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8581 | ASSERT_VK_SUCCESS(err); |
| 8582 | |
| 8583 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8584 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8585 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8586 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8587 | alloc_info.descriptorPool = ds_pool; |
| 8588 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8589 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8590 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8591 | ASSERT_VK_SUCCESS(err); |
| 8592 | |
| 8593 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8594 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8595 | sampler_ci.pNext = NULL; |
| 8596 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8597 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8598 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8599 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8600 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8601 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8602 | sampler_ci.mipLodBias = 1.0; |
| 8603 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8604 | sampler_ci.maxAnisotropy = 1; |
| 8605 | sampler_ci.compareEnable = VK_FALSE; |
| 8606 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8607 | sampler_ci.minLod = 1.0; |
| 8608 | sampler_ci.maxLod = 1.0; |
| 8609 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8610 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8611 | |
| 8612 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8613 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8614 | ASSERT_VK_SUCCESS(err); |
| 8615 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8616 | VkImageView view = |
| 8617 | (VkImageView)((size_t)0xbaadbeef); // invalid imageView object |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8618 | |
| 8619 | VkDescriptorImageInfo descriptor_info; |
| 8620 | memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo)); |
| 8621 | descriptor_info.sampler = sampler; |
| 8622 | descriptor_info.imageView = view; |
| 8623 | |
| 8624 | VkWriteDescriptorSet descriptor_write; |
| 8625 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8626 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8627 | descriptor_write.dstSet = descriptorSet; |
| 8628 | descriptor_write.dstBinding = 0; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8629 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8630 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 8631 | descriptor_write.pImageInfo = &descriptor_info; |
| 8632 | |
| 8633 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8634 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8635 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8636 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8637 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8638 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8639 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8640 | } |
| 8641 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8642 | TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) { |
| 8643 | // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update |
| 8644 | // into the other |
| 8645 | VkResult err; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8646 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8647 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8648 | " binding #1 with type " |
| 8649 | "VK_DESCRIPTOR_TYPE_SAMPLER. Types do " |
| 8650 | "not match."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8651 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8652 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8653 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8654 | VkDescriptorPoolSize ds_type_count[2] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8655 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8656 | ds_type_count[0].descriptorCount = 1; |
| 8657 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8658 | ds_type_count[1].descriptorCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8659 | |
| 8660 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8661 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8662 | ds_pool_ci.pNext = NULL; |
| 8663 | ds_pool_ci.maxSets = 1; |
| 8664 | ds_pool_ci.poolSizeCount = 2; |
| 8665 | ds_pool_ci.pPoolSizes = ds_type_count; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8666 | |
| 8667 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8668 | err = |
| 8669 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8670 | ASSERT_VK_SUCCESS(err); |
| 8671 | VkDescriptorSetLayoutBinding dsl_binding[2] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8672 | dsl_binding[0].binding = 0; |
| 8673 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8674 | dsl_binding[0].descriptorCount = 1; |
| 8675 | dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 8676 | dsl_binding[0].pImmutableSamplers = NULL; |
| 8677 | dsl_binding[1].binding = 1; |
| 8678 | dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8679 | dsl_binding[1].descriptorCount = 1; |
| 8680 | dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL; |
| 8681 | dsl_binding[1].pImmutableSamplers = NULL; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8682 | |
| 8683 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8684 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8685 | ds_layout_ci.pNext = NULL; |
| 8686 | ds_layout_ci.bindingCount = 2; |
| 8687 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8688 | |
| 8689 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8690 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8691 | &ds_layout); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8692 | ASSERT_VK_SUCCESS(err); |
| 8693 | |
| 8694 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8695 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8696 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8697 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8698 | alloc_info.descriptorPool = ds_pool; |
| 8699 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8700 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8701 | &descriptorSet); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8702 | ASSERT_VK_SUCCESS(err); |
| 8703 | |
| 8704 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8705 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8706 | sampler_ci.pNext = NULL; |
| 8707 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8708 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8709 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8710 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8711 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8712 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8713 | sampler_ci.mipLodBias = 1.0; |
| 8714 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8715 | sampler_ci.maxAnisotropy = 1; |
| 8716 | sampler_ci.compareEnable = VK_FALSE; |
| 8717 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8718 | sampler_ci.minLod = 1.0; |
| 8719 | sampler_ci.maxLod = 1.0; |
| 8720 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8721 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8722 | |
| 8723 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8724 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8725 | ASSERT_VK_SUCCESS(err); |
| 8726 | |
| 8727 | VkDescriptorImageInfo info = {}; |
| 8728 | info.sampler = sampler; |
| 8729 | |
| 8730 | VkWriteDescriptorSet descriptor_write; |
| 8731 | memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet)); |
| 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 = 1; // SAMPLER binding from layout above |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8735 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8736 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8737 | descriptor_write.pImageInfo = &info; |
| 8738 | // This write update should succeed |
| 8739 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8740 | // Now perform a copy update that fails due to type mismatch |
| 8741 | VkCopyDescriptorSet copy_ds_update; |
| 8742 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 8743 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 8744 | copy_ds_update.srcSet = descriptorSet; |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 8745 | copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8746 | copy_ds_update.dstSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8747 | copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8748 | copy_ds_update.descriptorCount = 1; // copy 1 descriptor |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8749 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 8750 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8751 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8752 | // 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] | 8753 | m_errorMonitor->SetDesiredFailureMsg( |
| 8754 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8755 | " does not have copy update src binding of 3."); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8756 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 8757 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 8758 | copy_ds_update.srcSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8759 | copy_ds_update.srcBinding = |
| 8760 | 3; // ERROR : Invalid binding for matching layout |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8761 | copy_ds_update.dstSet = descriptorSet; |
| 8762 | copy_ds_update.dstBinding = 0; |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 8763 | copy_ds_update.descriptorCount = 1; // Copy 1 descriptor |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8764 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 8765 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8766 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8767 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8768 | // 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] | 8769 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8770 | VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus " |
| 8771 | "update array offset of 0 and update of " |
| 8772 | "5 descriptors oversteps total number " |
| 8773 | "of descriptors in set: 2."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8774 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8775 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 8776 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 8777 | copy_ds_update.srcSet = descriptorSet; |
| 8778 | copy_ds_update.srcBinding = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8779 | copy_ds_update.dstSet = descriptorSet; |
| 8780 | copy_ds_update.dstBinding = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8781 | copy_ds_update.descriptorCount = |
| 8782 | 5; // ERROR copy 5 descriptors (out of bounds for layout) |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8783 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 8784 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8785 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8786 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8787 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8788 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8789 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8790 | } |
| 8791 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8792 | TEST_F(VkLayerTest, NumSamplesMismatch) { |
| 8793 | // Create CommandBuffer where MSAA samples doesn't match RenderPass |
| 8794 | // sampleCount |
| 8795 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8796 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 8797 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8798 | "Num samples mismatch! "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8799 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8800 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8801 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8802 | VkDescriptorPoolSize ds_type_count = {}; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8803 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8804 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8805 | |
| 8806 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8807 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8808 | ds_pool_ci.pNext = NULL; |
| 8809 | ds_pool_ci.maxSets = 1; |
| 8810 | ds_pool_ci.poolSizeCount = 1; |
| 8811 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 8812 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8813 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8814 | err = |
| 8815 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8816 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8817 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8818 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 8819 | dsl_binding.binding = 0; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8820 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | 0212448 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 8821 | dsl_binding.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8822 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8823 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8824 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8825 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 8826 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8827 | ds_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8828 | ds_layout_ci.bindingCount = 1; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 8829 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8830 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8831 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8832 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8833 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8834 | ASSERT_VK_SUCCESS(err); |
| 8835 | |
| 8836 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8837 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8838 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8839 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8840 | alloc_info.descriptorPool = ds_pool; |
| 8841 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8842 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8843 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8844 | ASSERT_VK_SUCCESS(err); |
| 8845 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8846 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8847 | pipe_ms_state_ci.sType = |
| 8848 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 8849 | pipe_ms_state_ci.pNext = NULL; |
| 8850 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT; |
| 8851 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 8852 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 8853 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8854 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8855 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8856 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 8857 | pipeline_layout_ci.pNext = NULL; |
| 8858 | pipeline_layout_ci.setLayoutCount = 1; |
| 8859 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8860 | |
| 8861 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8862 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 8863 | &pipeline_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8864 | ASSERT_VK_SUCCESS(err); |
| 8865 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8866 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 8867 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 8868 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 8869 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 8870 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8871 | // but add it to be able to run on more devices |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 8872 | VkPipelineObj pipe(m_device); |
| 8873 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 8874 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 8875 | pipe.AddColorAttachment(); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 8876 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 8877 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8878 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 8879 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8880 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 8881 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8882 | |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 8883 | // Render triangle (the error should trigger on the attempt to draw). |
| 8884 | Draw(3, 1, 0, 0); |
| 8885 | |
| 8886 | // Finalize recording of the command buffer |
| 8887 | EndCommandBuffer(); |
| 8888 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8889 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8890 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8891 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 8892 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8893 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8894 | } |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 8895 | |
Tobin Ehlis | 85aa15a | 2016-06-15 10:52:37 -0600 | [diff] [blame] | 8896 | TEST_F(VkLayerTest, RenderPassIncompatible) { |
| 8897 | TEST_DESCRIPTION("Hit RenderPass incompatible cases. " |
| 8898 | "Initial case is drawing with an active renderpass that's " |
| 8899 | "not compatible with the bound PSO's creation renderpass"); |
| 8900 | VkResult err; |
| 8901 | |
| 8902 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8903 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8904 | |
| 8905 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 8906 | dsl_binding.binding = 0; |
| 8907 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8908 | dsl_binding.descriptorCount = 1; |
| 8909 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8910 | dsl_binding.pImmutableSamplers = NULL; |
| 8911 | |
| 8912 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 8913 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8914 | ds_layout_ci.pNext = NULL; |
| 8915 | ds_layout_ci.bindingCount = 1; |
| 8916 | ds_layout_ci.pBindings = &dsl_binding; |
| 8917 | |
| 8918 | VkDescriptorSetLayout ds_layout; |
| 8919 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8920 | &ds_layout); |
| 8921 | ASSERT_VK_SUCCESS(err); |
| 8922 | |
| 8923 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 8924 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 8925 | pipeline_layout_ci.pNext = NULL; |
| 8926 | pipeline_layout_ci.setLayoutCount = 1; |
| 8927 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 8928 | |
| 8929 | VkPipelineLayout pipeline_layout; |
| 8930 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 8931 | &pipeline_layout); |
| 8932 | ASSERT_VK_SUCCESS(err); |
| 8933 | |
| 8934 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 8935 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 8936 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 8937 | VK_SHADER_STAGE_FRAGMENT_BIT, |
| 8938 | this); // We shouldn't need a fragment shader |
| 8939 | // but add it to be able to run on more devices |
| 8940 | // Create a renderpass that will be incompatible with default renderpass |
| 8941 | VkAttachmentReference attach = {}; |
| 8942 | attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 8943 | VkAttachmentReference color_att = {}; |
| 8944 | color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 8945 | VkSubpassDescription subpass = {}; |
| 8946 | subpass.inputAttachmentCount = 1; |
| 8947 | subpass.pInputAttachments = &attach; |
| 8948 | subpass.colorAttachmentCount = 1; |
| 8949 | subpass.pColorAttachments = &color_att; |
| 8950 | VkRenderPassCreateInfo rpci = {}; |
| 8951 | rpci.subpassCount = 1; |
| 8952 | rpci.pSubpasses = &subpass; |
| 8953 | rpci.attachmentCount = 1; |
| 8954 | VkAttachmentDescription attach_desc = {}; |
| 8955 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
| 8956 | // Format incompatible with PSO RP color attach format RGBA8_UNORM |
| 8957 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 8958 | rpci.pAttachments = &attach_desc; |
| 8959 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 8960 | VkRenderPass rp; |
| 8961 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 8962 | VkPipelineObj pipe(m_device); |
| 8963 | pipe.AddShader(&vs); |
| 8964 | pipe.AddShader(&fs); |
| 8965 | pipe.AddColorAttachment(); |
| 8966 | VkViewport view_port = {}; |
| 8967 | m_viewports.push_back(view_port); |
| 8968 | pipe.SetViewport(m_viewports); |
| 8969 | VkRect2D rect = {}; |
| 8970 | m_scissors.push_back(rect); |
| 8971 | pipe.SetScissor(m_scissors); |
| 8972 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 8973 | |
| 8974 | VkCommandBufferInheritanceInfo cbii = {}; |
| 8975 | cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; |
| 8976 | cbii.renderPass = rp; |
| 8977 | cbii.subpass = 0; |
| 8978 | VkCommandBufferBeginInfo cbbi = {}; |
| 8979 | cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 8980 | cbbi.pInheritanceInfo = &cbii; |
| 8981 | vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi); |
| 8982 | VkRenderPassBeginInfo rpbi = {}; |
| 8983 | rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 8984 | rpbi.framebuffer = m_framebuffer; |
| 8985 | rpbi.renderPass = rp; |
| 8986 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, |
| 8987 | VK_SUBPASS_CONTENTS_INLINE); |
| 8988 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 8989 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 8990 | |
| 8991 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8992 | " is incompatible w/ gfx pipeline "); |
| 8993 | // Render triangle (the error should trigger on the attempt to draw). |
| 8994 | Draw(3, 1, 0, 0); |
| 8995 | |
| 8996 | // Finalize recording of the command buffer |
| 8997 | EndCommandBuffer(); |
| 8998 | |
| 8999 | m_errorMonitor->VerifyFound(); |
| 9000 | |
| 9001 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9002 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9003 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 9004 | } |
| 9005 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9006 | TEST_F(VkLayerTest, NumBlendAttachMismatch) { |
| 9007 | // Create Pipeline where the number of blend attachments doesn't match the |
| 9008 | // number of color attachments. In this case, we don't add any color |
| 9009 | // blend attachments even though we have a color attachment. |
| 9010 | VkResult err; |
| 9011 | |
| 9012 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9013 | "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] | 9014 | |
| 9015 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9016 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9017 | VkDescriptorPoolSize ds_type_count = {}; |
| 9018 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9019 | ds_type_count.descriptorCount = 1; |
| 9020 | |
| 9021 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 9022 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9023 | ds_pool_ci.pNext = NULL; |
| 9024 | ds_pool_ci.maxSets = 1; |
| 9025 | ds_pool_ci.poolSizeCount = 1; |
| 9026 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 9027 | |
| 9028 | VkDescriptorPool ds_pool; |
| 9029 | err = |
| 9030 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 9031 | ASSERT_VK_SUCCESS(err); |
| 9032 | |
| 9033 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 9034 | dsl_binding.binding = 0; |
| 9035 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9036 | dsl_binding.descriptorCount = 1; |
| 9037 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9038 | dsl_binding.pImmutableSamplers = NULL; |
| 9039 | |
| 9040 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9041 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9042 | ds_layout_ci.pNext = NULL; |
| 9043 | ds_layout_ci.bindingCount = 1; |
| 9044 | ds_layout_ci.pBindings = &dsl_binding; |
| 9045 | |
| 9046 | VkDescriptorSetLayout ds_layout; |
| 9047 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9048 | &ds_layout); |
| 9049 | ASSERT_VK_SUCCESS(err); |
| 9050 | |
| 9051 | VkDescriptorSet descriptorSet; |
| 9052 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 9053 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 9054 | alloc_info.descriptorSetCount = 1; |
| 9055 | alloc_info.descriptorPool = ds_pool; |
| 9056 | alloc_info.pSetLayouts = &ds_layout; |
| 9057 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9058 | &descriptorSet); |
| 9059 | ASSERT_VK_SUCCESS(err); |
| 9060 | |
| 9061 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
| 9062 | pipe_ms_state_ci.sType = |
| 9063 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9064 | pipe_ms_state_ci.pNext = NULL; |
| 9065 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; |
| 9066 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9067 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9068 | pipe_ms_state_ci.pSampleMask = NULL; |
| 9069 | |
| 9070 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 9071 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9072 | pipeline_layout_ci.pNext = NULL; |
| 9073 | pipeline_layout_ci.setLayoutCount = 1; |
| 9074 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 9075 | |
| 9076 | VkPipelineLayout pipeline_layout; |
| 9077 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9078 | &pipeline_layout); |
| 9079 | ASSERT_VK_SUCCESS(err); |
| 9080 | |
| 9081 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9082 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9083 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9084 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9085 | this); // We shouldn't need a fragment shader |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9086 | // but add it to be able to run on more devices |
| 9087 | VkPipelineObj pipe(m_device); |
| 9088 | pipe.AddShader(&vs); |
| 9089 | pipe.AddShader(&fs); |
| 9090 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 9091 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 9092 | |
| 9093 | BeginCommandBuffer(); |
| 9094 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9095 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 9096 | |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9097 | // Render triangle (the error should trigger on the attempt to draw). |
| 9098 | Draw(3, 1, 0, 0); |
| 9099 | |
| 9100 | // Finalize recording of the command buffer |
| 9101 | EndCommandBuffer(); |
| 9102 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9103 | m_errorMonitor->VerifyFound(); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9104 | |
| 9105 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9106 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9107 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 9108 | } |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9109 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 9110 | TEST_F(VkLayerTest, MissingClearAttachment) { |
| 9111 | TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment " |
| 9112 | "structure passed to vkCmdClearAttachments"); |
| 9113 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9114 | "vkCmdClearAttachments() attachment index 1 not found in attachment " |
| 9115 | "reference array of active subpass 0"); |
| 9116 | |
| 9117 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments); |
| 9118 | m_errorMonitor->VerifyFound(); |
| 9119 | } |
| 9120 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9121 | TEST_F(VkLayerTest, ClearCmdNoDraw) { |
| 9122 | // Create CommandBuffer where we add ClearCmd for FB Color attachment prior |
| 9123 | // to issuing a Draw |
| 9124 | VkResult err; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9125 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9126 | m_errorMonitor->SetDesiredFailureMsg( |
Tony Barbour | 7e56d30 | 2016-03-02 15:12:01 -0700 | [diff] [blame] | 9127 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9128 | "vkCmdClearAttachments() issued on CB object "); |
| 9129 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9130 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9131 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9132 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9133 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9134 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9135 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9136 | |
| 9137 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9138 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9139 | ds_pool_ci.pNext = NULL; |
| 9140 | ds_pool_ci.maxSets = 1; |
| 9141 | ds_pool_ci.poolSizeCount = 1; |
| 9142 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9143 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9144 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9145 | err = |
| 9146 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9147 | ASSERT_VK_SUCCESS(err); |
| 9148 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9149 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9150 | dsl_binding.binding = 0; |
| 9151 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9152 | dsl_binding.descriptorCount = 1; |
| 9153 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9154 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9155 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9156 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9157 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9158 | ds_layout_ci.pNext = NULL; |
| 9159 | ds_layout_ci.bindingCount = 1; |
| 9160 | ds_layout_ci.pBindings = &dsl_binding; |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9161 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9162 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9163 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9164 | &ds_layout); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9165 | ASSERT_VK_SUCCESS(err); |
| 9166 | |
| 9167 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9168 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9169 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9170 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9171 | alloc_info.descriptorPool = ds_pool; |
| 9172 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9173 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9174 | &descriptorSet); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9175 | ASSERT_VK_SUCCESS(err); |
| 9176 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9177 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9178 | pipe_ms_state_ci.sType = |
| 9179 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9180 | pipe_ms_state_ci.pNext = NULL; |
| 9181 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT; |
| 9182 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9183 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9184 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9185 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9186 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9187 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9188 | pipeline_layout_ci.pNext = NULL; |
| 9189 | pipeline_layout_ci.setLayoutCount = 1; |
| 9190 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9191 | |
| 9192 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9193 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9194 | &pipeline_layout); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9195 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9196 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9197 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9198 | VK_SHADER_STAGE_VERTEX_BIT, this); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9199 | // 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] | 9200 | // on more devices |
| 9201 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9202 | VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9203 | |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9204 | VkPipelineObj pipe(m_device); |
| 9205 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 9206 | pipe.AddShader(&fs); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9207 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 9208 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 9209 | |
| 9210 | BeginCommandBuffer(); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9211 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9212 | // Main thing we care about for this test is that the VkImage obj we're |
| 9213 | // clearing matches Color Attachment of FB |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9214 | // Also pass down other dummy params to keep driver and paramchecker happy |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 9215 | VkClearAttachment color_attachment; |
| 9216 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9217 | color_attachment.clearValue.color.float32[0] = 1.0; |
| 9218 | color_attachment.clearValue.color.float32[1] = 1.0; |
| 9219 | color_attachment.clearValue.color.float32[2] = 1.0; |
| 9220 | color_attachment.clearValue.color.float32[3] = 1.0; |
| 9221 | color_attachment.colorAttachment = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9222 | VkClearRect clear_rect = { |
| 9223 | {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}}; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9224 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9225 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 9226 | &color_attachment, 1, &clear_rect); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9227 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9228 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9229 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9230 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9231 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9232 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9233 | } |
| 9234 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9235 | TEST_F(VkLayerTest, VtxBufferBadIndex) { |
| 9236 | VkResult err; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9237 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9238 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 9239 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | dfcd9b6 | 2015-12-14 15:14:10 -0700 | [diff] [blame] | 9240 | "but no vertex buffers are attached to this Pipeline State Object"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9241 | |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9242 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 9243 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9244 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9245 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9246 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9247 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9248 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9249 | |
| 9250 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9251 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9252 | ds_pool_ci.pNext = NULL; |
| 9253 | ds_pool_ci.maxSets = 1; |
| 9254 | ds_pool_ci.poolSizeCount = 1; |
| 9255 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9256 | |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 9257 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9258 | err = |
| 9259 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9260 | ASSERT_VK_SUCCESS(err); |
| 9261 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9262 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9263 | dsl_binding.binding = 0; |
| 9264 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9265 | dsl_binding.descriptorCount = 1; |
| 9266 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9267 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9268 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9269 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9270 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9271 | ds_layout_ci.pNext = NULL; |
| 9272 | ds_layout_ci.bindingCount = 1; |
| 9273 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9274 | |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9275 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9276 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9277 | &ds_layout); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9278 | ASSERT_VK_SUCCESS(err); |
| 9279 | |
| 9280 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9281 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9282 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9283 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9284 | alloc_info.descriptorPool = ds_pool; |
| 9285 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9286 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9287 | &descriptorSet); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9288 | ASSERT_VK_SUCCESS(err); |
| 9289 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9290 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9291 | pipe_ms_state_ci.sType = |
| 9292 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9293 | pipe_ms_state_ci.pNext = NULL; |
| 9294 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; |
| 9295 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9296 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9297 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9298 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9299 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9300 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9301 | pipeline_layout_ci.pNext = NULL; |
| 9302 | pipeline_layout_ci.setLayoutCount = 1; |
| 9303 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 9304 | VkPipelineLayout pipeline_layout; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9305 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9306 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9307 | &pipeline_layout); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9308 | ASSERT_VK_SUCCESS(err); |
| 9309 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9310 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9311 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9312 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9313 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9314 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9315 | // but add it to be able to run on more devices |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9316 | VkPipelineObj pipe(m_device); |
| 9317 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 9318 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9319 | pipe.AddColorAttachment(); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9320 | pipe.SetMSAA(&pipe_ms_state_ci); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 9321 | pipe.SetViewport(m_viewports); |
| 9322 | pipe.SetScissor(m_scissors); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9323 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 9324 | |
| 9325 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9326 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9327 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | f7bf450 | 2015-09-09 15:12:35 -0600 | [diff] [blame] | 9328 | // Don't care about actual data, just need to get to draw to flag error |
| 9329 | static const float vbo_data[3] = {1.f, 0.f, 1.f}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9330 | VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), |
| 9331 | (const void *)&vbo_data); |
Tobin Ehlis | f7bf450 | 2015-09-09 15:12:35 -0600 | [diff] [blame] | 9332 | 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] | 9333 | Draw(1, 0, 0, 0); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9334 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9335 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9336 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9337 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9338 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9339 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9340 | } |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 9341 | // INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here) |
| 9342 | TEST_F(VkLayerTest, InvalidImageLayout) { |
| 9343 | TEST_DESCRIPTION("Hit all possible validation checks associated with the " |
| 9344 | "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having" |
| 9345 | "images in the wrong layout when they're copied or transitioned."); |
| 9346 | // 3 in ValidateCmdBufImageLayouts |
| 9347 | // * -1 Attempt to submit cmd buf w/ deleted image |
| 9348 | // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource |
| 9349 | // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource |
| 9350 | m_errorMonitor->SetDesiredFailureMsg( |
| 9351 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9352 | "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL."); |
| 9353 | |
| 9354 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9355 | // Create src & dst images to use for copy operations |
| 9356 | VkImage src_image; |
| 9357 | VkImage dst_image; |
| 9358 | |
| 9359 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 9360 | const int32_t tex_width = 32; |
| 9361 | const int32_t tex_height = 32; |
| 9362 | |
| 9363 | VkImageCreateInfo image_create_info = {}; |
| 9364 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 9365 | image_create_info.pNext = NULL; |
| 9366 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 9367 | image_create_info.format = tex_format; |
| 9368 | image_create_info.extent.width = tex_width; |
| 9369 | image_create_info.extent.height = tex_height; |
| 9370 | image_create_info.extent.depth = 1; |
| 9371 | image_create_info.mipLevels = 1; |
| 9372 | image_create_info.arrayLayers = 4; |
| 9373 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 9374 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 9375 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 9376 | image_create_info.flags = 0; |
| 9377 | |
| 9378 | VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image); |
| 9379 | ASSERT_VK_SUCCESS(err); |
| 9380 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image); |
| 9381 | ASSERT_VK_SUCCESS(err); |
| 9382 | |
| 9383 | BeginCommandBuffer(); |
| 9384 | VkImageCopy copyRegion; |
| 9385 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9386 | copyRegion.srcSubresource.mipLevel = 0; |
| 9387 | copyRegion.srcSubresource.baseArrayLayer = 0; |
| 9388 | copyRegion.srcSubresource.layerCount = 1; |
| 9389 | copyRegion.srcOffset.x = 0; |
| 9390 | copyRegion.srcOffset.y = 0; |
| 9391 | copyRegion.srcOffset.z = 0; |
| 9392 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9393 | copyRegion.dstSubresource.mipLevel = 0; |
| 9394 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 9395 | copyRegion.dstSubresource.layerCount = 1; |
| 9396 | copyRegion.dstOffset.x = 0; |
| 9397 | copyRegion.dstOffset.y = 0; |
| 9398 | copyRegion.dstOffset.z = 0; |
| 9399 | copyRegion.extent.width = 1; |
| 9400 | copyRegion.extent.height = 1; |
| 9401 | copyRegion.extent.depth = 1; |
| 9402 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9403 | m_errorMonitor->VerifyFound(); |
| 9404 | // Now cause error due to src image layout changing |
| 9405 | m_errorMonitor->SetDesiredFailureMsg( |
| 9406 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9407 | "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL."); |
| 9408 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9409 | m_errorMonitor->VerifyFound(); |
| 9410 | // Final src error is due to bad layout type |
| 9411 | m_errorMonitor->SetDesiredFailureMsg( |
| 9412 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9413 | "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL."); |
| 9414 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9415 | m_errorMonitor->VerifyFound(); |
| 9416 | // Now verify same checks for dst |
| 9417 | m_errorMonitor->SetDesiredFailureMsg( |
| 9418 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9419 | "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL."); |
| 9420 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9421 | m_errorMonitor->VerifyFound(); |
| 9422 | // Now cause error due to src image layout changing |
| 9423 | m_errorMonitor->SetDesiredFailureMsg( |
| 9424 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9425 | "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL."); |
| 9426 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, ©Region); |
| 9427 | m_errorMonitor->VerifyFound(); |
| 9428 | m_errorMonitor->SetDesiredFailureMsg( |
| 9429 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9430 | "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL."); |
| 9431 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, ©Region); |
| 9432 | m_errorMonitor->VerifyFound(); |
| 9433 | // Now cause error due to bad image layout transition in PipelineBarrier |
| 9434 | VkImageMemoryBarrier image_barrier[1] = {}; |
| 9435 | image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 9436 | image_barrier[0].image = src_image; |
| 9437 | image_barrier[0].subresourceRange.layerCount = 2; |
| 9438 | image_barrier[0].subresourceRange.levelCount = 2; |
| 9439 | image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9440 | m_errorMonitor->SetDesiredFailureMsg( |
| 9441 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9442 | "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL."); |
| 9443 | vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier); |
| 9444 | m_errorMonitor->VerifyFound(); |
| 9445 | |
| 9446 | // Finally some layout errors at RenderPass create time |
| 9447 | // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing. |
| 9448 | VkAttachmentReference attach = {}; |
| 9449 | // perf warning for GENERAL layout w/ non-DS input attachment |
| 9450 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 9451 | VkSubpassDescription subpass = {}; |
| 9452 | subpass.inputAttachmentCount = 1; |
| 9453 | subpass.pInputAttachments = &attach; |
| 9454 | VkRenderPassCreateInfo rpci = {}; |
| 9455 | rpci.subpassCount = 1; |
| 9456 | rpci.pSubpasses = &subpass; |
| 9457 | rpci.attachmentCount = 1; |
| 9458 | VkAttachmentDescription attach_desc = {}; |
| 9459 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 9460 | rpci.pAttachments = &attach_desc; |
Tobin Ehlis | 1efce02 | 2016-05-11 10:40:34 -0600 | [diff] [blame] | 9461 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 9462 | VkRenderPass rp; |
| 9463 | m_errorMonitor->SetDesiredFailureMsg( |
| 9464 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9465 | "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL."); |
| 9466 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9467 | m_errorMonitor->VerifyFound(); |
| 9468 | // error w/ non-general layout |
| 9469 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 9470 | |
| 9471 | m_errorMonitor->SetDesiredFailureMsg( |
| 9472 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9473 | "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL."); |
| 9474 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9475 | m_errorMonitor->VerifyFound(); |
| 9476 | subpass.inputAttachmentCount = 0; |
| 9477 | subpass.colorAttachmentCount = 1; |
| 9478 | subpass.pColorAttachments = &attach; |
| 9479 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 9480 | // perf warning for GENERAL layout on color attachment |
| 9481 | m_errorMonitor->SetDesiredFailureMsg( |
| 9482 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9483 | "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL."); |
| 9484 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9485 | m_errorMonitor->VerifyFound(); |
| 9486 | // error w/ non-color opt or GENERAL layout for color attachment |
| 9487 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 9488 | m_errorMonitor->SetDesiredFailureMsg( |
| 9489 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9490 | "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL."); |
| 9491 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9492 | m_errorMonitor->VerifyFound(); |
| 9493 | subpass.colorAttachmentCount = 0; |
| 9494 | subpass.pDepthStencilAttachment = &attach; |
| 9495 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 9496 | // perf warning for GENERAL layout on DS attachment |
| 9497 | m_errorMonitor->SetDesiredFailureMsg( |
| 9498 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9499 | "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL."); |
| 9500 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9501 | m_errorMonitor->VerifyFound(); |
| 9502 | // error w/ non-ds opt or GENERAL layout for color attachment |
| 9503 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 9504 | m_errorMonitor->SetDesiredFailureMsg( |
| 9505 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9506 | "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL."); |
| 9507 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9508 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 1efce02 | 2016-05-11 10:40:34 -0600 | [diff] [blame] | 9509 | // For this error we need a valid renderpass so create default one |
| 9510 | attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 9511 | attach.attachment = 0; |
| 9512 | attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 9513 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
| 9514 | attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE; |
| 9515 | attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 9516 | attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 9517 | // Can't do a CLEAR load on READ_ONLY initialLayout |
| 9518 | attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 9519 | attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 9520 | attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 9521 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9522 | " with invalid first layout " |
| 9523 | "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_" |
| 9524 | "ONLY_OPTIMAL"); |
| 9525 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9526 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 9527 | |
| 9528 | vkDestroyImage(m_device->device(), src_image, NULL); |
| 9529 | vkDestroyImage(m_device->device(), dst_image, NULL); |
| 9530 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9531 | #endif // DRAW_STATE_TESTS |
| 9532 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 9533 | #if THREADING_TESTS |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9534 | #if GTEST_IS_THREADSAFE |
| 9535 | struct thread_data_struct { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9536 | VkCommandBuffer commandBuffer; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9537 | VkEvent event; |
| 9538 | bool bailout; |
| 9539 | }; |
| 9540 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9541 | extern "C" void *AddToCommandBuffer(void *arg) { |
| 9542 | struct thread_data_struct *data = (struct thread_data_struct *)arg; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9543 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9544 | for (int i = 0; i < 10000; i++) { |
| 9545 | vkCmdSetEvent(data->commandBuffer, data->event, |
| 9546 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9547 | if (data->bailout) { |
| 9548 | break; |
| 9549 | } |
| 9550 | } |
| 9551 | return NULL; |
| 9552 | } |
| 9553 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9554 | TEST_F(VkLayerTest, ThreadCommandBufferCollision) { |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 9555 | test_platform_thread thread; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9556 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9557 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9558 | "THREADING ERROR"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9559 | |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9560 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9561 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 9562 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9563 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9564 | // Calls AllocateCommandBuffers |
| 9565 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
Mark Lobodzinski | 5495d13 | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 9566 | |
| 9567 | // Avoid creating RenderPass |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9568 | commandBuffer.BeginCommandBuffer(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9569 | |
| 9570 | VkEventCreateInfo event_info; |
| 9571 | VkEvent event; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9572 | VkResult err; |
| 9573 | |
| 9574 | memset(&event_info, 0, sizeof(event_info)); |
| 9575 | event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 9576 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9577 | err = vkCreateEvent(device(), &event_info, NULL, &event); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9578 | ASSERT_VK_SUCCESS(err); |
| 9579 | |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9580 | err = vkResetEvent(device(), event); |
| 9581 | ASSERT_VK_SUCCESS(err); |
| 9582 | |
| 9583 | struct thread_data_struct data; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9584 | data.commandBuffer = commandBuffer.GetBufferHandle(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9585 | data.event = event; |
| 9586 | data.bailout = false; |
| 9587 | m_errorMonitor->SetBailout(&data.bailout); |
| 9588 | // Add many entries to command buffer from another thread. |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 9589 | test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9590 | // Add many entries to command buffer from this thread at the same time. |
| 9591 | AddToCommandBuffer(&data); |
Mark Lobodzinski | 5495d13 | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 9592 | |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 9593 | test_platform_thread_join(thread, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9594 | commandBuffer.EndCommandBuffer(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9595 | |
Mike Stroyan | 10b8cb7 | 2016-01-22 15:22:03 -0700 | [diff] [blame] | 9596 | m_errorMonitor->SetBailout(NULL); |
| 9597 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9598 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9599 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9600 | vkDestroyEvent(device(), event, NULL); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9601 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9602 | #endif // GTEST_IS_THREADSAFE |
| 9603 | #endif // THREADING_TESTS |
| 9604 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9605 | #if SHADER_CHECKER_TESTS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9606 | TEST_F(VkLayerTest, InvalidSPIRVCodeSize) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9607 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9608 | "Invalid SPIR-V header"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9609 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9610 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9611 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9612 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9613 | VkShaderModule module; |
| 9614 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 9615 | struct icd_spv_header spv; |
| 9616 | |
| 9617 | spv.magic = ICD_SPV_MAGIC; |
| 9618 | spv.version = ICD_SPV_VERSION; |
| 9619 | spv.gen_magic = 0; |
| 9620 | |
| 9621 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 9622 | moduleCreateInfo.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9623 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9624 | moduleCreateInfo.codeSize = 4; |
| 9625 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9626 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9627 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9628 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9629 | } |
| 9630 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9631 | TEST_F(VkLayerTest, InvalidSPIRVMagic) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9632 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9633 | "Invalid SPIR-V magic number"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9634 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9635 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9636 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9637 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9638 | VkShaderModule module; |
| 9639 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 9640 | struct icd_spv_header spv; |
| 9641 | |
| 9642 | spv.magic = ~ICD_SPV_MAGIC; |
| 9643 | spv.version = ICD_SPV_VERSION; |
| 9644 | spv.gen_magic = 0; |
| 9645 | |
| 9646 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 9647 | moduleCreateInfo.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9648 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9649 | moduleCreateInfo.codeSize = sizeof(spv) + 10; |
| 9650 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9651 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9652 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9653 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9654 | } |
| 9655 | |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9656 | #if 0 |
| 9657 | // Not currently covered by SPIRV-Tools validator |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9658 | TEST_F(VkLayerTest, InvalidSPIRVVersion) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9659 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9660 | "Invalid SPIR-V header"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9661 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9662 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9663 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9664 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9665 | VkShaderModule module; |
| 9666 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 9667 | struct icd_spv_header spv; |
| 9668 | |
| 9669 | spv.magic = ICD_SPV_MAGIC; |
| 9670 | spv.version = ~ICD_SPV_VERSION; |
| 9671 | spv.gen_magic = 0; |
| 9672 | |
| 9673 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 9674 | moduleCreateInfo.pNext = NULL; |
| 9675 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9676 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9677 | moduleCreateInfo.codeSize = sizeof(spv) + 10; |
| 9678 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9679 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9680 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9681 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9682 | } |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9683 | #endif |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9684 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9685 | TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 9686 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9687 | "not consumed by fragment shader"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9688 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9689 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 9690 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9691 | |
| 9692 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9693 | "#version 450\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9694 | "\n" |
| 9695 | "layout(location=0) out float x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 9696 | "out gl_PerVertex {\n" |
| 9697 | " vec4 gl_Position;\n" |
| 9698 | "};\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9699 | "void main(){\n" |
| 9700 | " gl_Position = vec4(1);\n" |
| 9701 | " x = 0;\n" |
| 9702 | "}\n"; |
| 9703 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9704 | "#version 450\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9705 | "\n" |
| 9706 | "layout(location=0) out vec4 color;\n" |
| 9707 | "void main(){\n" |
| 9708 | " color = vec4(1);\n" |
| 9709 | "}\n"; |
| 9710 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 9711 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9712 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9713 | |
| 9714 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 9715 | pipe.AddColorAttachment(); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9716 | pipe.AddShader(&vs); |
| 9717 | pipe.AddShader(&fs); |
| 9718 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9719 | VkDescriptorSetObj descriptorSet(m_device); |
| 9720 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9721 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9722 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 9723 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9724 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9725 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9726 | } |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9727 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9728 | TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9729 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9730 | "not written by vertex shader"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9731 | |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9732 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 9733 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9734 | |
| 9735 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9736 | "#version 450\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9737 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 9738 | "out gl_PerVertex {\n" |
| 9739 | " vec4 gl_Position;\n" |
| 9740 | "};\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9741 | "void main(){\n" |
| 9742 | " gl_Position = vec4(1);\n" |
| 9743 | "}\n"; |
| 9744 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9745 | "#version 450\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9746 | "\n" |
| 9747 | "layout(location=0) in float x;\n" |
| 9748 | "layout(location=0) out vec4 color;\n" |
| 9749 | "void main(){\n" |
| 9750 | " color = vec4(x);\n" |
| 9751 | "}\n"; |
| 9752 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 9753 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9754 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9755 | |
| 9756 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 9757 | pipe.AddColorAttachment(); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9758 | pipe.AddShader(&vs); |
| 9759 | pipe.AddShader(&fs); |
| 9760 | |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9761 | VkDescriptorSetObj descriptorSet(m_device); |
| 9762 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9763 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9764 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 9765 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9766 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9767 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9768 | } |
| 9769 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9770 | TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) { |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9771 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9772 | "not written by vertex shader"); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9773 | |
| 9774 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9775 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9776 | |
| 9777 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9778 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9779 | "\n" |
| 9780 | "out gl_PerVertex {\n" |
| 9781 | " vec4 gl_Position;\n" |
| 9782 | "};\n" |
| 9783 | "void main(){\n" |
| 9784 | " gl_Position = vec4(1);\n" |
| 9785 | "}\n"; |
| 9786 | char const *fsSource = |
| 9787 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9788 | "\n" |
| 9789 | "in block { layout(location=0) float x; } ins;\n" |
| 9790 | "layout(location=0) out vec4 color;\n" |
| 9791 | "void main(){\n" |
| 9792 | " color = vec4(ins.x);\n" |
| 9793 | "}\n"; |
| 9794 | |
| 9795 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9796 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 9797 | |
| 9798 | VkPipelineObj pipe(m_device); |
| 9799 | pipe.AddColorAttachment(); |
| 9800 | pipe.AddShader(&vs); |
| 9801 | pipe.AddShader(&fs); |
| 9802 | |
| 9803 | VkDescriptorSetObj descriptorSet(m_device); |
| 9804 | descriptorSet.AppendDummy(); |
| 9805 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 9806 | |
| 9807 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 9808 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9809 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9810 | } |
| 9811 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9812 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) { |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 9813 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 9814 | "Type mismatch on location 0.0: 'ptr to " |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9815 | "output arr[2] of float32' vs 'ptr to " |
| 9816 | "input arr[3] of float32'"); |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 9817 | |
| 9818 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9819 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9820 | |
| 9821 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9822 | "#version 450\n" |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 9823 | "\n" |
| 9824 | "layout(location=0) out float x[2];\n" |
| 9825 | "out gl_PerVertex {\n" |
| 9826 | " vec4 gl_Position;\n" |
| 9827 | "};\n" |
| 9828 | "void main(){\n" |
| 9829 | " x[0] = 0; x[1] = 0;\n" |
| 9830 | " gl_Position = vec4(1);\n" |
| 9831 | "}\n"; |
| 9832 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9833 | "#version 450\n" |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 9834 | "\n" |
| 9835 | "layout(location=0) in float x[3];\n" |
| 9836 | "layout(location=0) out vec4 color;\n" |
| 9837 | "void main(){\n" |
| 9838 | " color = vec4(x[0] + x[1] + x[2]);\n" |
| 9839 | "}\n"; |
| 9840 | |
| 9841 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9842 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 9843 | |
| 9844 | VkPipelineObj pipe(m_device); |
| 9845 | pipe.AddColorAttachment(); |
| 9846 | pipe.AddShader(&vs); |
| 9847 | pipe.AddShader(&fs); |
| 9848 | |
| 9849 | VkDescriptorSetObj descriptorSet(m_device); |
| 9850 | descriptorSet.AppendDummy(); |
| 9851 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 9852 | |
| 9853 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 9854 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9855 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 9856 | } |
| 9857 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9858 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9859 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9860 | "Type mismatch on location 0"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9861 | |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9862 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 9863 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9864 | |
| 9865 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9866 | "#version 450\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9867 | "\n" |
| 9868 | "layout(location=0) out int x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 9869 | "out gl_PerVertex {\n" |
| 9870 | " vec4 gl_Position;\n" |
| 9871 | "};\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9872 | "void main(){\n" |
| 9873 | " x = 0;\n" |
| 9874 | " gl_Position = vec4(1);\n" |
| 9875 | "}\n"; |
| 9876 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9877 | "#version 450\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9878 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9879 | "layout(location=0) in float x;\n" /* VS writes int */ |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9880 | "layout(location=0) out vec4 color;\n" |
| 9881 | "void main(){\n" |
| 9882 | " color = vec4(x);\n" |
| 9883 | "}\n"; |
| 9884 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 9885 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9886 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9887 | |
| 9888 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 9889 | pipe.AddColorAttachment(); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9890 | pipe.AddShader(&vs); |
| 9891 | pipe.AddShader(&fs); |
| 9892 | |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9893 | VkDescriptorSetObj descriptorSet(m_device); |
| 9894 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9895 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9896 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 9897 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9898 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9899 | m_errorMonitor->VerifyFound(); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9900 | } |
| 9901 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9902 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) { |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9903 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9904 | "Type mismatch on location 0"); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9905 | |
| 9906 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9907 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9908 | |
| 9909 | char const *vsSource = |
| 9910 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9911 | "\n" |
| 9912 | "out block { layout(location=0) int x; } outs;\n" |
| 9913 | "out gl_PerVertex {\n" |
| 9914 | " vec4 gl_Position;\n" |
| 9915 | "};\n" |
| 9916 | "void main(){\n" |
| 9917 | " outs.x = 0;\n" |
| 9918 | " gl_Position = vec4(1);\n" |
| 9919 | "}\n"; |
| 9920 | char const *fsSource = |
| 9921 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9922 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9923 | "in block { layout(location=0) float x; } ins;\n" /* VS writes int */ |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9924 | "layout(location=0) out vec4 color;\n" |
| 9925 | "void main(){\n" |
| 9926 | " color = vec4(ins.x);\n" |
| 9927 | "}\n"; |
| 9928 | |
| 9929 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9930 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 9931 | |
| 9932 | VkPipelineObj pipe(m_device); |
| 9933 | pipe.AddColorAttachment(); |
| 9934 | pipe.AddShader(&vs); |
| 9935 | pipe.AddShader(&fs); |
| 9936 | |
| 9937 | VkDescriptorSetObj descriptorSet(m_device); |
| 9938 | descriptorSet.AppendDummy(); |
| 9939 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 9940 | |
| 9941 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 9942 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9943 | m_errorMonitor->VerifyFound(); |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 9944 | } |
| 9945 | |
| 9946 | TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) { |
| 9947 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9948 | "location 0.0 which is not written by vertex shader"); |
| 9949 | |
| 9950 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9951 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9952 | |
| 9953 | char const *vsSource = |
| 9954 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 9955 | "\n" |
| 9956 | "out block { layout(location=1) float x; } outs;\n" |
| 9957 | "out gl_PerVertex {\n" |
| 9958 | " vec4 gl_Position;\n" |
| 9959 | "};\n" |
| 9960 | "void main(){\n" |
| 9961 | " outs.x = 0;\n" |
| 9962 | " gl_Position = vec4(1);\n" |
| 9963 | "}\n"; |
| 9964 | char const *fsSource = |
| 9965 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 9966 | "\n" |
| 9967 | "in block { layout(location=0) float x; } ins;\n" |
| 9968 | "layout(location=0) out vec4 color;\n" |
| 9969 | "void main(){\n" |
| 9970 | " color = vec4(ins.x);\n" |
| 9971 | "}\n"; |
| 9972 | |
| 9973 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9974 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 9975 | |
| 9976 | VkPipelineObj pipe(m_device); |
| 9977 | pipe.AddColorAttachment(); |
| 9978 | pipe.AddShader(&vs); |
| 9979 | pipe.AddShader(&fs); |
| 9980 | |
| 9981 | VkDescriptorSetObj descriptorSet(m_device); |
| 9982 | descriptorSet.AppendDummy(); |
| 9983 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 9984 | |
| 9985 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 9986 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9987 | m_errorMonitor->VerifyFound(); |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 9988 | } |
| 9989 | |
| 9990 | TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) { |
| 9991 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9992 | "location 0.1 which is not written by vertex shader"); |
| 9993 | |
| 9994 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9995 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9996 | |
| 9997 | char const *vsSource = |
| 9998 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 9999 | "\n" |
| 10000 | "out block { layout(location=0, component=0) float x; } outs;\n" |
| 10001 | "out gl_PerVertex {\n" |
| 10002 | " vec4 gl_Position;\n" |
| 10003 | "};\n" |
| 10004 | "void main(){\n" |
| 10005 | " outs.x = 0;\n" |
| 10006 | " gl_Position = vec4(1);\n" |
| 10007 | "}\n"; |
| 10008 | char const *fsSource = |
| 10009 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 10010 | "\n" |
| 10011 | "in block { layout(location=0, component=1) float x; } ins;\n" |
| 10012 | "layout(location=0) out vec4 color;\n" |
| 10013 | "void main(){\n" |
| 10014 | " color = vec4(ins.x);\n" |
| 10015 | "}\n"; |
| 10016 | |
| 10017 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10018 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10019 | |
| 10020 | VkPipelineObj pipe(m_device); |
| 10021 | pipe.AddColorAttachment(); |
| 10022 | pipe.AddShader(&vs); |
| 10023 | pipe.AddShader(&fs); |
| 10024 | |
| 10025 | VkDescriptorSetObj descriptorSet(m_device); |
| 10026 | descriptorSet.AppendDummy(); |
| 10027 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10028 | |
| 10029 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10030 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10031 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 10032 | } |
| 10033 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10034 | TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 10035 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10036 | "location 0 not consumed by VS"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10037 | |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10038 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10039 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10040 | |
| 10041 | VkVertexInputBindingDescription input_binding; |
| 10042 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10043 | |
| 10044 | VkVertexInputAttributeDescription input_attrib; |
| 10045 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10046 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10047 | |
| 10048 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10049 | "#version 450\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10050 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10051 | "out gl_PerVertex {\n" |
| 10052 | " vec4 gl_Position;\n" |
| 10053 | "};\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10054 | "void main(){\n" |
| 10055 | " gl_Position = vec4(1);\n" |
| 10056 | "}\n"; |
| 10057 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10058 | "#version 450\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10059 | "\n" |
| 10060 | "layout(location=0) out vec4 color;\n" |
| 10061 | "void main(){\n" |
| 10062 | " color = vec4(1);\n" |
| 10063 | "}\n"; |
| 10064 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10065 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10066 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10067 | |
| 10068 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10069 | pipe.AddColorAttachment(); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10070 | pipe.AddShader(&vs); |
| 10071 | pipe.AddShader(&fs); |
| 10072 | |
| 10073 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10074 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10075 | |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10076 | VkDescriptorSetObj descriptorSet(m_device); |
| 10077 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10078 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10079 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10080 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10081 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10082 | m_errorMonitor->VerifyFound(); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10083 | } |
| 10084 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10085 | TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 10086 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10087 | "location 0 not consumed by VS"); |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10088 | |
| 10089 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10090 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10091 | |
| 10092 | VkVertexInputBindingDescription input_binding; |
| 10093 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10094 | |
| 10095 | VkVertexInputAttributeDescription input_attrib; |
| 10096 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10097 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10098 | |
| 10099 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10100 | "#version 450\n" |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10101 | "\n" |
| 10102 | "layout(location=1) in float x;\n" |
| 10103 | "out gl_PerVertex {\n" |
| 10104 | " vec4 gl_Position;\n" |
| 10105 | "};\n" |
| 10106 | "void main(){\n" |
| 10107 | " gl_Position = vec4(x);\n" |
| 10108 | "}\n"; |
| 10109 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10110 | "#version 450\n" |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10111 | "\n" |
| 10112 | "layout(location=0) out vec4 color;\n" |
| 10113 | "void main(){\n" |
| 10114 | " color = vec4(1);\n" |
| 10115 | "}\n"; |
| 10116 | |
| 10117 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10118 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10119 | |
| 10120 | VkPipelineObj pipe(m_device); |
| 10121 | pipe.AddColorAttachment(); |
| 10122 | pipe.AddShader(&vs); |
| 10123 | pipe.AddShader(&fs); |
| 10124 | |
| 10125 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10126 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10127 | |
| 10128 | VkDescriptorSetObj descriptorSet(m_device); |
| 10129 | descriptorSet.AppendDummy(); |
| 10130 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10131 | |
| 10132 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10133 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10134 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10135 | } |
| 10136 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10137 | TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) { |
| 10138 | m_errorMonitor->SetDesiredFailureMsg( |
| 10139 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10140 | "VS consumes input at location 0 but not provided"); |
| 10141 | |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10142 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10143 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10144 | |
| 10145 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10146 | "#version 450\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10147 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10148 | "layout(location=0) in vec4 x;\n" /* not provided */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10149 | "out gl_PerVertex {\n" |
| 10150 | " vec4 gl_Position;\n" |
| 10151 | "};\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10152 | "void main(){\n" |
| 10153 | " gl_Position = x;\n" |
| 10154 | "}\n"; |
| 10155 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10156 | "#version 450\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10157 | "\n" |
| 10158 | "layout(location=0) out vec4 color;\n" |
| 10159 | "void main(){\n" |
| 10160 | " color = vec4(1);\n" |
| 10161 | "}\n"; |
| 10162 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10163 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10164 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10165 | |
| 10166 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10167 | pipe.AddColorAttachment(); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10168 | pipe.AddShader(&vs); |
| 10169 | pipe.AddShader(&fs); |
| 10170 | |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10171 | VkDescriptorSetObj descriptorSet(m_device); |
| 10172 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10173 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10174 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10175 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10176 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10177 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10178 | } |
| 10179 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10180 | TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) { |
| 10181 | m_errorMonitor->SetDesiredFailureMsg( |
| 10182 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10183 | "location 0 does not match VS input type"); |
| 10184 | |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10185 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10186 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10187 | |
| 10188 | VkVertexInputBindingDescription input_binding; |
| 10189 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10190 | |
| 10191 | VkVertexInputAttributeDescription input_attrib; |
| 10192 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10193 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10194 | |
| 10195 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10196 | "#version 450\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10197 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10198 | "layout(location=0) in int x;\n" /* attrib provided float */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10199 | "out gl_PerVertex {\n" |
| 10200 | " vec4 gl_Position;\n" |
| 10201 | "};\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10202 | "void main(){\n" |
| 10203 | " gl_Position = vec4(x);\n" |
| 10204 | "}\n"; |
| 10205 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10206 | "#version 450\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10207 | "\n" |
| 10208 | "layout(location=0) out vec4 color;\n" |
| 10209 | "void main(){\n" |
| 10210 | " color = vec4(1);\n" |
| 10211 | "}\n"; |
| 10212 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10213 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10214 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10215 | |
| 10216 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10217 | pipe.AddColorAttachment(); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10218 | pipe.AddShader(&vs); |
| 10219 | pipe.AddShader(&fs); |
| 10220 | |
| 10221 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10222 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10223 | |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10224 | VkDescriptorSetObj descriptorSet(m_device); |
| 10225 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10226 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10227 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10228 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10229 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10230 | m_errorMonitor->VerifyFound(); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10231 | } |
| 10232 | |
Chris Forbes | c68b43c | 2016-04-06 11:18:47 +1200 | [diff] [blame] | 10233 | TEST_F(VkLayerTest, CreatePipelineDuplicateStage) { |
| 10234 | m_errorMonitor->SetDesiredFailureMsg( |
| 10235 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10236 | "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT"); |
| 10237 | |
| 10238 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10239 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10240 | |
| 10241 | char const *vsSource = |
| 10242 | "#version 450\n" |
| 10243 | "\n" |
| 10244 | "out gl_PerVertex {\n" |
| 10245 | " vec4 gl_Position;\n" |
| 10246 | "};\n" |
| 10247 | "void main(){\n" |
| 10248 | " gl_Position = vec4(1);\n" |
| 10249 | "}\n"; |
| 10250 | char const *fsSource = |
| 10251 | "#version 450\n" |
| 10252 | "\n" |
| 10253 | "layout(location=0) out vec4 color;\n" |
| 10254 | "void main(){\n" |
| 10255 | " color = vec4(1);\n" |
| 10256 | "}\n"; |
| 10257 | |
| 10258 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10259 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10260 | |
| 10261 | VkPipelineObj pipe(m_device); |
| 10262 | pipe.AddColorAttachment(); |
| 10263 | pipe.AddShader(&vs); |
| 10264 | pipe.AddShader(&vs); |
| 10265 | pipe.AddShader(&fs); |
| 10266 | |
| 10267 | VkDescriptorSetObj descriptorSet(m_device); |
| 10268 | descriptorSet.AppendDummy(); |
| 10269 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10270 | |
| 10271 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10272 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10273 | m_errorMonitor->VerifyFound(); |
Chris Forbes | c68b43c | 2016-04-06 11:18:47 +1200 | [diff] [blame] | 10274 | } |
| 10275 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10276 | TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10277 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10278 | |
| 10279 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10280 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10281 | |
| 10282 | VkVertexInputBindingDescription input_binding; |
| 10283 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10284 | |
| 10285 | VkVertexInputAttributeDescription input_attribs[2]; |
| 10286 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 10287 | |
| 10288 | for (int i = 0; i < 2; i++) { |
| 10289 | input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 10290 | input_attribs[i].location = i; |
| 10291 | } |
| 10292 | |
| 10293 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10294 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10295 | "\n" |
| 10296 | "layout(location=0) in mat2x4 x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10297 | "out gl_PerVertex {\n" |
| 10298 | " vec4 gl_Position;\n" |
| 10299 | "};\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10300 | "void main(){\n" |
| 10301 | " gl_Position = x[0] + x[1];\n" |
| 10302 | "}\n"; |
| 10303 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10304 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10305 | "\n" |
| 10306 | "layout(location=0) out vec4 color;\n" |
| 10307 | "void main(){\n" |
| 10308 | " color = vec4(1);\n" |
| 10309 | "}\n"; |
| 10310 | |
| 10311 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10312 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10313 | |
| 10314 | VkPipelineObj pipe(m_device); |
| 10315 | pipe.AddColorAttachment(); |
| 10316 | pipe.AddShader(&vs); |
| 10317 | pipe.AddShader(&fs); |
| 10318 | |
| 10319 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10320 | pipe.AddVertexInputAttribs(input_attribs, 2); |
| 10321 | |
| 10322 | VkDescriptorSetObj descriptorSet(m_device); |
| 10323 | descriptorSet.AppendDummy(); |
| 10324 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10325 | |
| 10326 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10327 | |
| 10328 | /* expect success */ |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10329 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10330 | } |
| 10331 | |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10332 | TEST_F(VkLayerTest, CreatePipelineAttribArrayType) |
| 10333 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10334 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10335 | |
| 10336 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10337 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10338 | |
| 10339 | VkVertexInputBindingDescription input_binding; |
| 10340 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10341 | |
| 10342 | VkVertexInputAttributeDescription input_attribs[2]; |
| 10343 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 10344 | |
| 10345 | for (int i = 0; i < 2; i++) { |
| 10346 | input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 10347 | input_attribs[i].location = i; |
| 10348 | } |
| 10349 | |
| 10350 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10351 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10352 | "\n" |
| 10353 | "layout(location=0) in vec4 x[2];\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10354 | "out gl_PerVertex {\n" |
| 10355 | " vec4 gl_Position;\n" |
| 10356 | "};\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10357 | "void main(){\n" |
| 10358 | " gl_Position = x[0] + x[1];\n" |
| 10359 | "}\n"; |
| 10360 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10361 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10362 | "\n" |
| 10363 | "layout(location=0) out vec4 color;\n" |
| 10364 | "void main(){\n" |
| 10365 | " color = vec4(1);\n" |
| 10366 | "}\n"; |
| 10367 | |
| 10368 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10369 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10370 | |
| 10371 | VkPipelineObj pipe(m_device); |
| 10372 | pipe.AddColorAttachment(); |
| 10373 | pipe.AddShader(&vs); |
| 10374 | pipe.AddShader(&fs); |
| 10375 | |
| 10376 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10377 | pipe.AddVertexInputAttribs(input_attribs, 2); |
| 10378 | |
| 10379 | VkDescriptorSetObj descriptorSet(m_device); |
| 10380 | descriptorSet.AppendDummy(); |
| 10381 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10382 | |
| 10383 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10384 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10385 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10386 | } |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10387 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10388 | TEST_F(VkLayerTest, CreatePipelineSimplePositive) |
| 10389 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10390 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10391 | |
| 10392 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10393 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10394 | |
| 10395 | char const *vsSource = |
| 10396 | "#version 450\n" |
| 10397 | "out gl_PerVertex {\n" |
| 10398 | " vec4 gl_Position;\n" |
| 10399 | "};\n" |
| 10400 | "void main(){\n" |
| 10401 | " gl_Position = vec4(0);\n" |
| 10402 | "}\n"; |
| 10403 | char const *fsSource = |
| 10404 | "#version 450\n" |
| 10405 | "\n" |
| 10406 | "layout(location=0) out vec4 color;\n" |
| 10407 | "void main(){\n" |
| 10408 | " color = vec4(1);\n" |
| 10409 | "}\n"; |
| 10410 | |
| 10411 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10412 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10413 | |
| 10414 | VkPipelineObj pipe(m_device); |
| 10415 | pipe.AddColorAttachment(); |
| 10416 | pipe.AddShader(&vs); |
| 10417 | pipe.AddShader(&fs); |
| 10418 | |
| 10419 | VkDescriptorSetObj descriptorSet(m_device); |
| 10420 | descriptorSet.AppendDummy(); |
| 10421 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10422 | |
| 10423 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10424 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10425 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10426 | } |
| 10427 | |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 10428 | TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch) |
| 10429 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10430 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 10431 | |
| 10432 | // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block |
| 10433 | |
| 10434 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10435 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10436 | |
| 10437 | char const *vsSource = |
| 10438 | "#version 450\n" |
| 10439 | "out gl_PerVertex {\n" |
| 10440 | " vec4 gl_Position;\n" |
| 10441 | "};\n" |
| 10442 | "layout(location=0) out vec3 x;\n" |
| 10443 | "layout(location=1) out ivec3 y;\n" |
| 10444 | "layout(location=2) out vec3 z;\n" |
| 10445 | "void main(){\n" |
| 10446 | " gl_Position = vec4(0);\n" |
| 10447 | " x = vec3(0); y = ivec3(0); z = vec3(0);\n" |
| 10448 | "}\n"; |
| 10449 | char const *fsSource = |
| 10450 | "#version 450\n" |
| 10451 | "\n" |
| 10452 | "layout(location=0) out vec4 color;\n" |
| 10453 | "layout(location=0) in float x;\n" |
| 10454 | "layout(location=1) flat in int y;\n" |
| 10455 | "layout(location=2) in vec2 z;\n" |
| 10456 | "void main(){\n" |
| 10457 | " color = vec4(1 + x + y + z.x);\n" |
| 10458 | "}\n"; |
| 10459 | |
| 10460 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10461 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10462 | |
| 10463 | VkPipelineObj pipe(m_device); |
| 10464 | pipe.AddColorAttachment(); |
| 10465 | pipe.AddShader(&vs); |
| 10466 | pipe.AddShader(&fs); |
| 10467 | |
| 10468 | VkDescriptorSetObj descriptorSet(m_device); |
| 10469 | descriptorSet.AppendDummy(); |
| 10470 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10471 | |
| 10472 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10473 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10474 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 10475 | } |
| 10476 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10477 | TEST_F(VkLayerTest, CreatePipelineTessPerVertex) |
| 10478 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10479 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10480 | |
| 10481 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10482 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10483 | |
Chris Forbes | c1e852d | 2016-04-04 19:26:42 +1200 | [diff] [blame] | 10484 | if (!m_device->phy().features().tessellationShader) { |
| 10485 | printf("Device does not support tessellation shaders; skipped.\n"); |
| 10486 | return; |
| 10487 | } |
| 10488 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10489 | char const *vsSource = |
| 10490 | "#version 450\n" |
| 10491 | "void main(){}\n"; |
| 10492 | char const *tcsSource = |
| 10493 | "#version 450\n" |
| 10494 | "layout(location=0) out int x[];\n" |
| 10495 | "layout(vertices=3) out;\n" |
| 10496 | "void main(){\n" |
| 10497 | " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n" |
| 10498 | " gl_TessLevelInner[0] = 1;\n" |
| 10499 | " x[gl_InvocationID] = gl_InvocationID;\n" |
| 10500 | "}\n"; |
| 10501 | char const *tesSource = |
| 10502 | "#version 450\n" |
| 10503 | "layout(triangles, equal_spacing, cw) in;\n" |
| 10504 | "layout(location=0) in int x[];\n" |
| 10505 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 10506 | "void main(){\n" |
| 10507 | " gl_Position.xyz = gl_TessCoord;\n" |
| 10508 | " gl_Position.w = x[0] + x[1] + x[2];\n" |
| 10509 | "}\n"; |
| 10510 | char const *fsSource = |
| 10511 | "#version 450\n" |
| 10512 | "layout(location=0) out vec4 color;\n" |
| 10513 | "void main(){\n" |
| 10514 | " color = vec4(1);\n" |
| 10515 | "}\n"; |
| 10516 | |
| 10517 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10518 | VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this); |
| 10519 | VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this); |
| 10520 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10521 | |
| 10522 | VkPipelineInputAssemblyStateCreateInfo iasci{ |
| 10523 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, |
| 10524 | nullptr, |
| 10525 | 0, |
| 10526 | VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, |
| 10527 | VK_FALSE}; |
| 10528 | |
Chris Forbes | b4cacb6 | 2016-04-04 19:15:00 +1200 | [diff] [blame] | 10529 | VkPipelineTessellationStateCreateInfo tsci{ |
| 10530 | VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, |
| 10531 | nullptr, |
| 10532 | 0, |
| 10533 | 3}; |
| 10534 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10535 | VkPipelineObj pipe(m_device); |
| 10536 | pipe.SetInputAssembly(&iasci); |
Chris Forbes | b4cacb6 | 2016-04-04 19:15:00 +1200 | [diff] [blame] | 10537 | pipe.SetTessellation(&tsci); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10538 | pipe.AddColorAttachment(); |
| 10539 | pipe.AddShader(&vs); |
| 10540 | pipe.AddShader(&tcs); |
| 10541 | pipe.AddShader(&tes); |
| 10542 | pipe.AddShader(&fs); |
| 10543 | |
| 10544 | VkDescriptorSetObj descriptorSet(m_device); |
| 10545 | descriptorSet.AppendDummy(); |
| 10546 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10547 | |
| 10548 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10549 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10550 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10551 | } |
| 10552 | |
Chris Forbes | a0ab815 | 2016-04-20 13:34:27 +1200 | [diff] [blame] | 10553 | TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive) |
| 10554 | { |
| 10555 | m_errorMonitor->ExpectSuccess(); |
| 10556 | |
| 10557 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10558 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10559 | |
| 10560 | if (!m_device->phy().features().geometryShader) { |
| 10561 | printf("Device does not support geometry shaders; skipped.\n"); |
| 10562 | return; |
| 10563 | } |
| 10564 | |
| 10565 | char const *vsSource = |
| 10566 | "#version 450\n" |
| 10567 | "layout(location=0) out VertexData { vec4 x; } vs_out;\n" |
| 10568 | "void main(){\n" |
| 10569 | " vs_out.x = vec4(1);\n" |
| 10570 | "}\n"; |
| 10571 | char const *gsSource = |
| 10572 | "#version 450\n" |
| 10573 | "layout(triangles) in;\n" |
| 10574 | "layout(triangle_strip, max_vertices=3) out;\n" |
| 10575 | "layout(location=0) in VertexData { vec4 x; } gs_in[];\n" |
| 10576 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 10577 | "void main() {\n" |
| 10578 | " gl_Position = gs_in[0].x;\n" |
| 10579 | " EmitVertex();\n" |
| 10580 | "}\n"; |
| 10581 | char const *fsSource = |
| 10582 | "#version 450\n" |
| 10583 | "layout(location=0) out vec4 color;\n" |
| 10584 | "void main(){\n" |
| 10585 | " color = vec4(1);\n" |
| 10586 | "}\n"; |
| 10587 | |
| 10588 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10589 | VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this); |
| 10590 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10591 | |
| 10592 | VkPipelineObj pipe(m_device); |
| 10593 | pipe.AddColorAttachment(); |
| 10594 | pipe.AddShader(&vs); |
| 10595 | pipe.AddShader(&gs); |
| 10596 | pipe.AddShader(&fs); |
| 10597 | |
| 10598 | VkDescriptorSetObj descriptorSet(m_device); |
| 10599 | descriptorSet.AppendDummy(); |
| 10600 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10601 | |
| 10602 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10603 | |
| 10604 | m_errorMonitor->VerifyNotFound(); |
| 10605 | } |
| 10606 | |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 10607 | TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) |
| 10608 | { |
| 10609 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10610 | "is per-vertex in tessellation control shader stage " |
| 10611 | "but per-patch in tessellation evaluation shader stage"); |
| 10612 | |
| 10613 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10614 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10615 | |
Chris Forbes | c1e852d | 2016-04-04 19:26:42 +1200 | [diff] [blame] | 10616 | if (!m_device->phy().features().tessellationShader) { |
| 10617 | printf("Device does not support tessellation shaders; skipped.\n"); |
| 10618 | return; |
| 10619 | } |
| 10620 | |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 10621 | char const *vsSource = |
| 10622 | "#version 450\n" |
| 10623 | "void main(){}\n"; |
| 10624 | char const *tcsSource = |
| 10625 | "#version 450\n" |
| 10626 | "layout(location=0) out int x[];\n" |
| 10627 | "layout(vertices=3) out;\n" |
| 10628 | "void main(){\n" |
| 10629 | " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n" |
| 10630 | " gl_TessLevelInner[0] = 1;\n" |
| 10631 | " x[gl_InvocationID] = gl_InvocationID;\n" |
| 10632 | "}\n"; |
| 10633 | char const *tesSource = |
| 10634 | "#version 450\n" |
| 10635 | "layout(triangles, equal_spacing, cw) in;\n" |
| 10636 | "layout(location=0) patch in int x;\n" |
| 10637 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 10638 | "void main(){\n" |
| 10639 | " gl_Position.xyz = gl_TessCoord;\n" |
| 10640 | " gl_Position.w = x;\n" |
| 10641 | "}\n"; |
| 10642 | char const *fsSource = |
| 10643 | "#version 450\n" |
| 10644 | "layout(location=0) out vec4 color;\n" |
| 10645 | "void main(){\n" |
| 10646 | " color = vec4(1);\n" |
| 10647 | "}\n"; |
| 10648 | |
| 10649 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10650 | VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this); |
| 10651 | VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this); |
| 10652 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10653 | |
| 10654 | VkPipelineInputAssemblyStateCreateInfo iasci{ |
| 10655 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, |
| 10656 | nullptr, |
| 10657 | 0, |
| 10658 | VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, |
| 10659 | VK_FALSE}; |
| 10660 | |
| 10661 | VkPipelineTessellationStateCreateInfo tsci{ |
| 10662 | VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, |
| 10663 | nullptr, |
| 10664 | 0, |
| 10665 | 3}; |
| 10666 | |
| 10667 | VkPipelineObj pipe(m_device); |
| 10668 | pipe.SetInputAssembly(&iasci); |
| 10669 | pipe.SetTessellation(&tsci); |
| 10670 | pipe.AddColorAttachment(); |
| 10671 | pipe.AddShader(&vs); |
| 10672 | pipe.AddShader(&tcs); |
| 10673 | pipe.AddShader(&tes); |
| 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->VerifyFound(); |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 10683 | } |
| 10684 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10685 | TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) { |
| 10686 | m_errorMonitor->SetDesiredFailureMsg( |
| 10687 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10688 | "Duplicate vertex input binding descriptions for binding 0"); |
| 10689 | |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10690 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10691 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10692 | |
| 10693 | /* Two binding descriptions for binding 0 */ |
| 10694 | VkVertexInputBindingDescription input_bindings[2]; |
| 10695 | memset(input_bindings, 0, sizeof(input_bindings)); |
| 10696 | |
| 10697 | VkVertexInputAttributeDescription input_attrib; |
| 10698 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10699 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10700 | |
| 10701 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10702 | "#version 450\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10703 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10704 | "layout(location=0) in float x;\n" /* attrib provided float */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10705 | "out gl_PerVertex {\n" |
| 10706 | " vec4 gl_Position;\n" |
| 10707 | "};\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10708 | "void main(){\n" |
| 10709 | " gl_Position = vec4(x);\n" |
| 10710 | "}\n"; |
| 10711 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10712 | "#version 450\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10713 | "\n" |
| 10714 | "layout(location=0) out vec4 color;\n" |
| 10715 | "void main(){\n" |
| 10716 | " color = vec4(1);\n" |
| 10717 | "}\n"; |
| 10718 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10719 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10720 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10721 | |
| 10722 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10723 | pipe.AddColorAttachment(); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10724 | pipe.AddShader(&vs); |
| 10725 | pipe.AddShader(&fs); |
| 10726 | |
| 10727 | pipe.AddVertexInputBindings(input_bindings, 2); |
| 10728 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10729 | |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10730 | VkDescriptorSetObj descriptorSet(m_device); |
| 10731 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10732 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10733 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10734 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10735 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10736 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10737 | } |
Chris Forbes | 8f68b56 | 2015-05-25 11:13:32 +1200 | [diff] [blame] | 10738 | |
Chris Forbes | 35efec7 | 2016-04-21 14:32:08 +1200 | [diff] [blame] | 10739 | TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) { |
| 10740 | m_errorMonitor->ExpectSuccess(); |
| 10741 | |
| 10742 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10743 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10744 | |
| 10745 | if (!m_device->phy().features().tessellationShader) { |
| 10746 | printf("Device does not support 64bit vertex attributes; skipped.\n"); |
| 10747 | return; |
| 10748 | } |
| 10749 | |
| 10750 | VkVertexInputBindingDescription input_bindings[1]; |
| 10751 | memset(input_bindings, 0, sizeof(input_bindings)); |
| 10752 | |
| 10753 | VkVertexInputAttributeDescription input_attribs[4]; |
| 10754 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 10755 | input_attribs[0].location = 0; |
| 10756 | input_attribs[0].offset = 0; |
| 10757 | input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 10758 | input_attribs[1].location = 2; |
| 10759 | input_attribs[1].offset = 32; |
| 10760 | input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 10761 | input_attribs[2].location = 4; |
| 10762 | input_attribs[2].offset = 64; |
| 10763 | input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 10764 | input_attribs[3].location = 6; |
| 10765 | input_attribs[3].offset = 96; |
| 10766 | input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 10767 | |
| 10768 | char const *vsSource = |
| 10769 | "#version 450\n" |
| 10770 | "\n" |
| 10771 | "layout(location=0) in dmat4 x;\n" |
| 10772 | "out gl_PerVertex {\n" |
| 10773 | " vec4 gl_Position;\n" |
| 10774 | "};\n" |
| 10775 | "void main(){\n" |
| 10776 | " gl_Position = vec4(x[0][0]);\n" |
| 10777 | "}\n"; |
| 10778 | char const *fsSource = |
| 10779 | "#version 450\n" |
| 10780 | "\n" |
| 10781 | "layout(location=0) out vec4 color;\n" |
| 10782 | "void main(){\n" |
| 10783 | " color = vec4(1);\n" |
| 10784 | "}\n"; |
| 10785 | |
| 10786 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10787 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10788 | |
| 10789 | VkPipelineObj pipe(m_device); |
| 10790 | pipe.AddColorAttachment(); |
| 10791 | pipe.AddShader(&vs); |
| 10792 | pipe.AddShader(&fs); |
| 10793 | |
| 10794 | pipe.AddVertexInputBindings(input_bindings, 1); |
| 10795 | pipe.AddVertexInputAttribs(input_attribs, 4); |
| 10796 | |
| 10797 | VkDescriptorSetObj descriptorSet(m_device); |
| 10798 | descriptorSet.AppendDummy(); |
| 10799 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10800 | |
| 10801 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10802 | |
| 10803 | m_errorMonitor->VerifyNotFound(); |
| 10804 | } |
| 10805 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10806 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10807 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10808 | "Attachment 0 not written by FS"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10809 | |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10810 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10811 | |
| 10812 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10813 | "#version 450\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10814 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10815 | "out gl_PerVertex {\n" |
| 10816 | " vec4 gl_Position;\n" |
| 10817 | "};\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10818 | "void main(){\n" |
| 10819 | " gl_Position = vec4(1);\n" |
| 10820 | "}\n"; |
| 10821 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10822 | "#version 450\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10823 | "\n" |
| 10824 | "void main(){\n" |
| 10825 | "}\n"; |
| 10826 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10827 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10828 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10829 | |
| 10830 | VkPipelineObj pipe(m_device); |
| 10831 | pipe.AddShader(&vs); |
| 10832 | pipe.AddShader(&fs); |
| 10833 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10834 | /* set up CB 0, not written */ |
| 10835 | pipe.AddColorAttachment(); |
| 10836 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10837 | |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10838 | VkDescriptorSetObj descriptorSet(m_device); |
| 10839 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10840 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10841 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10842 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10843 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10844 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10845 | } |
| 10846 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10847 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10848 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 10849 | VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10850 | "FS writes to output location 1 with no matching attachment"); |
| 10851 | |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10852 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10853 | |
| 10854 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10855 | "#version 450\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10856 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10857 | "out gl_PerVertex {\n" |
| 10858 | " vec4 gl_Position;\n" |
| 10859 | "};\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10860 | "void main(){\n" |
| 10861 | " gl_Position = vec4(1);\n" |
| 10862 | "}\n"; |
| 10863 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10864 | "#version 450\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10865 | "\n" |
| 10866 | "layout(location=0) out vec4 x;\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10867 | "layout(location=1) out vec4 y;\n" /* no matching attachment for this */ |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10868 | "void main(){\n" |
| 10869 | " x = vec4(1);\n" |
| 10870 | " y = vec4(1);\n" |
| 10871 | "}\n"; |
| 10872 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10873 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10874 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10875 | |
| 10876 | VkPipelineObj pipe(m_device); |
| 10877 | pipe.AddShader(&vs); |
| 10878 | pipe.AddShader(&fs); |
| 10879 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10880 | /* set up CB 0, not written */ |
| 10881 | pipe.AddColorAttachment(); |
| 10882 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10883 | /* FS writes CB 1, but we don't configure it */ |
| 10884 | |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10885 | VkDescriptorSetObj descriptorSet(m_device); |
| 10886 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10887 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10888 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10889 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10890 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10891 | m_errorMonitor->VerifyFound(); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10892 | } |
| 10893 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10894 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10895 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10896 | "does not match FS output type"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10897 | |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10898 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10899 | |
| 10900 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10901 | "#version 450\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10902 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10903 | "out gl_PerVertex {\n" |
| 10904 | " vec4 gl_Position;\n" |
| 10905 | "};\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10906 | "void main(){\n" |
| 10907 | " gl_Position = vec4(1);\n" |
| 10908 | "}\n"; |
| 10909 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10910 | "#version 450\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10911 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10912 | "layout(location=0) out ivec4 x;\n" /* not UNORM */ |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10913 | "void main(){\n" |
| 10914 | " x = ivec4(1);\n" |
| 10915 | "}\n"; |
| 10916 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10917 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10918 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10919 | |
| 10920 | VkPipelineObj pipe(m_device); |
| 10921 | pipe.AddShader(&vs); |
| 10922 | pipe.AddShader(&fs); |
| 10923 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10924 | /* set up CB 0; type is UNORM by default */ |
| 10925 | pipe.AddColorAttachment(); |
| 10926 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10927 | |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10928 | VkDescriptorSetObj descriptorSet(m_device); |
| 10929 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10930 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10931 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10932 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10933 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10934 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10935 | } |
Chris Forbes | 7b1b893 | 2015-06-05 14:43:36 +1200 | [diff] [blame] | 10936 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10937 | TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10938 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10939 | "not declared in pipeline layout"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10940 | |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 10941 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 10942 | |
| 10943 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10944 | "#version 450\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 10945 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10946 | "out gl_PerVertex {\n" |
| 10947 | " vec4 gl_Position;\n" |
| 10948 | "};\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 10949 | "void main(){\n" |
| 10950 | " gl_Position = vec4(1);\n" |
| 10951 | "}\n"; |
| 10952 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10953 | "#version 450\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 10954 | "\n" |
| 10955 | "layout(location=0) out vec4 x;\n" |
| 10956 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 10957 | "void main(){\n" |
| 10958 | " x = vec4(bar.y);\n" |
| 10959 | "}\n"; |
| 10960 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10961 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10962 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 10963 | |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 10964 | VkPipelineObj pipe(m_device); |
| 10965 | pipe.AddShader(&vs); |
| 10966 | pipe.AddShader(&fs); |
| 10967 | |
| 10968 | /* set up CB 0; type is UNORM by default */ |
| 10969 | pipe.AddColorAttachment(); |
| 10970 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10971 | |
| 10972 | VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10973 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 10974 | |
| 10975 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10976 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10977 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 10978 | } |
| 10979 | |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 10980 | TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) { |
| 10981 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10982 | "not declared in layout"); |
| 10983 | |
| 10984 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10985 | |
| 10986 | char const *vsSource = |
| 10987 | "#version 450\n" |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 10988 | "\n" |
| 10989 | "layout(push_constant, std430) uniform foo { float x; } consts;\n" |
| 10990 | "out gl_PerVertex {\n" |
| 10991 | " vec4 gl_Position;\n" |
| 10992 | "};\n" |
| 10993 | "void main(){\n" |
| 10994 | " gl_Position = vec4(consts.x);\n" |
| 10995 | "}\n"; |
| 10996 | char const *fsSource = |
| 10997 | "#version 450\n" |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 10998 | "\n" |
| 10999 | "layout(location=0) out vec4 x;\n" |
| 11000 | "void main(){\n" |
| 11001 | " x = vec4(1);\n" |
| 11002 | "}\n"; |
| 11003 | |
| 11004 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 11005 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 11006 | |
| 11007 | VkPipelineObj pipe(m_device); |
| 11008 | pipe.AddShader(&vs); |
| 11009 | pipe.AddShader(&fs); |
| 11010 | |
| 11011 | /* set up CB 0; type is UNORM by default */ |
| 11012 | pipe.AddColorAttachment(); |
| 11013 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11014 | |
| 11015 | VkDescriptorSetObj descriptorSet(m_device); |
| 11016 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11017 | |
| 11018 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 11019 | |
| 11020 | /* should have generated an error -- no push constant ranges provided! */ |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11021 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 11022 | } |
| 11023 | |
Chris Forbes | 10eb9ae | 2016-05-31 16:09:42 +1200 | [diff] [blame] | 11024 | TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) { |
| 11025 | m_errorMonitor->SetDesiredFailureMsg( |
| 11026 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11027 | "Shader uses descriptor slot 0.0"); |
| 11028 | |
| 11029 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11030 | |
| 11031 | char const *csSource = |
| 11032 | "#version 450\n" |
| 11033 | "\n" |
| 11034 | "layout(local_size_x=1) in;\n" |
| 11035 | "layout(set=0, binding=0) buffer block { vec4 x; };\n" |
| 11036 | "void main(){\n" |
| 11037 | " x = vec4(1);\n" |
| 11038 | "}\n"; |
| 11039 | |
| 11040 | VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this); |
| 11041 | |
| 11042 | VkDescriptorSetObj descriptorSet(m_device); |
| 11043 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11044 | |
| 11045 | VkComputePipelineCreateInfo cpci = { |
| 11046 | VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, |
| 11047 | nullptr, 0, { |
| 11048 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 11049 | nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, |
| 11050 | cs.handle(), "main", nullptr |
| 11051 | }, |
| 11052 | descriptorSet.GetPipelineLayout(), |
| 11053 | VK_NULL_HANDLE, -1 |
| 11054 | }; |
| 11055 | |
| 11056 | VkPipeline pipe; |
| 11057 | VkResult err = vkCreateComputePipelines( |
| 11058 | m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe); |
| 11059 | |
| 11060 | m_errorMonitor->VerifyFound(); |
| 11061 | |
| 11062 | if (err == VK_SUCCESS) { |
| 11063 | vkDestroyPipeline(m_device->device(), pipe, nullptr); |
| 11064 | } |
| 11065 | } |
| 11066 | |
| 11067 | TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) { |
| 11068 | m_errorMonitor->ExpectSuccess(); |
| 11069 | |
| 11070 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11071 | |
| 11072 | char const *csSource = |
| 11073 | "#version 450\n" |
| 11074 | "\n" |
| 11075 | "layout(local_size_x=1) in;\n" |
| 11076 | "layout(set=0, binding=0) buffer block { vec4 x; };\n" |
| 11077 | "void main(){\n" |
| 11078 | " // x is not used.\n" |
| 11079 | "}\n"; |
| 11080 | |
| 11081 | VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this); |
| 11082 | |
| 11083 | VkDescriptorSetObj descriptorSet(m_device); |
| 11084 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11085 | |
| 11086 | VkComputePipelineCreateInfo cpci = { |
| 11087 | VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, |
| 11088 | nullptr, 0, { |
| 11089 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 11090 | nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, |
| 11091 | cs.handle(), "main", nullptr |
| 11092 | }, |
| 11093 | descriptorSet.GetPipelineLayout(), |
| 11094 | VK_NULL_HANDLE, -1 |
| 11095 | }; |
| 11096 | |
| 11097 | VkPipeline pipe; |
| 11098 | VkResult err = vkCreateComputePipelines( |
| 11099 | m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe); |
| 11100 | |
| 11101 | m_errorMonitor->VerifyNotFound(); |
| 11102 | |
| 11103 | if (err == VK_SUCCESS) { |
| 11104 | vkDestroyPipeline(m_device->device(), pipe, nullptr); |
| 11105 | } |
| 11106 | } |
| 11107 | |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 11108 | #endif // SHADER_CHECKER_TESTS |
| 11109 | |
| 11110 | #if DEVICE_LIMITS_TESTS |
Mark Young | c48c4c1 | 2016-04-11 14:26:49 -0600 | [diff] [blame] | 11111 | TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11112 | m_errorMonitor->SetDesiredFailureMsg( |
| 11113 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11114 | "CreateImage extents exceed allowable limits for format"); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11115 | |
| 11116 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11117 | |
| 11118 | // Create an image |
| 11119 | VkImage image; |
| 11120 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11121 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11122 | const int32_t tex_width = 32; |
| 11123 | const int32_t tex_height = 32; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11124 | |
| 11125 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11126 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11127 | image_create_info.pNext = NULL; |
| 11128 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11129 | image_create_info.format = tex_format; |
| 11130 | image_create_info.extent.width = tex_width; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11131 | image_create_info.extent.height = tex_height; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11132 | image_create_info.extent.depth = 1; |
| 11133 | image_create_info.mipLevels = 1; |
| 11134 | image_create_info.arrayLayers = 1; |
| 11135 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11136 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11137 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 11138 | image_create_info.flags = 0; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11139 | |
| 11140 | // Introduce error by sending down a bogus width extent |
| 11141 | image_create_info.extent.width = 65536; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11142 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11143 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11144 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11145 | } |
| 11146 | |
Mark Young | c48c4c1 | 2016-04-11 14:26:49 -0600 | [diff] [blame] | 11147 | TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) { |
| 11148 | m_errorMonitor->SetDesiredFailureMsg( |
| 11149 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11150 | "CreateImage extents is 0 for at least one required dimension"); |
| 11151 | |
| 11152 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11153 | |
| 11154 | // Create an image |
| 11155 | VkImage image; |
| 11156 | |
| 11157 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11158 | const int32_t tex_width = 32; |
| 11159 | const int32_t tex_height = 32; |
| 11160 | |
| 11161 | VkImageCreateInfo image_create_info = {}; |
| 11162 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11163 | image_create_info.pNext = NULL; |
| 11164 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11165 | image_create_info.format = tex_format; |
| 11166 | image_create_info.extent.width = tex_width; |
| 11167 | image_create_info.extent.height = tex_height; |
| 11168 | image_create_info.extent.depth = 1; |
| 11169 | image_create_info.mipLevels = 1; |
| 11170 | image_create_info.arrayLayers = 1; |
| 11171 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11172 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11173 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 11174 | image_create_info.flags = 0; |
| 11175 | |
| 11176 | // Introduce error by sending down a bogus width extent |
| 11177 | image_create_info.extent.width = 0; |
| 11178 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 11179 | |
| 11180 | m_errorMonitor->VerifyFound(); |
| 11181 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 11182 | #endif // DEVICE_LIMITS_TESTS |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11183 | |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11184 | #if IMAGE_TESTS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11185 | TEST_F(VkLayerTest, InvalidImageView) { |
| 11186 | VkResult err; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11187 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11188 | m_errorMonitor->SetDesiredFailureMsg( |
| 11189 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11190 | "vkCreateImageView called with baseMipLevel 10 "); |
| 11191 | |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11192 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11193 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11194 | // Create an image and try to create a view with bad baseMipLevel |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11195 | VkImage image; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11196 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11197 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11198 | const int32_t tex_width = 32; |
| 11199 | const int32_t tex_height = 32; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11200 | |
| 11201 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11202 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11203 | image_create_info.pNext = NULL; |
| 11204 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11205 | image_create_info.format = tex_format; |
| 11206 | image_create_info.extent.width = tex_width; |
| 11207 | image_create_info.extent.height = tex_height; |
| 11208 | image_create_info.extent.depth = 1; |
| 11209 | image_create_info.mipLevels = 1; |
| 11210 | image_create_info.arrayLayers = 1; |
| 11211 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11212 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11213 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 11214 | image_create_info.flags = 0; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11215 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11216 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11217 | ASSERT_VK_SUCCESS(err); |
| 11218 | |
| 11219 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11220 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11221 | image_view_create_info.image = image; |
| 11222 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 11223 | image_view_create_info.format = tex_format; |
| 11224 | image_view_create_info.subresourceRange.layerCount = 1; |
| 11225 | image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error |
| 11226 | image_view_create_info.subresourceRange.levelCount = 1; |
| 11227 | image_view_create_info.subresourceRange.aspectMask = |
| 11228 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11229 | |
| 11230 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11231 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 11232 | &view); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11233 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11234 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 11235 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11236 | } |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11237 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11238 | TEST_F(VkLayerTest, InvalidImageViewAspect) { |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11239 | TEST_DESCRIPTION( |
| 11240 | "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] | 11241 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11242 | "vkCreateImageView: Color image " |
| 11243 | "formats must have ONLY the " |
| 11244 | "VK_IMAGE_ASPECT_COLOR_BIT set"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11245 | |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11246 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11247 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11248 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11249 | VkImageObj image(m_device); |
| 11250 | image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, |
| 11251 | VK_IMAGE_TILING_LINEAR, 0); |
| 11252 | ASSERT_TRUE(image.initialized()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11253 | |
| 11254 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11255 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11256 | image_view_create_info.image = image.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11257 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 11258 | image_view_create_info.format = tex_format; |
| 11259 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 11260 | image_view_create_info.subresourceRange.levelCount = 1; |
| 11261 | // Cause an error by setting an invalid image aspect |
| 11262 | image_view_create_info.subresourceRange.aspectMask = |
| 11263 | VK_IMAGE_ASPECT_METADATA_BIT; |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11264 | |
| 11265 | VkImageView view; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11266 | vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11267 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11268 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11269 | } |
| 11270 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11271 | TEST_F(VkLayerTest, CopyImageLayerCountMismatch) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11272 | VkResult err; |
| 11273 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11274 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11275 | m_errorMonitor->SetDesiredFailureMsg( |
| 11276 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11277 | "vkCmdCopyImage: number of layers in source and destination subresources for pRegions"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11278 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11279 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11280 | |
| 11281 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11282 | VkImage srcImage; |
| 11283 | VkImage dstImage; |
| 11284 | VkDeviceMemory srcMem; |
| 11285 | VkDeviceMemory destMem; |
| 11286 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11287 | |
| 11288 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11289 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11290 | image_create_info.pNext = NULL; |
| 11291 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11292 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11293 | image_create_info.extent.width = 32; |
| 11294 | image_create_info.extent.height = 32; |
| 11295 | image_create_info.extent.depth = 1; |
| 11296 | image_create_info.mipLevels = 1; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11297 | image_create_info.arrayLayers = 4; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11298 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11299 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 11300 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11301 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11302 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11303 | err = |
| 11304 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11305 | ASSERT_VK_SUCCESS(err); |
| 11306 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11307 | err = |
| 11308 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11309 | ASSERT_VK_SUCCESS(err); |
| 11310 | |
| 11311 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11312 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11313 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 11314 | memAlloc.pNext = NULL; |
| 11315 | memAlloc.allocationSize = 0; |
| 11316 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11317 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 11318 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11319 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11320 | pass = |
| 11321 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 11322 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11323 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11324 | ASSERT_VK_SUCCESS(err); |
| 11325 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11326 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11327 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11328 | pass = |
| 11329 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11330 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11331 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11332 | ASSERT_VK_SUCCESS(err); |
| 11333 | |
| 11334 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 11335 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11336 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11337 | ASSERT_VK_SUCCESS(err); |
| 11338 | |
| 11339 | BeginCommandBuffer(); |
| 11340 | VkImageCopy copyRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11341 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11342 | copyRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 11343 | copyRegion.srcSubresource.baseArrayLayer = 0; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11344 | copyRegion.srcSubresource.layerCount = 1; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11345 | copyRegion.srcOffset.x = 0; |
| 11346 | copyRegion.srcOffset.y = 0; |
| 11347 | copyRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11348 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11349 | copyRegion.dstSubresource.mipLevel = 0; |
| 11350 | copyRegion.dstSubresource.baseArrayLayer = 0; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11351 | // Introduce failure by forcing the dst layerCount to differ from src |
| 11352 | copyRegion.dstSubresource.layerCount = 3; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11353 | copyRegion.dstOffset.x = 0; |
| 11354 | copyRegion.dstOffset.y = 0; |
| 11355 | copyRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11356 | copyRegion.extent.width = 1; |
| 11357 | copyRegion.extent.height = 1; |
| 11358 | copyRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11359 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 11360 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11361 | EndCommandBuffer(); |
| 11362 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11363 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11364 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11365 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11366 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11367 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 11368 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11369 | } |
| 11370 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11371 | TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) { |
| 11372 | |
| 11373 | TEST_DESCRIPTION("Creating images with unsuported formats "); |
| 11374 | |
| 11375 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11376 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11377 | VkImageObj image(m_device); |
| 11378 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 11379 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 11380 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 11381 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 11382 | ASSERT_TRUE(image.initialized()); |
| 11383 | |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11384 | // Create image with unsupported format - Expect FORMAT_UNSUPPORTED |
| 11385 | VkImageCreateInfo image_create_info; |
| 11386 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11387 | image_create_info.pNext = NULL; |
| 11388 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11389 | image_create_info.format = VK_FORMAT_UNDEFINED; |
| 11390 | image_create_info.extent.width = 32; |
| 11391 | image_create_info.extent.height = 32; |
| 11392 | image_create_info.extent.depth = 1; |
| 11393 | image_create_info.mipLevels = 1; |
| 11394 | image_create_info.arrayLayers = 1; |
| 11395 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11396 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 11397 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11398 | image_create_info.flags = 0; |
| 11399 | |
| 11400 | m_errorMonitor->SetDesiredFailureMsg( |
| 11401 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11402 | "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED"); |
| 11403 | |
| 11404 | VkImage localImage; |
| 11405 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage); |
| 11406 | m_errorMonitor->VerifyFound(); |
| 11407 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11408 | VkFormat unsupported = VK_FORMAT_UNDEFINED; |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11409 | // Look for a format that is COMPLETELY unsupported with this hardware |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11410 | for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) { |
| 11411 | VkFormat format = static_cast<VkFormat>(f); |
| 11412 | VkFormatProperties fProps = m_device->format_properties(format); |
| 11413 | if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && |
| 11414 | fProps.optimalTilingFeatures == 0) { |
| 11415 | unsupported = format; |
| 11416 | break; |
| 11417 | } |
| 11418 | } |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11419 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11420 | if (unsupported != VK_FORMAT_UNDEFINED) { |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11421 | image_create_info.format = unsupported; |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11422 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11423 | "is an unsupported format"); |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11424 | |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11425 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage); |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11426 | m_errorMonitor->VerifyFound(); |
| 11427 | } |
| 11428 | } |
| 11429 | |
| 11430 | TEST_F(VkLayerTest, ImageLayerViewTests) { |
| 11431 | VkResult ret; |
| 11432 | TEST_DESCRIPTION("Passing bad parameters to CreateImageView"); |
| 11433 | |
| 11434 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11435 | |
| 11436 | VkImageObj image(m_device); |
| 11437 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 11438 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 11439 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 11440 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 11441 | ASSERT_TRUE(image.initialized()); |
| 11442 | |
| 11443 | VkImageView imgView; |
| 11444 | VkImageViewCreateInfo imgViewInfo = {}; |
| 11445 | imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 11446 | imgViewInfo.image = image.handle(); |
| 11447 | imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 11448 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11449 | imgViewInfo.subresourceRange.layerCount = 1; |
| 11450 | imgViewInfo.subresourceRange.baseMipLevel = 0; |
| 11451 | imgViewInfo.subresourceRange.levelCount = 1; |
| 11452 | imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11453 | |
| 11454 | m_errorMonitor->SetDesiredFailureMsg( |
| 11455 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11456 | "vkCreateImageView called with baseMipLevel"); |
| 11457 | // View can't have baseMipLevel >= image's mipLevels - Expect |
| 11458 | // VIEW_CREATE_ERROR |
| 11459 | imgViewInfo.subresourceRange.baseMipLevel = 1; |
| 11460 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11461 | m_errorMonitor->VerifyFound(); |
| 11462 | imgViewInfo.subresourceRange.baseMipLevel = 0; |
| 11463 | |
| 11464 | m_errorMonitor->SetDesiredFailureMsg( |
| 11465 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11466 | "vkCreateImageView called with baseArrayLayer"); |
| 11467 | // View can't have baseArrayLayer >= image's arraySize - Expect |
| 11468 | // VIEW_CREATE_ERROR |
| 11469 | imgViewInfo.subresourceRange.baseArrayLayer = 1; |
| 11470 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11471 | m_errorMonitor->VerifyFound(); |
| 11472 | imgViewInfo.subresourceRange.baseArrayLayer = 0; |
| 11473 | |
| 11474 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11475 | "vkCreateImageView called with 0 in " |
| 11476 | "pCreateInfo->subresourceRange." |
| 11477 | "levelCount"); |
| 11478 | // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR |
| 11479 | imgViewInfo.subresourceRange.levelCount = 0; |
| 11480 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11481 | m_errorMonitor->VerifyFound(); |
| 11482 | imgViewInfo.subresourceRange.levelCount = 1; |
| 11483 | |
| 11484 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11485 | "vkCreateImageView called with 0 in " |
| 11486 | "pCreateInfo->subresourceRange." |
| 11487 | "layerCount"); |
| 11488 | // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR |
| 11489 | imgViewInfo.subresourceRange.layerCount = 0; |
| 11490 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11491 | m_errorMonitor->VerifyFound(); |
| 11492 | imgViewInfo.subresourceRange.layerCount = 1; |
| 11493 | |
| 11494 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11495 | "but both must be color formats"); |
| 11496 | // Can't use depth format for view into color image - Expect INVALID_FORMAT |
| 11497 | imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 11498 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11499 | m_errorMonitor->VerifyFound(); |
| 11500 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11501 | |
| 11502 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11503 | "Formats MUST be IDENTICAL unless " |
| 11504 | "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT " |
| 11505 | "was set on image creation."); |
| 11506 | // Same compatibility class but no MUTABLE_FORMAT bit - Expect |
| 11507 | // VIEW_CREATE_ERROR |
| 11508 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT; |
| 11509 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11510 | m_errorMonitor->VerifyFound(); |
| 11511 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11512 | |
| 11513 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11514 | "can support ImageViews with " |
| 11515 | "differing formats but they must be " |
| 11516 | "in the same compatibility class."); |
| 11517 | // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect |
| 11518 | // VIEW_CREATE_ERROR |
| 11519 | VkImageCreateInfo mutImgInfo = image.create_info(); |
| 11520 | VkImage mutImage; |
| 11521 | mutImgInfo.format = VK_FORMAT_R8_UINT; |
| 11522 | assert( |
| 11523 | m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & |
| 11524 | VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT); |
| 11525 | mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; |
| 11526 | mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 11527 | ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage); |
| 11528 | ASSERT_VK_SUCCESS(ret); |
| 11529 | imgViewInfo.image = mutImage; |
| 11530 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11531 | m_errorMonitor->VerifyFound(); |
| 11532 | imgViewInfo.image = image.handle(); |
| 11533 | vkDestroyImage(m_device->handle(), mutImage, NULL); |
| 11534 | } |
| 11535 | |
| 11536 | TEST_F(VkLayerTest, MiscImageLayerTests) { |
| 11537 | |
| 11538 | TEST_DESCRIPTION("Image layer tests that don't belong elsewhare"); |
| 11539 | |
| 11540 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11541 | |
| 11542 | VkImageObj image(m_device); |
| 11543 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 11544 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 11545 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 11546 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 11547 | ASSERT_TRUE(image.initialized()); |
| 11548 | |
| 11549 | m_errorMonitor->SetDesiredFailureMsg( |
| 11550 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11551 | "number of layers in image subresource is zero"); |
| 11552 | vk_testing::Buffer buffer; |
| 11553 | VkMemoryPropertyFlags reqs = 0; |
| 11554 | buffer.init_as_src(*m_device, 128 * 128 * 4, reqs); |
| 11555 | VkBufferImageCopy region = {}; |
| 11556 | region.bufferRowLength = 128; |
| 11557 | region.bufferImageHeight = 128; |
| 11558 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11559 | // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT |
| 11560 | region.imageSubresource.layerCount = 0; |
| 11561 | region.imageExtent.height = 4; |
| 11562 | region.imageExtent.width = 4; |
| 11563 | region.imageExtent.depth = 1; |
| 11564 | m_commandBuffer->BeginCommandBuffer(); |
| 11565 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 11566 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 11567 | 1, ®ion); |
| 11568 | m_errorMonitor->VerifyFound(); |
| 11569 | region.imageSubresource.layerCount = 1; |
| 11570 | |
| 11571 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11572 | "aspectMasks for each region must " |
| 11573 | "specify only COLOR or DEPTH or " |
| 11574 | "STENCIL"); |
| 11575 | // Expect MISMATCHED_IMAGE_ASPECT |
| 11576 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT; |
| 11577 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 11578 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 11579 | 1, ®ion); |
| 11580 | m_errorMonitor->VerifyFound(); |
| 11581 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11582 | |
| 11583 | m_errorMonitor->SetDesiredFailureMsg( |
| 11584 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11585 | "If the format of srcImage is a depth, stencil, depth stencil or " |
| 11586 | "integer-based format then filter must be VK_FILTER_NEAREST"); |
| 11587 | // Expect INVALID_FILTER |
| 11588 | VkImageObj intImage1(m_device); |
| 11589 | intImage1.init(128, 128, VK_FORMAT_R8_UINT, |
| 11590 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, |
| 11591 | 0); |
| 11592 | VkImageObj intImage2(m_device); |
| 11593 | intImage2.init(128, 128, VK_FORMAT_R8_UINT, |
| 11594 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, |
| 11595 | 0); |
| 11596 | VkImageBlit blitRegion = {}; |
| 11597 | blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11598 | blitRegion.srcSubresource.baseArrayLayer = 0; |
| 11599 | blitRegion.srcSubresource.layerCount = 1; |
| 11600 | blitRegion.srcSubresource.mipLevel = 0; |
| 11601 | blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11602 | blitRegion.dstSubresource.baseArrayLayer = 0; |
| 11603 | blitRegion.dstSubresource.layerCount = 1; |
| 11604 | blitRegion.dstSubresource.mipLevel = 0; |
| 11605 | |
| 11606 | vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), |
| 11607 | intImage1.layout(), intImage2.handle(), intImage2.layout(), |
| 11608 | 16, &blitRegion, VK_FILTER_LINEAR); |
| 11609 | m_errorMonitor->VerifyFound(); |
| 11610 | |
| 11611 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11612 | "called with 0 in ppMemoryBarriers"); |
| 11613 | VkImageMemoryBarrier img_barrier; |
| 11614 | img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 11615 | img_barrier.pNext = NULL; |
| 11616 | img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 11617 | img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 11618 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 11619 | img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 11620 | img_barrier.image = image.handle(); |
| 11621 | img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 11622 | img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 11623 | img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11624 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 11625 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 11626 | // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE |
| 11627 | img_barrier.subresourceRange.layerCount = 0; |
| 11628 | img_barrier.subresourceRange.levelCount = 1; |
| 11629 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 11630 | VK_PIPELINE_STAGE_HOST_BIT, |
| 11631 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 11632 | nullptr, 1, &img_barrier); |
| 11633 | m_errorMonitor->VerifyFound(); |
| 11634 | img_barrier.subresourceRange.layerCount = 1; |
| 11635 | } |
| 11636 | |
| 11637 | TEST_F(VkLayerTest, ImageFormatLimits) { |
| 11638 | |
| 11639 | TEST_DESCRIPTION("Exceed the limits of image format "); |
| 11640 | |
| 11641 | m_errorMonitor->SetDesiredFailureMsg( |
| 11642 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11643 | "CreateImage extents exceed allowable limits for format"); |
| 11644 | VkImageCreateInfo image_create_info = {}; |
| 11645 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11646 | image_create_info.pNext = NULL; |
| 11647 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11648 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11649 | image_create_info.extent.width = 32; |
| 11650 | image_create_info.extent.height = 32; |
| 11651 | image_create_info.extent.depth = 1; |
| 11652 | image_create_info.mipLevels = 1; |
| 11653 | image_create_info.arrayLayers = 1; |
| 11654 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11655 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11656 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11657 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 11658 | image_create_info.flags = 0; |
| 11659 | |
| 11660 | VkImage nullImg; |
| 11661 | VkImageFormatProperties imgFmtProps; |
| 11662 | vkGetPhysicalDeviceImageFormatProperties( |
| 11663 | gpu(), image_create_info.format, image_create_info.imageType, |
| 11664 | image_create_info.tiling, image_create_info.usage, |
| 11665 | image_create_info.flags, &imgFmtProps); |
| 11666 | image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1; |
| 11667 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 11668 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11669 | m_errorMonitor->VerifyFound(); |
| 11670 | image_create_info.extent.depth = 1; |
| 11671 | |
| 11672 | m_errorMonitor->SetDesiredFailureMsg( |
| 11673 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11674 | "exceeds allowable maximum supported by format of"); |
| 11675 | image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1; |
| 11676 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 11677 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11678 | m_errorMonitor->VerifyFound(); |
| 11679 | image_create_info.mipLevels = 1; |
| 11680 | |
| 11681 | m_errorMonitor->SetDesiredFailureMsg( |
| 11682 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11683 | "exceeds allowable maximum supported by format of"); |
| 11684 | image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1; |
| 11685 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 11686 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11687 | m_errorMonitor->VerifyFound(); |
| 11688 | image_create_info.arrayLayers = 1; |
| 11689 | |
| 11690 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11691 | "is not supported by format"); |
| 11692 | int samples = imgFmtProps.sampleCounts >> 1; |
| 11693 | image_create_info.samples = (VkSampleCountFlagBits)samples; |
| 11694 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 11695 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11696 | m_errorMonitor->VerifyFound(); |
| 11697 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11698 | |
| 11699 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11700 | "pCreateInfo->initialLayout, must be " |
| 11701 | "VK_IMAGE_LAYOUT_UNDEFINED or " |
| 11702 | "VK_IMAGE_LAYOUT_PREINITIALIZED"); |
| 11703 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 11704 | // Expect INVALID_LAYOUT |
| 11705 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11706 | m_errorMonitor->VerifyFound(); |
| 11707 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 11708 | } |
| 11709 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11710 | TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 11711 | VkResult err; |
| 11712 | bool pass; |
| 11713 | |
| 11714 | // Create color images with different format sizes and try to copy between them |
| 11715 | m_errorMonitor->SetDesiredFailureMsg( |
| 11716 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11717 | "vkCmdCopyImage called with unmatched source and dest image format sizes"); |
| 11718 | |
| 11719 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11720 | |
| 11721 | // Create two images of different types and try to copy between them |
| 11722 | VkImage srcImage; |
| 11723 | VkImage dstImage; |
| 11724 | VkDeviceMemory srcMem; |
| 11725 | VkDeviceMemory destMem; |
| 11726 | VkMemoryRequirements memReqs; |
| 11727 | |
| 11728 | VkImageCreateInfo image_create_info = {}; |
| 11729 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11730 | image_create_info.pNext = NULL; |
| 11731 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11732 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11733 | image_create_info.extent.width = 32; |
| 11734 | image_create_info.extent.height = 32; |
| 11735 | image_create_info.extent.depth = 1; |
| 11736 | image_create_info.mipLevels = 1; |
| 11737 | image_create_info.arrayLayers = 1; |
| 11738 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11739 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11740 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11741 | image_create_info.flags = 0; |
| 11742 | |
| 11743 | err = |
| 11744 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
| 11745 | ASSERT_VK_SUCCESS(err); |
| 11746 | |
| 11747 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 11748 | // Introduce failure by creating second image with a different-sized format. |
| 11749 | image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16; |
| 11750 | |
| 11751 | err = |
| 11752 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
| 11753 | ASSERT_VK_SUCCESS(err); |
| 11754 | |
| 11755 | // Allocate memory |
| 11756 | VkMemoryAllocateInfo memAlloc = {}; |
| 11757 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 11758 | memAlloc.pNext = NULL; |
| 11759 | memAlloc.allocationSize = 0; |
| 11760 | memAlloc.memoryTypeIndex = 0; |
| 11761 | |
| 11762 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
| 11763 | memAlloc.allocationSize = memReqs.size; |
| 11764 | pass = |
| 11765 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
| 11766 | ASSERT_TRUE(pass); |
| 11767 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
| 11768 | ASSERT_VK_SUCCESS(err); |
| 11769 | |
| 11770 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
| 11771 | memAlloc.allocationSize = memReqs.size; |
| 11772 | pass = |
| 11773 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
| 11774 | ASSERT_TRUE(pass); |
| 11775 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
| 11776 | ASSERT_VK_SUCCESS(err); |
| 11777 | |
| 11778 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 11779 | ASSERT_VK_SUCCESS(err); |
| 11780 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
| 11781 | ASSERT_VK_SUCCESS(err); |
| 11782 | |
| 11783 | BeginCommandBuffer(); |
| 11784 | VkImageCopy copyRegion; |
| 11785 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11786 | copyRegion.srcSubresource.mipLevel = 0; |
| 11787 | copyRegion.srcSubresource.baseArrayLayer = 0; |
| 11788 | copyRegion.srcSubresource.layerCount = 0; |
| 11789 | copyRegion.srcOffset.x = 0; |
| 11790 | copyRegion.srcOffset.y = 0; |
| 11791 | copyRegion.srcOffset.z = 0; |
| 11792 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11793 | copyRegion.dstSubresource.mipLevel = 0; |
| 11794 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 11795 | copyRegion.dstSubresource.layerCount = 0; |
| 11796 | copyRegion.dstOffset.x = 0; |
| 11797 | copyRegion.dstOffset.y = 0; |
| 11798 | copyRegion.dstOffset.z = 0; |
| 11799 | copyRegion.extent.width = 1; |
| 11800 | copyRegion.extent.height = 1; |
| 11801 | copyRegion.extent.depth = 1; |
| 11802 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 11803 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 11804 | EndCommandBuffer(); |
| 11805 | |
| 11806 | m_errorMonitor->VerifyFound(); |
| 11807 | |
| 11808 | vkDestroyImage(m_device->device(), srcImage, NULL); |
| 11809 | vkDestroyImage(m_device->device(), dstImage, NULL); |
| 11810 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 11811 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11812 | } |
| 11813 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11814 | TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) { |
| 11815 | VkResult err; |
| 11816 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11817 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11818 | // 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] | 11819 | m_errorMonitor->SetDesiredFailureMsg( |
| 11820 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11821 | "vkCmdCopyImage called with unmatched source and dest image depth"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11822 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11823 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11824 | |
| 11825 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11826 | VkImage srcImage; |
| 11827 | VkImage dstImage; |
| 11828 | VkDeviceMemory srcMem; |
| 11829 | VkDeviceMemory destMem; |
| 11830 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11831 | |
| 11832 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11833 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11834 | image_create_info.pNext = NULL; |
| 11835 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11836 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11837 | image_create_info.extent.width = 32; |
| 11838 | image_create_info.extent.height = 32; |
| 11839 | image_create_info.extent.depth = 1; |
| 11840 | image_create_info.mipLevels = 1; |
| 11841 | image_create_info.arrayLayers = 1; |
| 11842 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11843 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11844 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11845 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11846 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11847 | err = |
| 11848 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11849 | ASSERT_VK_SUCCESS(err); |
| 11850 | |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 11851 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 11852 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11853 | // Introduce failure by creating second image with a depth/stencil format |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11854 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11855 | image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 11856 | image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11857 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11858 | err = |
| 11859 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11860 | ASSERT_VK_SUCCESS(err); |
| 11861 | |
| 11862 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11863 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11864 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 11865 | memAlloc.pNext = NULL; |
| 11866 | memAlloc.allocationSize = 0; |
| 11867 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11868 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 11869 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11870 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11871 | pass = |
| 11872 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 11873 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11874 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11875 | ASSERT_VK_SUCCESS(err); |
| 11876 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11877 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11878 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11879 | pass = |
| 11880 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 11881 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11882 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11883 | ASSERT_VK_SUCCESS(err); |
| 11884 | |
| 11885 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 11886 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11887 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11888 | ASSERT_VK_SUCCESS(err); |
| 11889 | |
| 11890 | BeginCommandBuffer(); |
| 11891 | VkImageCopy copyRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11892 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11893 | copyRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 11894 | copyRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11895 | copyRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11896 | copyRegion.srcOffset.x = 0; |
| 11897 | copyRegion.srcOffset.y = 0; |
| 11898 | copyRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11899 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11900 | copyRegion.dstSubresource.mipLevel = 0; |
| 11901 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 11902 | copyRegion.dstSubresource.layerCount = 0; |
| 11903 | copyRegion.dstOffset.x = 0; |
| 11904 | copyRegion.dstOffset.y = 0; |
| 11905 | copyRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11906 | copyRegion.extent.width = 1; |
| 11907 | copyRegion.extent.height = 1; |
| 11908 | copyRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11909 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 11910 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11911 | EndCommandBuffer(); |
| 11912 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11913 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11914 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11915 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11916 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11917 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 11918 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11919 | } |
| 11920 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11921 | TEST_F(VkLayerTest, ResolveImageLowSampleCount) { |
| 11922 | VkResult err; |
| 11923 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11924 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11925 | m_errorMonitor->SetDesiredFailureMsg( |
| 11926 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11927 | "vkCmdResolveImage called with source sample count less than 2."); |
| 11928 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11929 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11930 | |
| 11931 | // 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] | 11932 | VkImage srcImage; |
| 11933 | VkImage dstImage; |
| 11934 | VkDeviceMemory srcMem; |
| 11935 | VkDeviceMemory destMem; |
| 11936 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11937 | |
| 11938 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11939 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11940 | image_create_info.pNext = NULL; |
| 11941 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11942 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11943 | image_create_info.extent.width = 32; |
| 11944 | image_create_info.extent.height = 1; |
| 11945 | image_create_info.extent.depth = 1; |
| 11946 | image_create_info.mipLevels = 1; |
| 11947 | image_create_info.arrayLayers = 1; |
| 11948 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11949 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 11950 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11951 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11952 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11953 | err = |
| 11954 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11955 | ASSERT_VK_SUCCESS(err); |
| 11956 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11957 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11958 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11959 | err = |
| 11960 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11961 | ASSERT_VK_SUCCESS(err); |
| 11962 | |
| 11963 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11964 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11965 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 11966 | memAlloc.pNext = NULL; |
| 11967 | memAlloc.allocationSize = 0; |
| 11968 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11969 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 11970 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11971 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11972 | pass = |
| 11973 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 11974 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11975 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11976 | ASSERT_VK_SUCCESS(err); |
| 11977 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11978 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11979 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11980 | pass = |
| 11981 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 11982 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11983 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11984 | ASSERT_VK_SUCCESS(err); |
| 11985 | |
| 11986 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 11987 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11988 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11989 | ASSERT_VK_SUCCESS(err); |
| 11990 | |
| 11991 | BeginCommandBuffer(); |
| 11992 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11993 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 11994 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11995 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11996 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11997 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 11998 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11999 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12000 | resolveRegion.srcOffset.x = 0; |
| 12001 | resolveRegion.srcOffset.y = 0; |
| 12002 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12003 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12004 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12005 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12006 | resolveRegion.dstSubresource.layerCount = 0; |
| 12007 | resolveRegion.dstOffset.x = 0; |
| 12008 | resolveRegion.dstOffset.y = 0; |
| 12009 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12010 | resolveRegion.extent.width = 1; |
| 12011 | resolveRegion.extent.height = 1; |
| 12012 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12013 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12014 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12015 | EndCommandBuffer(); |
| 12016 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12017 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12018 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12019 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12020 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12021 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12022 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12023 | } |
| 12024 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12025 | TEST_F(VkLayerTest, ResolveImageHighSampleCount) { |
| 12026 | VkResult err; |
| 12027 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12028 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12029 | m_errorMonitor->SetDesiredFailureMsg( |
| 12030 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12031 | "vkCmdResolveImage called with dest sample count greater than 1."); |
| 12032 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12033 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12034 | |
Chris Forbes | a753069 | 2016-05-08 12:35:39 +1200 | [diff] [blame] | 12035 | // 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] | 12036 | VkImage srcImage; |
| 12037 | VkImage dstImage; |
| 12038 | VkDeviceMemory srcMem; |
| 12039 | VkDeviceMemory destMem; |
| 12040 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12041 | |
| 12042 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12043 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12044 | image_create_info.pNext = NULL; |
| 12045 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12046 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12047 | image_create_info.extent.width = 32; |
| 12048 | image_create_info.extent.height = 1; |
| 12049 | image_create_info.extent.depth = 1; |
| 12050 | image_create_info.mipLevels = 1; |
| 12051 | image_create_info.arrayLayers = 1; |
Chris Forbes | a753069 | 2016-05-08 12:35:39 +1200 | [diff] [blame] | 12052 | image_create_info.samples = VK_SAMPLE_COUNT_4_BIT; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12053 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12054 | // Note: Some implementations expect color attachment usage for any |
| 12055 | // multisample surface |
| 12056 | image_create_info.usage = |
| 12057 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12058 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12059 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12060 | err = |
| 12061 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12062 | ASSERT_VK_SUCCESS(err); |
| 12063 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12064 | // Note: Some implementations expect color attachment usage for any |
| 12065 | // multisample surface |
| 12066 | image_create_info.usage = |
| 12067 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12068 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12069 | err = |
| 12070 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12071 | ASSERT_VK_SUCCESS(err); |
| 12072 | |
| 12073 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12074 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12075 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12076 | memAlloc.pNext = NULL; |
| 12077 | memAlloc.allocationSize = 0; |
| 12078 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12079 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12080 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12081 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12082 | pass = |
| 12083 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12084 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12085 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12086 | ASSERT_VK_SUCCESS(err); |
| 12087 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12088 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12089 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12090 | pass = |
| 12091 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12092 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12093 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12094 | ASSERT_VK_SUCCESS(err); |
| 12095 | |
| 12096 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12097 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12098 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12099 | ASSERT_VK_SUCCESS(err); |
| 12100 | |
| 12101 | BeginCommandBuffer(); |
| 12102 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12103 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12104 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12105 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12106 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12107 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12108 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12109 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12110 | resolveRegion.srcOffset.x = 0; |
| 12111 | resolveRegion.srcOffset.y = 0; |
| 12112 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12113 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12114 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12115 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12116 | resolveRegion.dstSubresource.layerCount = 0; |
| 12117 | resolveRegion.dstOffset.x = 0; |
| 12118 | resolveRegion.dstOffset.y = 0; |
| 12119 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12120 | resolveRegion.extent.width = 1; |
| 12121 | resolveRegion.extent.height = 1; |
| 12122 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12123 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12124 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12125 | EndCommandBuffer(); |
| 12126 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12127 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12128 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12129 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12130 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12131 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12132 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12133 | } |
| 12134 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12135 | TEST_F(VkLayerTest, ResolveImageFormatMismatch) { |
| 12136 | VkResult err; |
| 12137 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12138 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12139 | m_errorMonitor->SetDesiredFailureMsg( |
| 12140 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12141 | "vkCmdResolveImage called with unmatched source and dest formats."); |
| 12142 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12143 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12144 | |
| 12145 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12146 | VkImage srcImage; |
| 12147 | VkImage dstImage; |
| 12148 | VkDeviceMemory srcMem; |
| 12149 | VkDeviceMemory destMem; |
| 12150 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12151 | |
| 12152 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12153 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12154 | image_create_info.pNext = NULL; |
| 12155 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12156 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12157 | image_create_info.extent.width = 32; |
| 12158 | image_create_info.extent.height = 1; |
| 12159 | image_create_info.extent.depth = 1; |
| 12160 | image_create_info.mipLevels = 1; |
| 12161 | image_create_info.arrayLayers = 1; |
| 12162 | image_create_info.samples = VK_SAMPLE_COUNT_2_BIT; |
| 12163 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12164 | // Note: Some implementations expect color attachment usage for any |
| 12165 | // multisample surface |
| 12166 | image_create_info.usage = |
| 12167 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12168 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12169 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12170 | err = |
| 12171 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12172 | ASSERT_VK_SUCCESS(err); |
| 12173 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12174 | // Set format to something other than source image |
| 12175 | image_create_info.format = VK_FORMAT_R32_SFLOAT; |
| 12176 | // Note: Some implementations expect color attachment usage for any |
| 12177 | // multisample surface |
| 12178 | image_create_info.usage = |
| 12179 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12180 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12181 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12182 | err = |
| 12183 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12184 | ASSERT_VK_SUCCESS(err); |
| 12185 | |
| 12186 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12187 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12188 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12189 | memAlloc.pNext = NULL; |
| 12190 | memAlloc.allocationSize = 0; |
| 12191 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12192 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12193 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12194 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12195 | pass = |
| 12196 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12197 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12198 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12199 | ASSERT_VK_SUCCESS(err); |
| 12200 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12201 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12202 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12203 | pass = |
| 12204 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12205 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12206 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12207 | ASSERT_VK_SUCCESS(err); |
| 12208 | |
| 12209 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12210 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12211 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12212 | ASSERT_VK_SUCCESS(err); |
| 12213 | |
| 12214 | BeginCommandBuffer(); |
| 12215 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12216 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12217 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12218 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12219 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12220 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12221 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12222 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12223 | resolveRegion.srcOffset.x = 0; |
| 12224 | resolveRegion.srcOffset.y = 0; |
| 12225 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12226 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12227 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12228 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12229 | resolveRegion.dstSubresource.layerCount = 0; |
| 12230 | resolveRegion.dstOffset.x = 0; |
| 12231 | resolveRegion.dstOffset.y = 0; |
| 12232 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12233 | resolveRegion.extent.width = 1; |
| 12234 | resolveRegion.extent.height = 1; |
| 12235 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12236 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12237 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12238 | EndCommandBuffer(); |
| 12239 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12240 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12241 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12242 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12243 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12244 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12245 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12246 | } |
| 12247 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12248 | TEST_F(VkLayerTest, ResolveImageTypeMismatch) { |
| 12249 | VkResult err; |
| 12250 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12251 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12252 | m_errorMonitor->SetDesiredFailureMsg( |
| 12253 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12254 | "vkCmdResolveImage called with unmatched source and dest image types."); |
| 12255 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12256 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12257 | |
| 12258 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12259 | VkImage srcImage; |
| 12260 | VkImage dstImage; |
| 12261 | VkDeviceMemory srcMem; |
| 12262 | VkDeviceMemory destMem; |
| 12263 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12264 | |
| 12265 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12266 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12267 | image_create_info.pNext = NULL; |
| 12268 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12269 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12270 | image_create_info.extent.width = 32; |
| 12271 | image_create_info.extent.height = 1; |
| 12272 | image_create_info.extent.depth = 1; |
| 12273 | image_create_info.mipLevels = 1; |
| 12274 | image_create_info.arrayLayers = 1; |
| 12275 | image_create_info.samples = VK_SAMPLE_COUNT_2_BIT; |
| 12276 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12277 | // Note: Some implementations expect color attachment usage for any |
| 12278 | // multisample surface |
| 12279 | image_create_info.usage = |
| 12280 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12281 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12282 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12283 | err = |
| 12284 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12285 | ASSERT_VK_SUCCESS(err); |
| 12286 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12287 | image_create_info.imageType = VK_IMAGE_TYPE_1D; |
| 12288 | // Note: Some implementations expect color attachment usage for any |
| 12289 | // multisample surface |
| 12290 | image_create_info.usage = |
| 12291 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12292 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12293 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12294 | err = |
| 12295 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12296 | ASSERT_VK_SUCCESS(err); |
| 12297 | |
| 12298 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12299 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12300 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12301 | memAlloc.pNext = NULL; |
| 12302 | memAlloc.allocationSize = 0; |
| 12303 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12304 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12305 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12306 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12307 | pass = |
| 12308 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12309 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12310 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12311 | ASSERT_VK_SUCCESS(err); |
| 12312 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12313 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12314 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12315 | pass = |
| 12316 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12317 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12318 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12319 | ASSERT_VK_SUCCESS(err); |
| 12320 | |
| 12321 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12322 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12323 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12324 | ASSERT_VK_SUCCESS(err); |
| 12325 | |
| 12326 | BeginCommandBuffer(); |
| 12327 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12328 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12329 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12330 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12331 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12332 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12333 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12334 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12335 | resolveRegion.srcOffset.x = 0; |
| 12336 | resolveRegion.srcOffset.y = 0; |
| 12337 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12338 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12339 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12340 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12341 | resolveRegion.dstSubresource.layerCount = 0; |
| 12342 | resolveRegion.dstOffset.x = 0; |
| 12343 | resolveRegion.dstOffset.y = 0; |
| 12344 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12345 | resolveRegion.extent.width = 1; |
| 12346 | resolveRegion.extent.height = 1; |
| 12347 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12348 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12349 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12350 | EndCommandBuffer(); |
| 12351 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12352 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12353 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12354 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12355 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12356 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12357 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12358 | } |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12359 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12360 | TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) { |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12361 | // 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] | 12362 | // to using a DS format, then cause it to hit error due to COLOR_BIT not |
| 12363 | // set in aspect |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12364 | // The image format check comes 2nd in validation so we trigger it first, |
| 12365 | // 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] | 12366 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12367 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12368 | m_errorMonitor->SetDesiredFailureMsg( |
| 12369 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12370 | "Combination depth/stencil image formats can have only the "); |
| 12371 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12372 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12373 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 12374 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12375 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 12376 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12377 | |
| 12378 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12379 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 12380 | ds_pool_ci.pNext = NULL; |
| 12381 | ds_pool_ci.maxSets = 1; |
| 12382 | ds_pool_ci.poolSizeCount = 1; |
| 12383 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12384 | |
| 12385 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12386 | err = |
| 12387 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12388 | ASSERT_VK_SUCCESS(err); |
| 12389 | |
| 12390 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12391 | dsl_binding.binding = 0; |
| 12392 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 12393 | dsl_binding.descriptorCount = 1; |
| 12394 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 12395 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12396 | |
| 12397 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12398 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 12399 | ds_layout_ci.pNext = NULL; |
| 12400 | ds_layout_ci.bindingCount = 1; |
| 12401 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12402 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12403 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 12404 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12405 | ASSERT_VK_SUCCESS(err); |
| 12406 | |
| 12407 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12408 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 12409 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 12410 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12411 | alloc_info.descriptorPool = ds_pool; |
| 12412 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12413 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 12414 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12415 | ASSERT_VK_SUCCESS(err); |
| 12416 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12417 | VkImage image_bad; |
| 12418 | VkImage image_good; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12419 | // One bad format and one good format for Color attachment |
Tobin Ehlis | 269f032 | 2016-05-25 16:24:21 -0600 | [diff] [blame] | 12420 | const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12421 | const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12422 | const int32_t tex_width = 32; |
| 12423 | const int32_t tex_height = 32; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12424 | |
| 12425 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12426 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12427 | image_create_info.pNext = NULL; |
| 12428 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12429 | image_create_info.format = tex_format_bad; |
| 12430 | image_create_info.extent.width = tex_width; |
| 12431 | image_create_info.extent.height = tex_height; |
| 12432 | image_create_info.extent.depth = 1; |
| 12433 | image_create_info.mipLevels = 1; |
| 12434 | image_create_info.arrayLayers = 1; |
| 12435 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12436 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12437 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | |
| 12438 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 12439 | image_create_info.flags = 0; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12440 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12441 | err = |
| 12442 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12443 | ASSERT_VK_SUCCESS(err); |
| 12444 | image_create_info.format = tex_format_good; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12445 | image_create_info.usage = |
| 12446 | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12447 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, |
| 12448 | &image_good); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12449 | ASSERT_VK_SUCCESS(err); |
| 12450 | |
| 12451 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12452 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12453 | image_view_create_info.image = image_bad; |
| 12454 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 12455 | image_view_create_info.format = tex_format_bad; |
| 12456 | image_view_create_info.subresourceRange.baseArrayLayer = 0; |
| 12457 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 12458 | image_view_create_info.subresourceRange.layerCount = 1; |
| 12459 | image_view_create_info.subresourceRange.levelCount = 1; |
| 12460 | image_view_create_info.subresourceRange.aspectMask = |
| 12461 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12462 | |
| 12463 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12464 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 12465 | &view); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12466 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12467 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12468 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12469 | vkDestroyImage(m_device->device(), image_bad, NULL); |
| 12470 | vkDestroyImage(m_device->device(), image_good, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12471 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 12472 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12473 | } |
Tobin Ehlis | 6e23d77 | 2016-05-19 11:08:34 -0600 | [diff] [blame] | 12474 | |
| 12475 | TEST_F(VkLayerTest, ClearImageErrors) { |
| 12476 | TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and " |
| 12477 | "ClearDepthStencilImage with a color image."); |
| 12478 | |
| 12479 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12480 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 12481 | |
| 12482 | // Renderpass is started here so end it as Clear cmds can't be in renderpass |
| 12483 | BeginCommandBuffer(); |
| 12484 | m_commandBuffer->EndRenderPass(); |
| 12485 | |
| 12486 | // Color image |
| 12487 | VkClearColorValue clear_color; |
| 12488 | memset(clear_color.uint32, 0, sizeof(uint32_t) * 4); |
| 12489 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 12490 | const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12491 | const int32_t img_width = 32; |
| 12492 | const int32_t img_height = 32; |
| 12493 | VkImageCreateInfo image_create_info = {}; |
| 12494 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12495 | image_create_info.pNext = NULL; |
| 12496 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12497 | image_create_info.format = color_format; |
| 12498 | image_create_info.extent.width = img_width; |
| 12499 | image_create_info.extent.height = img_height; |
| 12500 | image_create_info.extent.depth = 1; |
| 12501 | image_create_info.mipLevels = 1; |
| 12502 | image_create_info.arrayLayers = 1; |
| 12503 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12504 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12505 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 12506 | |
| 12507 | vk_testing::Image color_image; |
| 12508 | color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 12509 | reqs); |
| 12510 | |
| 12511 | const VkImageSubresourceRange color_range = |
| 12512 | vk_testing::Image::subresource_range(image_create_info, |
| 12513 | VK_IMAGE_ASPECT_COLOR_BIT); |
| 12514 | |
| 12515 | // Depth/Stencil image |
| 12516 | VkClearDepthStencilValue clear_value = {0}; |
| 12517 | reqs = 0; // don't need HOST_VISIBLE DS image |
| 12518 | VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info(); |
| 12519 | ds_image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12520 | ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 12521 | ds_image_create_info.extent.width = 64; |
| 12522 | ds_image_create_info.extent.height = 64; |
| 12523 | ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12524 | ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 12525 | |
| 12526 | vk_testing::Image ds_image; |
| 12527 | ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, |
| 12528 | reqs); |
| 12529 | |
| 12530 | const VkImageSubresourceRange ds_range = |
| 12531 | vk_testing::Image::subresource_range(ds_image_create_info, |
| 12532 | VK_IMAGE_ASPECT_DEPTH_BIT); |
| 12533 | |
| 12534 | m_errorMonitor->SetDesiredFailureMsg( |
| 12535 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12536 | "vkCmdClearColorImage called with depth/stencil image."); |
| 12537 | |
| 12538 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), |
| 12539 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, |
| 12540 | &color_range); |
| 12541 | |
| 12542 | m_errorMonitor->VerifyFound(); |
| 12543 | |
Tony Barbour | 26434b9 | 2016-06-02 09:43:50 -0600 | [diff] [blame] | 12544 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12545 | "vkCmdClearColorImage called with " |
| 12546 | "image created without " |
| 12547 | "VK_IMAGE_USAGE_TRANSFER_DST_BIT"); |
| 12548 | |
| 12549 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), |
| 12550 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, |
| 12551 | &color_range); |
| 12552 | |
| 12553 | m_errorMonitor->VerifyFound(); |
| 12554 | |
Tobin Ehlis | 6e23d77 | 2016-05-19 11:08:34 -0600 | [diff] [blame] | 12555 | // Call CmdClearDepthStencilImage with color image |
| 12556 | m_errorMonitor->SetDesiredFailureMsg( |
| 12557 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12558 | "vkCmdClearDepthStencilImage called without a depth/stencil image."); |
| 12559 | |
| 12560 | vkCmdClearDepthStencilImage( |
| 12561 | m_commandBuffer->GetBufferHandle(), color_image.handle(), |
| 12562 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, |
| 12563 | &ds_range); |
| 12564 | |
| 12565 | m_errorMonitor->VerifyFound(); |
| 12566 | } |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12567 | #endif // IMAGE_TESTS |
| 12568 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 12569 | int main(int argc, char **argv) { |
| 12570 | int result; |
| 12571 | |
Cody Northrop | 8e54a40 | 2016-03-08 22:25:52 -0700 | [diff] [blame] | 12572 | #ifdef ANDROID |
| 12573 | int vulkanSupport = InitVulkan(); |
| 12574 | if (vulkanSupport == 0) |
| 12575 | return 1; |
| 12576 | #endif |
| 12577 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 12578 | ::testing::InitGoogleTest(&argc, argv); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 12579 | VkTestFramework::InitArgs(&argc, argv); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 12580 | |
| 12581 | ::testing::AddGlobalTestEnvironment(new TestEnvironment); |
| 12582 | |
| 12583 | result = RUN_ALL_TESTS(); |
| 12584 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 12585 | VkTestFramework::Finish(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 12586 | return result; |
| 12587 | } |