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 | 18127d1 | 2016-06-08 16:52:28 +1200 | [diff] [blame] | 2322 | TEST_F(VkLayerTest, CommandBufferSimultaneousUseSync) |
| 2323 | { |
| 2324 | m_errorMonitor->ExpectSuccess(); |
| 2325 | |
| 2326 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2327 | VkResult err; |
| 2328 | |
| 2329 | // Record (empty!) command buffer that can be submitted multiple times |
| 2330 | // simultaneously. |
| 2331 | VkCommandBufferBeginInfo cbbi = { |
| 2332 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, |
| 2333 | VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr |
| 2334 | }; |
| 2335 | m_commandBuffer->BeginCommandBuffer(&cbbi); |
| 2336 | m_commandBuffer->EndCommandBuffer(); |
| 2337 | |
| 2338 | VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 }; |
| 2339 | VkFence fence; |
| 2340 | err = vkCreateFence(m_device->device(), &fci, nullptr, &fence); |
| 2341 | ASSERT_VK_SUCCESS(err); |
| 2342 | |
| 2343 | VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 }; |
| 2344 | VkSemaphore s1, s2; |
| 2345 | err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1); |
| 2346 | ASSERT_VK_SUCCESS(err); |
| 2347 | err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2); |
| 2348 | ASSERT_VK_SUCCESS(err); |
| 2349 | |
| 2350 | // Submit CB once signaling s1, with fence so we can roll forward to its retirement. |
| 2351 | VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, |
| 2352 | 1, &m_commandBuffer->handle(), 1, &s1 }; |
| 2353 | err = vkQueueSubmit(m_device->m_queue, 1, &si, fence); |
| 2354 | ASSERT_VK_SUCCESS(err); |
| 2355 | |
| 2356 | // Submit CB again, signaling s2. |
| 2357 | si.pSignalSemaphores = &s2; |
| 2358 | err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE); |
| 2359 | ASSERT_VK_SUCCESS(err); |
| 2360 | |
| 2361 | // Wait for fence. |
| 2362 | err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 2363 | ASSERT_VK_SUCCESS(err); |
| 2364 | |
| 2365 | // CB is still in flight from second submission, but semaphore s1 is no |
| 2366 | // longer in flight. delete it. |
| 2367 | vkDestroySemaphore(m_device->device(), s1, nullptr); |
| 2368 | |
| 2369 | m_errorMonitor->VerifyNotFound(); |
| 2370 | |
| 2371 | // Force device idle and clean up remaining objects |
| 2372 | vkDeviceWaitIdle(m_device->device()); |
| 2373 | vkDestroySemaphore(m_device->device(), s2, nullptr); |
| 2374 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 2375 | } |
| 2376 | |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2377 | TEST_F(VkLayerTest, InvalidUsageBits) |
| 2378 | { |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2379 | TEST_DESCRIPTION( |
Karl Schultz | b5bc11e | 2016-05-04 08:36:08 -0600 | [diff] [blame] | 2380 | "Specify wrong usage for image then create conflicting view of image " |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2381 | "Initialize buffer with wrong usage then perform copy expecting errors " |
| 2382 | "from both the image and the buffer (2 calls)"); |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2383 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2384 | "Invalid usage flag for image "); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2385 | |
| 2386 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2387 | VkImageObj image(m_device); |
| 2388 | // Initialize image with USAGE_INPUT_ATTACHMENT |
Tobin Ehlis | 8b313c0 | 2016-05-25 15:01:52 -0600 | [diff] [blame] | 2389 | image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, |
Karl Schultz | b5bc11e | 2016-05-04 08:36:08 -0600 | [diff] [blame] | 2390 | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 2391 | ASSERT_TRUE(image.initialized()); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2392 | |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2393 | VkImageView dsv; |
| 2394 | VkImageViewCreateInfo dsvci = {}; |
| 2395 | dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 2396 | dsvci.image = image.handle(); |
| 2397 | dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 2398 | dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT; |
| 2399 | dsvci.subresourceRange.layerCount = 1; |
| 2400 | dsvci.subresourceRange.baseMipLevel = 0; |
| 2401 | dsvci.subresourceRange.levelCount = 1; |
| 2402 | dsvci.subresourceRange.aspectMask = |
| 2403 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2404 | |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2405 | // Create a view with depth / stencil aspect for image with different usage |
| 2406 | vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2407 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2408 | m_errorMonitor->VerifyFound(); |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2409 | |
| 2410 | // Initialize buffer with TRANSFER_DST usage |
| 2411 | vk_testing::Buffer buffer; |
| 2412 | VkMemoryPropertyFlags reqs = 0; |
| 2413 | buffer.init_as_dst(*m_device, 128 * 128, reqs); |
| 2414 | VkBufferImageCopy region = {}; |
| 2415 | region.bufferRowLength = 128; |
| 2416 | region.bufferImageHeight = 128; |
| 2417 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 2418 | region.imageSubresource.layerCount = 1; |
| 2419 | region.imageExtent.height = 16; |
| 2420 | region.imageExtent.width = 16; |
| 2421 | region.imageExtent.depth = 1; |
| 2422 | |
| 2423 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2424 | "Invalid usage flag for buffer "); |
| 2425 | // Buffer usage not set to TRANSFER_SRC and image usage not set to |
| 2426 | // TRANSFER_DST |
| 2427 | BeginCommandBuffer(); |
| 2428 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 2429 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 2430 | 1, ®ion); |
| 2431 | m_errorMonitor->VerifyFound(); |
| 2432 | |
| 2433 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2434 | "Invalid usage flag for image "); |
| 2435 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 2436 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 2437 | 1, ®ion); |
| 2438 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2439 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 2440 | #endif // MEM_TRACKER_TESTS |
| 2441 | |
Tobin Ehlis | 4bf96d1 | 2015-06-25 11:58:41 -0600 | [diff] [blame] | 2442 | #if OBJ_TRACKER_TESTS |
Mark Lobodzinski | fc5cc66 | 2016-05-02 17:17:41 -0600 | [diff] [blame] | 2443 | |
| 2444 | TEST_F(VkLayerTest, LeakAnObject) { |
| 2445 | VkResult err; |
| 2446 | |
| 2447 | TEST_DESCRIPTION( |
| 2448 | "Create a fence and destroy its device without first destroying the fence."); |
| 2449 | |
| 2450 | // Note that we have to create a new device since destroying the |
| 2451 | // framework's device causes Teardown() to fail and just calling Teardown |
| 2452 | // will destroy the errorMonitor. |
| 2453 | |
| 2454 | m_errorMonitor->SetDesiredFailureMsg( |
| 2455 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2456 | "OBJ ERROR : VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT object"); |
| 2457 | |
| 2458 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2459 | |
| 2460 | const std::vector<VkQueueFamilyProperties> queue_props = |
| 2461 | m_device->queue_props; |
| 2462 | std::vector<VkDeviceQueueCreateInfo> queue_info; |
| 2463 | queue_info.reserve(queue_props.size()); |
| 2464 | std::vector<std::vector<float>> queue_priorities; |
| 2465 | for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) { |
| 2466 | VkDeviceQueueCreateInfo qi = {}; |
| 2467 | qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; |
| 2468 | qi.pNext = NULL; |
| 2469 | qi.queueFamilyIndex = i; |
| 2470 | qi.queueCount = queue_props[i].queueCount; |
| 2471 | queue_priorities.emplace_back(qi.queueCount, 0.0f); |
| 2472 | qi.pQueuePriorities = queue_priorities[i].data(); |
| 2473 | queue_info.push_back(qi); |
| 2474 | } |
| 2475 | |
| 2476 | std::vector<const char *> device_layer_names; |
| 2477 | std::vector<const char *> device_extension_names; |
| 2478 | device_layer_names.push_back("VK_LAYER_GOOGLE_threading"); |
| 2479 | device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation"); |
| 2480 | device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker"); |
| 2481 | device_layer_names.push_back("VK_LAYER_LUNARG_core_validation"); |
| 2482 | device_layer_names.push_back("VK_LAYER_LUNARG_device_limits"); |
| 2483 | device_layer_names.push_back("VK_LAYER_LUNARG_image"); |
| 2484 | device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects"); |
| 2485 | |
| 2486 | // The sacrificial device object |
| 2487 | VkDevice testDevice; |
| 2488 | VkDeviceCreateInfo device_create_info = {}; |
| 2489 | auto features = m_device->phy().features(); |
| 2490 | device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; |
| 2491 | device_create_info.pNext = NULL; |
| 2492 | device_create_info.queueCreateInfoCount = queue_info.size(); |
| 2493 | device_create_info.pQueueCreateInfos = queue_info.data(); |
| 2494 | device_create_info.enabledLayerCount = device_layer_names.size(); |
| 2495 | device_create_info.ppEnabledLayerNames = device_layer_names.data(); |
| 2496 | device_create_info.pEnabledFeatures = &features; |
| 2497 | err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice); |
| 2498 | ASSERT_VK_SUCCESS(err); |
| 2499 | |
| 2500 | VkFence fence; |
| 2501 | VkFenceCreateInfo fence_create_info = {}; |
| 2502 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 2503 | fence_create_info.pNext = NULL; |
| 2504 | fence_create_info.flags = 0; |
| 2505 | err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence); |
| 2506 | ASSERT_VK_SUCCESS(err); |
| 2507 | |
| 2508 | // Induce failure by not calling vkDestroyFence |
| 2509 | vkDestroyDevice(testDevice, NULL); |
| 2510 | m_errorMonitor->VerifyFound(); |
| 2511 | } |
| 2512 | |
| 2513 | TEST_F(VkLayerTest, InvalidCommandPoolConsistency) { |
| 2514 | |
| 2515 | TEST_DESCRIPTION("Allocate command buffers from one command pool and " |
| 2516 | "attempt to delete them from another."); |
| 2517 | |
| 2518 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2519 | "FreeCommandBuffers is attempting to free Command Buffer"); |
| 2520 | |
| 2521 | VkCommandPool command_pool_one; |
| 2522 | VkCommandPool command_pool_two; |
| 2523 | |
| 2524 | VkCommandPoolCreateInfo pool_create_info{}; |
| 2525 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 2526 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 2527 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 2528 | |
| 2529 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 2530 | &command_pool_one); |
| 2531 | |
| 2532 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 2533 | &command_pool_two); |
| 2534 | |
| 2535 | VkCommandBuffer command_buffer[9]; |
| 2536 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 2537 | command_buffer_allocate_info.sType = |
| 2538 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 2539 | command_buffer_allocate_info.commandPool = command_pool_one; |
| 2540 | command_buffer_allocate_info.commandBufferCount = 9; |
| 2541 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 2542 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 2543 | command_buffer); |
| 2544 | |
| 2545 | vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, |
| 2546 | &command_buffer[3]); |
| 2547 | |
| 2548 | m_errorMonitor->VerifyFound(); |
| 2549 | |
| 2550 | vkDestroyCommandPool(m_device->device(), command_pool_one, NULL); |
| 2551 | vkDestroyCommandPool(m_device->device(), command_pool_two, NULL); |
| 2552 | } |
| 2553 | |
| 2554 | TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) { |
| 2555 | VkResult err; |
| 2556 | |
| 2557 | TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and " |
| 2558 | "attempt to delete them from another."); |
| 2559 | |
| 2560 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2561 | "FreeDescriptorSets is attempting to free descriptorSet"); |
| 2562 | |
| 2563 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2564 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 2565 | |
| 2566 | VkDescriptorPoolSize ds_type_count = {}; |
| 2567 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 2568 | ds_type_count.descriptorCount = 1; |
| 2569 | |
| 2570 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 2571 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 2572 | ds_pool_ci.pNext = NULL; |
| 2573 | ds_pool_ci.flags = 0; |
| 2574 | ds_pool_ci.maxSets = 1; |
| 2575 | ds_pool_ci.poolSizeCount = 1; |
| 2576 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 2577 | |
| 2578 | VkDescriptorPool ds_pool_one; |
| 2579 | err = |
| 2580 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one); |
| 2581 | ASSERT_VK_SUCCESS(err); |
| 2582 | |
| 2583 | // Create a second descriptor pool |
| 2584 | VkDescriptorPool ds_pool_two; |
| 2585 | err = |
| 2586 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two); |
| 2587 | ASSERT_VK_SUCCESS(err); |
| 2588 | |
| 2589 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 2590 | dsl_binding.binding = 0; |
| 2591 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 2592 | dsl_binding.descriptorCount = 1; |
| 2593 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 2594 | dsl_binding.pImmutableSamplers = NULL; |
| 2595 | |
| 2596 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 2597 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 2598 | ds_layout_ci.pNext = NULL; |
| 2599 | ds_layout_ci.bindingCount = 1; |
| 2600 | ds_layout_ci.pBindings = &dsl_binding; |
| 2601 | |
| 2602 | VkDescriptorSetLayout ds_layout; |
| 2603 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 2604 | &ds_layout); |
| 2605 | ASSERT_VK_SUCCESS(err); |
| 2606 | |
| 2607 | VkDescriptorSet descriptorSet; |
| 2608 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 2609 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 2610 | alloc_info.descriptorSetCount = 1; |
| 2611 | alloc_info.descriptorPool = ds_pool_one; |
| 2612 | alloc_info.pSetLayouts = &ds_layout; |
| 2613 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 2614 | &descriptorSet); |
| 2615 | ASSERT_VK_SUCCESS(err); |
| 2616 | |
| 2617 | err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet); |
| 2618 | |
| 2619 | m_errorMonitor->VerifyFound(); |
| 2620 | |
| 2621 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 2622 | vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL); |
| 2623 | vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL); |
| 2624 | } |
| 2625 | |
| 2626 | TEST_F(VkLayerTest, CreateUnknownObject) { |
| 2627 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2628 | "Invalid VkImage Object "); |
| 2629 | |
| 2630 | TEST_DESCRIPTION( |
| 2631 | "Pass an invalid image object handle into a Vulkan API call."); |
| 2632 | |
| 2633 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2634 | |
| 2635 | // Pass bogus handle into GetImageMemoryRequirements |
| 2636 | VkMemoryRequirements mem_reqs; |
| 2637 | uint64_t fakeImageHandle = 0xCADECADE; |
| 2638 | VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle); |
| 2639 | |
| 2640 | vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs); |
| 2641 | |
| 2642 | m_errorMonitor->VerifyFound(); |
| 2643 | } |
| 2644 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2645 | TEST_F(VkLayerTest, PipelineNotBound) { |
| 2646 | VkResult err; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2647 | |
Mark Lobodzinski | fc5cc66 | 2016-05-02 17:17:41 -0600 | [diff] [blame] | 2648 | TEST_DESCRIPTION( |
| 2649 | "Pass in an invalid pipeline object handle into a Vulkan API call."); |
| 2650 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2651 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2652 | "Invalid VkPipeline Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2653 | |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2654 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2655 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2656 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 2657 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2658 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 2659 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2660 | |
| 2661 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2662 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 2663 | ds_pool_ci.pNext = NULL; |
| 2664 | ds_pool_ci.maxSets = 1; |
| 2665 | ds_pool_ci.poolSizeCount = 1; |
| 2666 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2667 | |
| 2668 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2669 | err = |
| 2670 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2671 | ASSERT_VK_SUCCESS(err); |
| 2672 | |
| 2673 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2674 | dsl_binding.binding = 0; |
| 2675 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 2676 | dsl_binding.descriptorCount = 1; |
| 2677 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 2678 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2679 | |
| 2680 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2681 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 2682 | ds_layout_ci.pNext = NULL; |
| 2683 | ds_layout_ci.bindingCount = 1; |
| 2684 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2685 | |
| 2686 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2687 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 2688 | &ds_layout); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2689 | ASSERT_VK_SUCCESS(err); |
| 2690 | |
| 2691 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2692 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 2693 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 2694 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 2695 | alloc_info.descriptorPool = ds_pool; |
| 2696 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2697 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 2698 | &descriptorSet); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2699 | ASSERT_VK_SUCCESS(err); |
| 2700 | |
| 2701 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2702 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 2703 | pipeline_layout_ci.pNext = NULL; |
| 2704 | pipeline_layout_ci.setLayoutCount = 1; |
| 2705 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2706 | |
| 2707 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2708 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 2709 | &pipeline_layout); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2710 | ASSERT_VK_SUCCESS(err); |
| 2711 | |
Mark Young | ad77905 | 2016-01-06 14:26:04 -0700 | [diff] [blame] | 2712 | VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2713 | |
| 2714 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2715 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 2716 | VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2717 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2718 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2719 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2720 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 2721 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 2722 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2723 | } |
Tobin Ehlis | 93d57e1 | 2016-06-20 11:32:13 -0600 | [diff] [blame] | 2724 | #if 0 // Disabling this test for now, needs to be updated |
Mark Lobodzinski | bc18576 | 2016-06-15 16:28:53 -0600 | [diff] [blame] | 2725 | TEST_F(VkLayerTest, BindImageInvalidMemoryType) { |
| 2726 | VkResult err; |
| 2727 | |
| 2728 | TEST_DESCRIPTION("Test validation check for an invalid memory type index " |
| 2729 | "during bind[Buffer|Image]Memory time"); |
| 2730 | |
| 2731 | m_errorMonitor->SetDesiredFailureMsg( |
| 2732 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2733 | "for this object type are not compatible with the memory"); |
| 2734 | |
| 2735 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2736 | |
| 2737 | // Create an image, allocate memory, set a bad typeIndex and then try to |
| 2738 | // bind it |
| 2739 | VkImage image; |
| 2740 | VkDeviceMemory mem; |
| 2741 | VkMemoryRequirements mem_reqs; |
| 2742 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2743 | const int32_t tex_width = 32; |
| 2744 | const int32_t tex_height = 32; |
| 2745 | |
| 2746 | VkImageCreateInfo image_create_info = {}; |
| 2747 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2748 | image_create_info.pNext = NULL; |
| 2749 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2750 | image_create_info.format = tex_format; |
| 2751 | image_create_info.extent.width = tex_width; |
| 2752 | image_create_info.extent.height = tex_height; |
| 2753 | image_create_info.extent.depth = 1; |
| 2754 | image_create_info.mipLevels = 1; |
| 2755 | image_create_info.arrayLayers = 1; |
| 2756 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2757 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 2758 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2759 | image_create_info.flags = 0; |
| 2760 | |
| 2761 | VkMemoryAllocateInfo mem_alloc = {}; |
| 2762 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2763 | mem_alloc.pNext = NULL; |
| 2764 | mem_alloc.allocationSize = 0; |
| 2765 | mem_alloc.memoryTypeIndex = 0; |
| 2766 | |
| 2767 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 2768 | ASSERT_VK_SUCCESS(err); |
| 2769 | |
| 2770 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 2771 | mem_alloc.allocationSize = mem_reqs.size; |
Tobin Ehlis | 93d57e1 | 2016-06-20 11:32:13 -0600 | [diff] [blame] | 2772 | // TODO : This is not an ideal way to cause the error and triggers a segF |
| 2773 | // on at least one android driver when attempting to Allocate the memory. |
| 2774 | // That segF may or may not be a driver bug, but really what we want to do |
| 2775 | // here is find a device-supported memory type that is also not supported |
| 2776 | // for the particular image we're binding the memory too. If no such |
| 2777 | // type exists, then we can print a message and skip the test. |
Mark Lobodzinski | bc18576 | 2016-06-15 16:28:53 -0600 | [diff] [blame] | 2778 | // Introduce Failure, select likely invalid TypeIndex |
| 2779 | mem_alloc.memoryTypeIndex = 31; |
| 2780 | |
| 2781 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 2782 | ASSERT_VK_SUCCESS(err); |
| 2783 | |
| 2784 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 2785 | (void)err; |
| 2786 | |
| 2787 | m_errorMonitor->VerifyFound(); |
| 2788 | |
| 2789 | vkDestroyImage(m_device->device(), image, NULL); |
| 2790 | vkFreeMemory(m_device->device(), mem, NULL); |
| 2791 | } |
Tobin Ehlis | 93d57e1 | 2016-06-20 11:32:13 -0600 | [diff] [blame] | 2792 | #endif |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2793 | TEST_F(VkLayerTest, BindInvalidMemory) { |
| 2794 | VkResult err; |
| 2795 | bool pass; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2796 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2797 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2798 | "Invalid VkDeviceMemory Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2799 | |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2800 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2801 | |
| 2802 | // 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] | 2803 | VkImage image; |
| 2804 | VkDeviceMemory mem; |
| 2805 | VkMemoryRequirements mem_reqs; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2806 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2807 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2808 | const int32_t tex_width = 32; |
| 2809 | const int32_t tex_height = 32; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2810 | |
| 2811 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2812 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2813 | image_create_info.pNext = NULL; |
| 2814 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2815 | image_create_info.format = tex_format; |
| 2816 | image_create_info.extent.width = tex_width; |
| 2817 | image_create_info.extent.height = tex_height; |
| 2818 | image_create_info.extent.depth = 1; |
| 2819 | image_create_info.mipLevels = 1; |
| 2820 | image_create_info.arrayLayers = 1; |
| 2821 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2822 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2823 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2824 | image_create_info.flags = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2825 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2826 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2827 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2828 | mem_alloc.pNext = NULL; |
| 2829 | mem_alloc.allocationSize = 0; |
| 2830 | mem_alloc.memoryTypeIndex = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2831 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2832 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2833 | ASSERT_VK_SUCCESS(err); |
| 2834 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2835 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2836 | |
| 2837 | mem_alloc.allocationSize = mem_reqs.size; |
| 2838 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2839 | pass = |
| 2840 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 2841 | ASSERT_TRUE(pass); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2842 | |
| 2843 | // allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2844 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2845 | ASSERT_VK_SUCCESS(err); |
| 2846 | |
| 2847 | // Introduce validation failure, free memory before binding |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2848 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2849 | |
| 2850 | // Try to bind free memory that has been freed |
| 2851 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 2852 | // This may very well return an error. |
| 2853 | (void)err; |
| 2854 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2855 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2856 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2857 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2858 | } |
| 2859 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2860 | TEST_F(VkLayerTest, BindMemoryToDestroyedObject) { |
| 2861 | VkResult err; |
| 2862 | bool pass; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2863 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2864 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2865 | "Invalid VkImage Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2866 | |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2867 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2868 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2869 | // Create an image object, allocate memory, destroy the object and then try |
| 2870 | // to bind it |
| 2871 | VkImage image; |
| 2872 | VkDeviceMemory mem; |
| 2873 | VkMemoryRequirements mem_reqs; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2874 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2875 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2876 | const int32_t tex_width = 32; |
| 2877 | const int32_t tex_height = 32; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2878 | |
| 2879 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2880 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2881 | image_create_info.pNext = NULL; |
| 2882 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2883 | image_create_info.format = tex_format; |
| 2884 | image_create_info.extent.width = tex_width; |
| 2885 | image_create_info.extent.height = tex_height; |
| 2886 | image_create_info.extent.depth = 1; |
| 2887 | image_create_info.mipLevels = 1; |
| 2888 | image_create_info.arrayLayers = 1; |
| 2889 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2890 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2891 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2892 | image_create_info.flags = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2893 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2894 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2895 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2896 | mem_alloc.pNext = NULL; |
| 2897 | mem_alloc.allocationSize = 0; |
| 2898 | mem_alloc.memoryTypeIndex = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2899 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2900 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2901 | ASSERT_VK_SUCCESS(err); |
| 2902 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2903 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2904 | |
| 2905 | mem_alloc.allocationSize = mem_reqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2906 | pass = |
| 2907 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 2908 | ASSERT_TRUE(pass); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2909 | |
| 2910 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2911 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2912 | ASSERT_VK_SUCCESS(err); |
| 2913 | |
| 2914 | // Introduce validation failure, destroy Image object before binding |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2915 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2916 | ASSERT_VK_SUCCESS(err); |
| 2917 | |
| 2918 | // Now Try to bind memory to this destroyed object |
| 2919 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 2920 | // This may very well return an error. |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2921 | (void)err; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2922 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2923 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2924 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2925 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2926 | } |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 2927 | |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 2928 | #endif // OBJ_TRACKER_TESTS |
| 2929 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 2930 | #if DRAW_STATE_TESTS |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 2931 | |
Mark Lobodzinski | ce7eee7 | 2016-06-14 16:33:29 -0600 | [diff] [blame] | 2932 | // This is a positive test. No errors are expected. |
| 2933 | TEST_F(VkLayerTest, StencilLoadOp) { |
| 2934 | TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to " |
| 2935 | "CLEAR. stencil[Load|Store]Op used to be ignored."); |
| 2936 | VkResult result = VK_SUCCESS; |
| 2937 | VkImageFormatProperties formatProps; |
| 2938 | vkGetPhysicalDeviceImageFormatProperties( |
| 2939 | gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, |
| 2940 | VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 2941 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, |
| 2942 | 0, &formatProps); |
| 2943 | if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) { |
| 2944 | return; |
| 2945 | } |
| 2946 | |
| 2947 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2948 | VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT; |
| 2949 | m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt, |
| 2950 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 2951 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT); |
| 2952 | VkAttachmentDescription att = {}; |
| 2953 | VkAttachmentReference ref = {}; |
| 2954 | att.format = depth_stencil_fmt; |
| 2955 | att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 2956 | att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 2957 | att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 2958 | att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE; |
| 2959 | att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 2960 | att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 2961 | |
| 2962 | VkClearValue clear; |
| 2963 | clear.depthStencil.depth = 1.0; |
| 2964 | clear.depthStencil.stencil = 0; |
| 2965 | ref.attachment = 0; |
| 2966 | ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 2967 | |
| 2968 | VkSubpassDescription subpass = {}; |
| 2969 | subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; |
| 2970 | subpass.flags = 0; |
| 2971 | subpass.inputAttachmentCount = 0; |
| 2972 | subpass.pInputAttachments = NULL; |
| 2973 | subpass.colorAttachmentCount = 0; |
| 2974 | subpass.pColorAttachments = NULL; |
| 2975 | subpass.pResolveAttachments = NULL; |
| 2976 | subpass.pDepthStencilAttachment = &ref; |
| 2977 | subpass.preserveAttachmentCount = 0; |
| 2978 | subpass.pPreserveAttachments = NULL; |
| 2979 | |
| 2980 | VkRenderPass rp; |
| 2981 | VkRenderPassCreateInfo rp_info = {}; |
| 2982 | rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 2983 | rp_info.attachmentCount = 1; |
| 2984 | rp_info.pAttachments = &att; |
| 2985 | rp_info.subpassCount = 1; |
| 2986 | rp_info.pSubpasses = &subpass; |
| 2987 | result = vkCreateRenderPass(device(), &rp_info, NULL, &rp); |
| 2988 | ASSERT_VK_SUCCESS(result); |
| 2989 | |
| 2990 | VkImageView *depthView = m_depthStencil->BindInfo(); |
| 2991 | VkFramebufferCreateInfo fb_info = {}; |
| 2992 | fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
| 2993 | fb_info.pNext = NULL; |
| 2994 | fb_info.renderPass = rp; |
| 2995 | fb_info.attachmentCount = 1; |
| 2996 | fb_info.pAttachments = depthView; |
| 2997 | fb_info.width = 100; |
| 2998 | fb_info.height = 100; |
| 2999 | fb_info.layers = 1; |
| 3000 | VkFramebuffer fb; |
| 3001 | result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3002 | ASSERT_VK_SUCCESS(result); |
| 3003 | |
| 3004 | |
| 3005 | VkRenderPassBeginInfo rpbinfo = {}; |
| 3006 | rpbinfo.clearValueCount = 1; |
| 3007 | rpbinfo.pClearValues = &clear; |
| 3008 | rpbinfo.pNext = NULL; |
| 3009 | rpbinfo.renderPass = rp; |
| 3010 | rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 3011 | rpbinfo.renderArea.extent.width = 100; |
| 3012 | rpbinfo.renderArea.extent.height = 100; |
| 3013 | rpbinfo.renderArea.offset.x = 0; |
| 3014 | rpbinfo.renderArea.offset.y = 0; |
| 3015 | rpbinfo.framebuffer = fb; |
| 3016 | |
| 3017 | VkFence fence = {}; |
| 3018 | VkFenceCreateInfo fence_ci = {}; |
| 3019 | fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3020 | fence_ci.pNext = nullptr; |
| 3021 | fence_ci.flags = 0; |
| 3022 | result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence); |
| 3023 | ASSERT_VK_SUCCESS(result); |
| 3024 | |
| 3025 | |
| 3026 | m_commandBuffer->BeginCommandBuffer(); |
| 3027 | m_commandBuffer->BeginRenderPass(rpbinfo); |
| 3028 | m_commandBuffer->EndRenderPass(); |
| 3029 | m_commandBuffer->EndCommandBuffer(); |
| 3030 | m_commandBuffer->QueueCommandBuffer(fence); |
| 3031 | |
| 3032 | VkImageObj destImage(m_device); |
| 3033 | destImage.init(100, 100, depth_stencil_fmt, |
| 3034 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 3035 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 3036 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 3037 | VkImageMemoryBarrier barrier = {}; |
| 3038 | VkImageSubresourceRange range; |
| 3039 | barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 3040 | barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | |
| 3041 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; |
| 3042 | barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | |
| 3043 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT; |
| 3044 | barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 3045 | barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 3046 | barrier.image = m_depthStencil->handle(); |
| 3047 | range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3048 | range.baseMipLevel = 0; |
| 3049 | range.levelCount = 1; |
| 3050 | range.baseArrayLayer = 0; |
| 3051 | range.layerCount = 1; |
| 3052 | barrier.subresourceRange = range; |
| 3053 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 3054 | VkCommandBufferObj cmdbuf(m_device, m_commandPool); |
| 3055 | cmdbuf.BeginCommandBuffer(); |
| 3056 | cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3057 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, |
| 3058 | nullptr, 1, &barrier); |
| 3059 | barrier.srcAccessMask = 0; |
| 3060 | barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 3061 | barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; |
| 3062 | barrier.image = destImage.handle(); |
| 3063 | barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | |
| 3064 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; |
| 3065 | cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3066 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, |
| 3067 | nullptr, 1, &barrier); |
| 3068 | VkImageCopy cregion; |
| 3069 | cregion.srcSubresource.aspectMask = |
| 3070 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3071 | cregion.srcSubresource.mipLevel = 0; |
| 3072 | cregion.srcSubresource.baseArrayLayer = 0; |
| 3073 | cregion.srcSubresource.layerCount = 1; |
| 3074 | cregion.srcOffset.x = 0; |
| 3075 | cregion.srcOffset.y = 0; |
| 3076 | cregion.srcOffset.z = 0; |
| 3077 | cregion.dstSubresource.aspectMask = |
| 3078 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 3079 | cregion.dstSubresource.mipLevel = 0; |
| 3080 | cregion.dstSubresource.baseArrayLayer = 0; |
| 3081 | cregion.dstSubresource.layerCount = 1; |
| 3082 | cregion.dstOffset.x = 0; |
| 3083 | cregion.dstOffset.y = 0; |
| 3084 | cregion.dstOffset.z = 0; |
| 3085 | cregion.extent.width = 100; |
| 3086 | cregion.extent.height = 100; |
| 3087 | cregion.extent.depth = 1; |
| 3088 | cmdbuf.CopyImage(m_depthStencil->handle(), |
| 3089 | VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(), |
| 3090 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion); |
| 3091 | cmdbuf.EndCommandBuffer(); |
| 3092 | |
| 3093 | VkSubmitInfo submit_info; |
| 3094 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3095 | submit_info.pNext = NULL; |
| 3096 | submit_info.waitSemaphoreCount = 0; |
| 3097 | submit_info.pWaitSemaphores = NULL; |
| 3098 | submit_info.pWaitDstStageMask = NULL; |
| 3099 | submit_info.commandBufferCount = 1; |
| 3100 | submit_info.pCommandBuffers = &cmdbuf.handle(); |
| 3101 | submit_info.signalSemaphoreCount = 0; |
| 3102 | submit_info.pSignalSemaphores = NULL; |
| 3103 | |
| 3104 | m_errorMonitor->ExpectSuccess(); |
| 3105 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3106 | m_errorMonitor->VerifyNotFound(); |
| 3107 | |
Mark Lobodzinski | d0440da | 2016-06-17 15:10:03 -0600 | [diff] [blame] | 3108 | vkQueueWaitIdle(m_device->m_queue); |
Mark Lobodzinski | ce7eee7 | 2016-06-14 16:33:29 -0600 | [diff] [blame] | 3109 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 3110 | vkDestroyRenderPass(m_device->device(), rp, nullptr); |
| 3111 | vkDestroyFramebuffer(m_device->device(), fb, nullptr); |
| 3112 | } |
| 3113 | |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3114 | TEST_F(VkLayerTest, UnusedPreserveAttachment) { |
| 3115 | TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve " |
| 3116 | "attachment reference of VK_ATTACHMENT_UNUSED"); |
| 3117 | |
| 3118 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3119 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 3120 | |
| 3121 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3122 | "must not be VK_ATTACHMENT_UNUSED"); |
| 3123 | |
| 3124 | VkAttachmentReference color_attach = {}; |
| 3125 | color_attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 3126 | color_attach.attachment = 0; |
| 3127 | uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED; |
| 3128 | VkSubpassDescription subpass = {}; |
| 3129 | subpass.colorAttachmentCount = 1; |
| 3130 | subpass.pColorAttachments = &color_attach; |
| 3131 | subpass.preserveAttachmentCount = 1; |
| 3132 | subpass.pPreserveAttachments = &preserve_attachment; |
| 3133 | |
| 3134 | VkRenderPassCreateInfo rpci = {}; |
| 3135 | rpci.subpassCount = 1; |
| 3136 | rpci.pSubpasses = &subpass; |
| 3137 | rpci.attachmentCount = 1; |
| 3138 | VkAttachmentDescription attach_desc = {}; |
| 3139 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 3140 | rpci.pAttachments = &attach_desc; |
| 3141 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 3142 | VkRenderPass rp; |
Mark Lobodzinski | a4feeeb | 2016-06-17 12:00:46 -0600 | [diff] [blame] | 3143 | VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3144 | |
| 3145 | m_errorMonitor->VerifyFound(); |
| 3146 | |
Mark Lobodzinski | a4feeeb | 2016-06-17 12:00:46 -0600 | [diff] [blame] | 3147 | if (result == VK_SUCCESS) { |
| 3148 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 3149 | } |
Mark Lobodzinski | 6d17b9f | 2016-06-16 13:21:38 -0600 | [diff] [blame] | 3150 | } |
| 3151 | |
| 3152 | TEST_F(VkLayerTest, AttachmentUsageMismatch) { |
| 3153 | TEST_DESCRIPTION("Create a framebuffer where a subpass uses a color image " |
| 3154 | "in the depthStencil attachment point"); |
| 3155 | |
| 3156 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3157 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 3158 | |
| 3159 | m_errorMonitor->SetDesiredFailureMsg( |
| 3160 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3161 | "conflicts with the image's IMAGE_USAGE flags"); |
| 3162 | |
| 3163 | // Create a renderPass with a depth-stencil attachment created with |
| 3164 | // IMAGE_USAGE_COLOR_ATTACHMENT |
| 3165 | VkAttachmentReference attach = {}; |
| 3166 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 3167 | VkSubpassDescription subpass = {}; |
| 3168 | // Add our color attachment to pDepthStencilAttachment |
| 3169 | subpass.pDepthStencilAttachment = &attach; |
| 3170 | VkRenderPassCreateInfo rpci = {}; |
| 3171 | rpci.subpassCount = 1; |
| 3172 | rpci.pSubpasses = &subpass; |
| 3173 | rpci.attachmentCount = 1; |
| 3174 | VkAttachmentDescription attach_desc = {}; |
| 3175 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 3176 | rpci.pAttachments = &attach_desc; |
| 3177 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 3178 | VkRenderPass rp; |
| 3179 | VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 3180 | ASSERT_VK_SUCCESS(err); |
| 3181 | |
| 3182 | VkImageView imageView = |
| 3183 | m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM); |
| 3184 | VkFramebufferCreateInfo fb_info = {}; |
| 3185 | fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
| 3186 | fb_info.pNext = NULL; |
| 3187 | fb_info.renderPass = rp; |
| 3188 | fb_info.attachmentCount = 1; |
| 3189 | fb_info.pAttachments = &imageView; |
| 3190 | fb_info.width = 100; |
| 3191 | fb_info.height = 100; |
| 3192 | fb_info.layers = 1; |
| 3193 | |
| 3194 | VkFramebuffer fb; |
| 3195 | err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb); |
| 3196 | |
| 3197 | m_errorMonitor->VerifyFound(); |
| 3198 | |
| 3199 | if (err == VK_SUCCESS) { |
| 3200 | vkDestroyFramebuffer(m_device->device(), fb, NULL); |
| 3201 | } |
| 3202 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 3203 | } |
| 3204 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3205 | // This is a positive test. No errors should be generated. |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3206 | TEST_F(VkLayerTest, WaitEventThenSet) { |
| 3207 | TEST_DESCRIPTION( |
| 3208 | "Wait on a event then set it after the wait has been submitted."); |
| 3209 | |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3210 | m_errorMonitor->ExpectSuccess(); |
| 3211 | |
| 3212 | VkEvent event; |
| 3213 | VkEventCreateInfo event_create_info{}; |
| 3214 | event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 3215 | vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event); |
| 3216 | |
| 3217 | VkCommandPool command_pool; |
| 3218 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3219 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3220 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3221 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3222 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3223 | &command_pool); |
| 3224 | |
| 3225 | VkCommandBuffer command_buffer; |
| 3226 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3227 | command_buffer_allocate_info.sType = |
| 3228 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3229 | command_buffer_allocate_info.commandPool = command_pool; |
| 3230 | command_buffer_allocate_info.commandBufferCount = 1; |
| 3231 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3232 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3233 | &command_buffer); |
| 3234 | |
| 3235 | VkQueue queue = VK_NULL_HANDLE; |
| 3236 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
Tony Barbour | fe302c0 | 2016-06-06 13:05:19 -0600 | [diff] [blame] | 3237 | 0, &queue); |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3238 | |
| 3239 | { |
| 3240 | VkCommandBufferBeginInfo begin_info{}; |
| 3241 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3242 | vkBeginCommandBuffer(command_buffer, &begin_info); |
| 3243 | |
| 3244 | vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, |
| 3245 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, |
| 3246 | nullptr, 0, nullptr); |
| 3247 | vkCmdResetEvent(command_buffer, event, |
| 3248 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 3249 | vkEndCommandBuffer(command_buffer); |
| 3250 | } |
| 3251 | { |
| 3252 | VkSubmitInfo submit_info{}; |
| 3253 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3254 | submit_info.commandBufferCount = 1; |
| 3255 | submit_info.pCommandBuffers = &command_buffer; |
| 3256 | submit_info.signalSemaphoreCount = 0; |
| 3257 | submit_info.pSignalSemaphores = nullptr; |
| 3258 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3259 | } |
| 3260 | { vkSetEvent(m_device->device(), event); } |
| 3261 | |
| 3262 | vkQueueWaitIdle(queue); |
| 3263 | |
| 3264 | vkDestroyEvent(m_device->device(), event, nullptr); |
| 3265 | vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer); |
| 3266 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3267 | |
| 3268 | m_errorMonitor->VerifyNotFound(); |
| 3269 | } |
Michael Lentine | 5627e69 | 2016-05-20 17:45:02 -0500 | [diff] [blame] | 3270 | // This is a positive test. No errors should be generated. |
| 3271 | TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) { |
| 3272 | TEST_DESCRIPTION( |
| 3273 | "Issue a query and copy from it on a second command buffer."); |
| 3274 | |
| 3275 | if ((m_device->queue_props.empty()) || |
| 3276 | (m_device->queue_props[0].queueCount < 2)) |
| 3277 | return; |
| 3278 | |
| 3279 | m_errorMonitor->ExpectSuccess(); |
| 3280 | |
| 3281 | VkQueryPool query_pool; |
| 3282 | VkQueryPoolCreateInfo query_pool_create_info{}; |
| 3283 | query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; |
| 3284 | query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP; |
| 3285 | query_pool_create_info.queryCount = 1; |
| 3286 | vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, |
| 3287 | &query_pool); |
| 3288 | |
| 3289 | VkCommandPool command_pool; |
| 3290 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3291 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3292 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3293 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3294 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3295 | &command_pool); |
| 3296 | |
| 3297 | VkCommandBuffer command_buffer[2]; |
| 3298 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3299 | command_buffer_allocate_info.sType = |
| 3300 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3301 | command_buffer_allocate_info.commandPool = command_pool; |
| 3302 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3303 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3304 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3305 | command_buffer); |
| 3306 | |
| 3307 | VkQueue queue = VK_NULL_HANDLE; |
| 3308 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3309 | 1, &queue); |
| 3310 | |
| 3311 | uint32_t qfi = 0; |
| 3312 | VkBufferCreateInfo buff_create_info = {}; |
| 3313 | buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 3314 | buff_create_info.size = 1024; |
| 3315 | buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT; |
| 3316 | buff_create_info.queueFamilyIndexCount = 1; |
| 3317 | buff_create_info.pQueueFamilyIndices = &qfi; |
| 3318 | |
| 3319 | VkResult err; |
| 3320 | VkBuffer buffer; |
| 3321 | err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer); |
| 3322 | ASSERT_VK_SUCCESS(err); |
| 3323 | VkMemoryAllocateInfo mem_alloc = {}; |
| 3324 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 3325 | mem_alloc.pNext = NULL; |
| 3326 | mem_alloc.allocationSize = 1024; |
| 3327 | mem_alloc.memoryTypeIndex = 0; |
| 3328 | |
| 3329 | VkMemoryRequirements memReqs; |
| 3330 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs); |
| 3331 | bool pass = |
| 3332 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0); |
| 3333 | if (!pass) { |
| 3334 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 3335 | return; |
| 3336 | } |
| 3337 | |
| 3338 | VkDeviceMemory mem; |
| 3339 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 3340 | ASSERT_VK_SUCCESS(err); |
| 3341 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 3342 | ASSERT_VK_SUCCESS(err); |
| 3343 | |
| 3344 | { |
| 3345 | VkCommandBufferBeginInfo begin_info{}; |
| 3346 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3347 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3348 | |
| 3349 | vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1); |
| 3350 | vkCmdWriteTimestamp(command_buffer[0], |
| 3351 | VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0); |
| 3352 | |
| 3353 | vkEndCommandBuffer(command_buffer[0]); |
| 3354 | |
| 3355 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3356 | |
| 3357 | vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, |
| 3358 | 0, 0, 0); |
| 3359 | |
| 3360 | vkEndCommandBuffer(command_buffer[1]); |
| 3361 | } |
| 3362 | { |
| 3363 | VkSubmitInfo submit_info{}; |
| 3364 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3365 | submit_info.commandBufferCount = 2; |
| 3366 | submit_info.pCommandBuffers = command_buffer; |
| 3367 | submit_info.signalSemaphoreCount = 0; |
| 3368 | submit_info.pSignalSemaphores = nullptr; |
| 3369 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3370 | } |
| 3371 | |
| 3372 | vkQueueWaitIdle(queue); |
| 3373 | |
| 3374 | vkDestroyQueryPool(m_device->device(), query_pool, nullptr); |
| 3375 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer); |
| 3376 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 3377 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 3378 | vkFreeMemory(m_device->device(), mem, NULL); |
Michael Lentine | 5627e69 | 2016-05-20 17:45:02 -0500 | [diff] [blame] | 3379 | |
| 3380 | m_errorMonitor->VerifyNotFound(); |
| 3381 | } |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3382 | |
| 3383 | TEST_F(VkLayerTest, ResetEventThenSet) { |
| 3384 | TEST_DESCRIPTION( |
| 3385 | "Reset an event then set it after the reset has been submitted."); |
| 3386 | |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3387 | m_errorMonitor->ExpectSuccess(); |
| 3388 | |
| 3389 | VkEvent event; |
| 3390 | VkEventCreateInfo event_create_info{}; |
| 3391 | event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 3392 | vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event); |
| 3393 | |
| 3394 | VkCommandPool command_pool; |
| 3395 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3396 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3397 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3398 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3399 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3400 | &command_pool); |
| 3401 | |
| 3402 | VkCommandBuffer command_buffer; |
| 3403 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3404 | command_buffer_allocate_info.sType = |
| 3405 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3406 | command_buffer_allocate_info.commandPool = command_pool; |
| 3407 | command_buffer_allocate_info.commandBufferCount = 1; |
| 3408 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3409 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3410 | &command_buffer); |
| 3411 | |
| 3412 | VkQueue queue = VK_NULL_HANDLE; |
| 3413 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
Tony Barbour | fe302c0 | 2016-06-06 13:05:19 -0600 | [diff] [blame] | 3414 | 0, &queue); |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 3415 | |
| 3416 | { |
| 3417 | VkCommandBufferBeginInfo begin_info{}; |
| 3418 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3419 | vkBeginCommandBuffer(command_buffer, &begin_info); |
| 3420 | |
| 3421 | vkCmdResetEvent(command_buffer, event, |
| 3422 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 3423 | vkCmdWaitEvents(command_buffer, 1, &event, |
| 3424 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3425 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, |
| 3426 | nullptr, 0, nullptr); |
| 3427 | vkEndCommandBuffer(command_buffer); |
| 3428 | } |
| 3429 | { |
| 3430 | VkSubmitInfo submit_info{}; |
| 3431 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3432 | submit_info.commandBufferCount = 1; |
| 3433 | submit_info.pCommandBuffers = &command_buffer; |
| 3434 | submit_info.signalSemaphoreCount = 0; |
| 3435 | submit_info.pSignalSemaphores = nullptr; |
| 3436 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3437 | } |
| 3438 | { |
| 3439 | m_errorMonitor->SetDesiredFailureMsg( |
| 3440 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkSetEvent() on event " |
| 3441 | "0x1 that is already in use by a " |
| 3442 | "command buffer."); |
| 3443 | vkSetEvent(m_device->device(), event); |
| 3444 | m_errorMonitor->VerifyFound(); |
| 3445 | } |
| 3446 | |
| 3447 | vkQueueWaitIdle(queue); |
| 3448 | |
| 3449 | vkDestroyEvent(m_device->device(), event, nullptr); |
| 3450 | vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer); |
| 3451 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3452 | } |
| 3453 | |
| 3454 | // This is a positive test. No errors should be generated. |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3455 | TEST_F(VkLayerTest, TwoFencesThreeFrames) { |
| 3456 | TEST_DESCRIPTION("Two command buffers with two separate fences are each " |
| 3457 | "run through a Submit & WaitForFences cycle 3 times. This " |
| 3458 | "previously revealed a bug so running this positive test " |
| 3459 | "to prevent a regression."); |
| 3460 | m_errorMonitor->ExpectSuccess(); |
| 3461 | |
| 3462 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 3463 | VkQueue queue = VK_NULL_HANDLE; |
| 3464 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3465 | 0, &queue); |
| 3466 | |
| 3467 | static const uint32_t NUM_OBJECTS = 2; |
| 3468 | static const uint32_t NUM_FRAMES = 3; |
| 3469 | VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {}; |
| 3470 | VkFence fences[NUM_OBJECTS] = {}; |
| 3471 | |
| 3472 | VkCommandPool cmd_pool; |
| 3473 | VkCommandPoolCreateInfo cmd_pool_ci = {}; |
| 3474 | cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3475 | cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3476 | cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3477 | VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, |
| 3478 | nullptr, &cmd_pool); |
| 3479 | ASSERT_VK_SUCCESS(err); |
| 3480 | |
| 3481 | VkCommandBufferAllocateInfo cmd_buf_info = {}; |
| 3482 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3483 | cmd_buf_info.commandPool = cmd_pool; |
| 3484 | cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3485 | cmd_buf_info.commandBufferCount = 1; |
| 3486 | |
| 3487 | VkFenceCreateInfo fence_ci = {}; |
| 3488 | fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3489 | fence_ci.pNext = nullptr; |
| 3490 | fence_ci.flags = 0; |
| 3491 | |
| 3492 | for (uint32_t i = 0; i < NUM_OBJECTS; ++i) { |
| 3493 | err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, |
| 3494 | &cmd_buffers[i]); |
| 3495 | ASSERT_VK_SUCCESS(err); |
| 3496 | err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]); |
| 3497 | ASSERT_VK_SUCCESS(err); |
| 3498 | } |
| 3499 | |
| 3500 | for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) { |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 3501 | for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) { |
| 3502 | // Create empty cmd buffer |
| 3503 | VkCommandBufferBeginInfo cmdBufBeginDesc = {}; |
| 3504 | cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3505 | |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 3506 | err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc); |
| 3507 | ASSERT_VK_SUCCESS(err); |
| 3508 | err = vkEndCommandBuffer(cmd_buffers[obj]); |
| 3509 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3510 | |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 3511 | VkSubmitInfo submit_info = {}; |
| 3512 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3513 | submit_info.commandBufferCount = 1; |
| 3514 | submit_info.pCommandBuffers = &cmd_buffers[obj]; |
| 3515 | // Submit cmd buffer and wait for fence |
| 3516 | err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]); |
| 3517 | ASSERT_VK_SUCCESS(err); |
| 3518 | err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, |
| 3519 | UINT64_MAX); |
| 3520 | ASSERT_VK_SUCCESS(err); |
| 3521 | err = vkResetFences(m_device->device(), 1, &fences[obj]); |
| 3522 | ASSERT_VK_SUCCESS(err); |
| 3523 | } |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3524 | } |
| 3525 | m_errorMonitor->VerifyNotFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 3526 | vkDestroyCommandPool(m_device->device(), cmd_pool, NULL); |
| 3527 | for (uint32_t i = 0; i < NUM_OBJECTS; ++i) { |
| 3528 | vkDestroyFence(m_device->device(), fences[i], nullptr); |
| 3529 | } |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3530 | } |
| 3531 | // This is a positive test. No errors should be generated. |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3532 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) { |
| 3533 | |
| 3534 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 3535 | "submitted on separate queues followed by a QueueWaitIdle."); |
| 3536 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 3537 | if ((m_device->queue_props.empty()) || |
| 3538 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 3539 | return; |
| 3540 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3541 | m_errorMonitor->ExpectSuccess(); |
| 3542 | |
| 3543 | VkSemaphore semaphore; |
| 3544 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 3545 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 3546 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 3547 | &semaphore); |
| 3548 | |
| 3549 | VkCommandPool command_pool; |
| 3550 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3551 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3552 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3553 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3554 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3555 | &command_pool); |
| 3556 | |
| 3557 | VkCommandBuffer command_buffer[2]; |
| 3558 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3559 | command_buffer_allocate_info.sType = |
| 3560 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3561 | command_buffer_allocate_info.commandPool = command_pool; |
| 3562 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3563 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3564 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3565 | command_buffer); |
| 3566 | |
| 3567 | VkQueue queue = VK_NULL_HANDLE; |
| 3568 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3569 | 1, &queue); |
| 3570 | |
| 3571 | { |
| 3572 | VkCommandBufferBeginInfo begin_info{}; |
| 3573 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3574 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3575 | |
| 3576 | vkCmdPipelineBarrier(command_buffer[0], |
| 3577 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3578 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 3579 | 0, nullptr, 0, nullptr); |
| 3580 | |
| 3581 | VkViewport viewport{}; |
| 3582 | viewport.maxDepth = 1.0f; |
| 3583 | viewport.minDepth = 0.0f; |
| 3584 | viewport.width = 512; |
| 3585 | viewport.height = 512; |
| 3586 | viewport.x = 0; |
| 3587 | viewport.y = 0; |
| 3588 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 3589 | vkEndCommandBuffer(command_buffer[0]); |
| 3590 | } |
| 3591 | { |
| 3592 | VkCommandBufferBeginInfo begin_info{}; |
| 3593 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3594 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3595 | |
| 3596 | VkViewport viewport{}; |
| 3597 | viewport.maxDepth = 1.0f; |
| 3598 | viewport.minDepth = 0.0f; |
| 3599 | viewport.width = 512; |
| 3600 | viewport.height = 512; |
| 3601 | viewport.x = 0; |
| 3602 | viewport.y = 0; |
| 3603 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 3604 | vkEndCommandBuffer(command_buffer[1]); |
| 3605 | } |
| 3606 | { |
| 3607 | VkSubmitInfo submit_info{}; |
| 3608 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3609 | submit_info.commandBufferCount = 1; |
| 3610 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 3611 | submit_info.signalSemaphoreCount = 1; |
| 3612 | submit_info.pSignalSemaphores = &semaphore; |
| 3613 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3614 | } |
| 3615 | { |
| 3616 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 3617 | VkSubmitInfo submit_info{}; |
| 3618 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3619 | submit_info.commandBufferCount = 1; |
| 3620 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 3621 | submit_info.waitSemaphoreCount = 1; |
| 3622 | submit_info.pWaitSemaphores = &semaphore; |
| 3623 | submit_info.pWaitDstStageMask = flags; |
| 3624 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3625 | } |
| 3626 | |
| 3627 | vkQueueWaitIdle(m_device->m_queue); |
| 3628 | |
| 3629 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 3630 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 3631 | &command_buffer[0]); |
| 3632 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3633 | |
| 3634 | m_errorMonitor->VerifyNotFound(); |
| 3635 | } |
| 3636 | |
| 3637 | // This is a positive test. No errors should be generated. |
| 3638 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) { |
| 3639 | |
| 3640 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 3641 | "submitted on separate queues, the second having a fence" |
| 3642 | "followed by a QueueWaitIdle."); |
| 3643 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 3644 | if ((m_device->queue_props.empty()) || |
| 3645 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 3646 | return; |
| 3647 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3648 | m_errorMonitor->ExpectSuccess(); |
| 3649 | |
| 3650 | VkFence fence; |
| 3651 | VkFenceCreateInfo fence_create_info{}; |
| 3652 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3653 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 3654 | |
| 3655 | VkSemaphore semaphore; |
| 3656 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 3657 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 3658 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 3659 | &semaphore); |
| 3660 | |
| 3661 | VkCommandPool command_pool; |
| 3662 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3663 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3664 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3665 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3666 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3667 | &command_pool); |
| 3668 | |
| 3669 | VkCommandBuffer command_buffer[2]; |
| 3670 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3671 | command_buffer_allocate_info.sType = |
| 3672 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3673 | command_buffer_allocate_info.commandPool = command_pool; |
| 3674 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3675 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3676 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3677 | command_buffer); |
| 3678 | |
| 3679 | VkQueue queue = VK_NULL_HANDLE; |
| 3680 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3681 | 1, &queue); |
| 3682 | |
| 3683 | { |
| 3684 | VkCommandBufferBeginInfo begin_info{}; |
| 3685 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3686 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3687 | |
| 3688 | vkCmdPipelineBarrier(command_buffer[0], |
| 3689 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3690 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 3691 | 0, nullptr, 0, nullptr); |
| 3692 | |
| 3693 | VkViewport viewport{}; |
| 3694 | viewport.maxDepth = 1.0f; |
| 3695 | viewport.minDepth = 0.0f; |
| 3696 | viewport.width = 512; |
| 3697 | viewport.height = 512; |
| 3698 | viewport.x = 0; |
| 3699 | viewport.y = 0; |
| 3700 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 3701 | vkEndCommandBuffer(command_buffer[0]); |
| 3702 | } |
| 3703 | { |
| 3704 | VkCommandBufferBeginInfo begin_info{}; |
| 3705 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3706 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3707 | |
| 3708 | VkViewport viewport{}; |
| 3709 | viewport.maxDepth = 1.0f; |
| 3710 | viewport.minDepth = 0.0f; |
| 3711 | viewport.width = 512; |
| 3712 | viewport.height = 512; |
| 3713 | viewport.x = 0; |
| 3714 | viewport.y = 0; |
| 3715 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 3716 | vkEndCommandBuffer(command_buffer[1]); |
| 3717 | } |
| 3718 | { |
| 3719 | VkSubmitInfo submit_info{}; |
| 3720 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3721 | submit_info.commandBufferCount = 1; |
| 3722 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 3723 | submit_info.signalSemaphoreCount = 1; |
| 3724 | submit_info.pSignalSemaphores = &semaphore; |
| 3725 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3726 | } |
| 3727 | { |
| 3728 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 3729 | VkSubmitInfo submit_info{}; |
| 3730 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3731 | submit_info.commandBufferCount = 1; |
| 3732 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 3733 | submit_info.waitSemaphoreCount = 1; |
| 3734 | submit_info.pWaitSemaphores = &semaphore; |
| 3735 | submit_info.pWaitDstStageMask = flags; |
| 3736 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 3737 | } |
| 3738 | |
| 3739 | vkQueueWaitIdle(m_device->m_queue); |
| 3740 | |
| 3741 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 3742 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 3743 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 3744 | &command_buffer[0]); |
| 3745 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3746 | |
| 3747 | m_errorMonitor->VerifyNotFound(); |
| 3748 | } |
| 3749 | |
| 3750 | // This is a positive test. No errors should be generated. |
| 3751 | TEST_F(VkLayerTest, |
| 3752 | TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) { |
| 3753 | |
| 3754 | TEST_DESCRIPTION( |
| 3755 | "Two command buffers, each in a separate QueueSubmit call " |
| 3756 | "submitted on separate queues, the second having a fence" |
| 3757 | "followed by two consecutive WaitForFences calls on the same fence."); |
| 3758 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 3759 | if ((m_device->queue_props.empty()) || |
| 3760 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 3761 | return; |
| 3762 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3763 | m_errorMonitor->ExpectSuccess(); |
| 3764 | |
| 3765 | VkFence fence; |
| 3766 | VkFenceCreateInfo fence_create_info{}; |
| 3767 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3768 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 3769 | |
| 3770 | VkSemaphore semaphore; |
| 3771 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 3772 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 3773 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 3774 | &semaphore); |
| 3775 | |
| 3776 | VkCommandPool command_pool; |
| 3777 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3778 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3779 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3780 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3781 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3782 | &command_pool); |
| 3783 | |
| 3784 | VkCommandBuffer command_buffer[2]; |
| 3785 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3786 | command_buffer_allocate_info.sType = |
| 3787 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3788 | command_buffer_allocate_info.commandPool = command_pool; |
| 3789 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3790 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3791 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3792 | command_buffer); |
| 3793 | |
| 3794 | VkQueue queue = VK_NULL_HANDLE; |
| 3795 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3796 | 1, &queue); |
| 3797 | |
| 3798 | { |
| 3799 | VkCommandBufferBeginInfo begin_info{}; |
| 3800 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3801 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3802 | |
| 3803 | vkCmdPipelineBarrier(command_buffer[0], |
| 3804 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3805 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 3806 | 0, nullptr, 0, nullptr); |
| 3807 | |
| 3808 | VkViewport viewport{}; |
| 3809 | viewport.maxDepth = 1.0f; |
| 3810 | viewport.minDepth = 0.0f; |
| 3811 | viewport.width = 512; |
| 3812 | viewport.height = 512; |
| 3813 | viewport.x = 0; |
| 3814 | viewport.y = 0; |
| 3815 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 3816 | vkEndCommandBuffer(command_buffer[0]); |
| 3817 | } |
| 3818 | { |
| 3819 | VkCommandBufferBeginInfo begin_info{}; |
| 3820 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3821 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3822 | |
| 3823 | VkViewport viewport{}; |
| 3824 | viewport.maxDepth = 1.0f; |
| 3825 | viewport.minDepth = 0.0f; |
| 3826 | viewport.width = 512; |
| 3827 | viewport.height = 512; |
| 3828 | viewport.x = 0; |
| 3829 | viewport.y = 0; |
| 3830 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 3831 | vkEndCommandBuffer(command_buffer[1]); |
| 3832 | } |
| 3833 | { |
| 3834 | VkSubmitInfo submit_info{}; |
| 3835 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3836 | submit_info.commandBufferCount = 1; |
| 3837 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 3838 | submit_info.signalSemaphoreCount = 1; |
| 3839 | submit_info.pSignalSemaphores = &semaphore; |
| 3840 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3841 | } |
| 3842 | { |
| 3843 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 3844 | VkSubmitInfo submit_info{}; |
| 3845 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3846 | submit_info.commandBufferCount = 1; |
| 3847 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 3848 | submit_info.waitSemaphoreCount = 1; |
| 3849 | submit_info.pWaitSemaphores = &semaphore; |
| 3850 | submit_info.pWaitDstStageMask = flags; |
| 3851 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 3852 | } |
| 3853 | |
| 3854 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 3855 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 3856 | |
| 3857 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 3858 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 3859 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 3860 | &command_buffer[0]); |
| 3861 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3862 | |
| 3863 | m_errorMonitor->VerifyNotFound(); |
| 3864 | } |
| 3865 | |
| 3866 | // This is a positive test. No errors should be generated. |
| 3867 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) { |
| 3868 | |
| 3869 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 3870 | "submitted on separate queues, the second having a fence, " |
| 3871 | "followed by a WaitForFences call."); |
| 3872 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 3873 | if ((m_device->queue_props.empty()) || |
| 3874 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 3875 | return; |
| 3876 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3877 | m_errorMonitor->ExpectSuccess(); |
| 3878 | |
| 3879 | VkFence fence; |
| 3880 | VkFenceCreateInfo fence_create_info{}; |
| 3881 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3882 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 3883 | |
| 3884 | VkSemaphore semaphore; |
| 3885 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 3886 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 3887 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 3888 | &semaphore); |
| 3889 | |
| 3890 | VkCommandPool command_pool; |
| 3891 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3892 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3893 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3894 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3895 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3896 | &command_pool); |
| 3897 | |
| 3898 | VkCommandBuffer command_buffer[2]; |
| 3899 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3900 | command_buffer_allocate_info.sType = |
| 3901 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3902 | command_buffer_allocate_info.commandPool = command_pool; |
| 3903 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3904 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3905 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3906 | command_buffer); |
| 3907 | |
| 3908 | VkQueue queue = VK_NULL_HANDLE; |
| 3909 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3910 | 1, &queue); |
| 3911 | |
| 3912 | |
| 3913 | { |
| 3914 | VkCommandBufferBeginInfo begin_info{}; |
| 3915 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3916 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3917 | |
| 3918 | vkCmdPipelineBarrier(command_buffer[0], |
| 3919 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3920 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 3921 | 0, nullptr, 0, nullptr); |
| 3922 | |
| 3923 | VkViewport viewport{}; |
| 3924 | viewport.maxDepth = 1.0f; |
| 3925 | viewport.minDepth = 0.0f; |
| 3926 | viewport.width = 512; |
| 3927 | viewport.height = 512; |
| 3928 | viewport.x = 0; |
| 3929 | viewport.y = 0; |
| 3930 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 3931 | vkEndCommandBuffer(command_buffer[0]); |
| 3932 | } |
| 3933 | { |
| 3934 | VkCommandBufferBeginInfo begin_info{}; |
| 3935 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3936 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3937 | |
| 3938 | VkViewport viewport{}; |
| 3939 | viewport.maxDepth = 1.0f; |
| 3940 | viewport.minDepth = 0.0f; |
| 3941 | viewport.width = 512; |
| 3942 | viewport.height = 512; |
| 3943 | viewport.x = 0; |
| 3944 | viewport.y = 0; |
| 3945 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 3946 | vkEndCommandBuffer(command_buffer[1]); |
| 3947 | } |
| 3948 | { |
| 3949 | VkSubmitInfo submit_info{}; |
| 3950 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3951 | submit_info.commandBufferCount = 1; |
| 3952 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 3953 | submit_info.signalSemaphoreCount = 1; |
| 3954 | submit_info.pSignalSemaphores = &semaphore; |
| 3955 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3956 | } |
| 3957 | { |
| 3958 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 3959 | VkSubmitInfo submit_info{}; |
| 3960 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3961 | submit_info.commandBufferCount = 1; |
| 3962 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 3963 | submit_info.waitSemaphoreCount = 1; |
| 3964 | submit_info.pWaitSemaphores = &semaphore; |
| 3965 | submit_info.pWaitDstStageMask = flags; |
| 3966 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 3967 | } |
| 3968 | |
| 3969 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 3970 | |
| 3971 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 3972 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 3973 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 3974 | &command_buffer[0]); |
| 3975 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3976 | |
| 3977 | m_errorMonitor->VerifyNotFound(); |
| 3978 | } |
| 3979 | |
| 3980 | // This is a positive test. No errors should be generated. |
| 3981 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) { |
| 3982 | |
| 3983 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 3984 | "on the same queue, sharing a signal/wait semaphore, the " |
| 3985 | "second having a fence, " |
| 3986 | "followed by a WaitForFences call."); |
| 3987 | |
| 3988 | m_errorMonitor->ExpectSuccess(); |
| 3989 | |
| 3990 | VkFence fence; |
| 3991 | VkFenceCreateInfo fence_create_info{}; |
| 3992 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3993 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 3994 | |
| 3995 | VkSemaphore semaphore; |
| 3996 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 3997 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 3998 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 3999 | &semaphore); |
| 4000 | |
| 4001 | VkCommandPool command_pool; |
| 4002 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4003 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4004 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4005 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4006 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4007 | &command_pool); |
| 4008 | |
| 4009 | VkCommandBuffer command_buffer[2]; |
| 4010 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4011 | command_buffer_allocate_info.sType = |
| 4012 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4013 | command_buffer_allocate_info.commandPool = command_pool; |
| 4014 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4015 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4016 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4017 | command_buffer); |
| 4018 | |
| 4019 | { |
| 4020 | VkCommandBufferBeginInfo begin_info{}; |
| 4021 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4022 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4023 | |
| 4024 | vkCmdPipelineBarrier(command_buffer[0], |
| 4025 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4026 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4027 | 0, nullptr, 0, nullptr); |
| 4028 | |
| 4029 | VkViewport viewport{}; |
| 4030 | viewport.maxDepth = 1.0f; |
| 4031 | viewport.minDepth = 0.0f; |
| 4032 | viewport.width = 512; |
| 4033 | viewport.height = 512; |
| 4034 | viewport.x = 0; |
| 4035 | viewport.y = 0; |
| 4036 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4037 | vkEndCommandBuffer(command_buffer[0]); |
| 4038 | } |
| 4039 | { |
| 4040 | VkCommandBufferBeginInfo begin_info{}; |
| 4041 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4042 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4043 | |
| 4044 | VkViewport viewport{}; |
| 4045 | viewport.maxDepth = 1.0f; |
| 4046 | viewport.minDepth = 0.0f; |
| 4047 | viewport.width = 512; |
| 4048 | viewport.height = 512; |
| 4049 | viewport.x = 0; |
| 4050 | viewport.y = 0; |
| 4051 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4052 | vkEndCommandBuffer(command_buffer[1]); |
| 4053 | } |
| 4054 | { |
| 4055 | VkSubmitInfo submit_info{}; |
| 4056 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4057 | submit_info.commandBufferCount = 1; |
| 4058 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4059 | submit_info.signalSemaphoreCount = 1; |
| 4060 | submit_info.pSignalSemaphores = &semaphore; |
| 4061 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4062 | } |
| 4063 | { |
| 4064 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4065 | VkSubmitInfo submit_info{}; |
| 4066 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4067 | submit_info.commandBufferCount = 1; |
| 4068 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4069 | submit_info.waitSemaphoreCount = 1; |
| 4070 | submit_info.pWaitSemaphores = &semaphore; |
| 4071 | submit_info.pWaitDstStageMask = flags; |
| 4072 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4073 | } |
| 4074 | |
| 4075 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4076 | |
| 4077 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4078 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 4079 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4080 | &command_buffer[0]); |
| 4081 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4082 | |
| 4083 | m_errorMonitor->VerifyNotFound(); |
| 4084 | } |
| 4085 | |
| 4086 | // This is a positive test. No errors should be generated. |
| 4087 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) { |
| 4088 | |
| 4089 | TEST_DESCRIPTION( |
| 4090 | "Two command buffers, each in a separate QueueSubmit call " |
| 4091 | "on the same queue, no fences, followed by a third QueueSubmit with NO " |
| 4092 | "SubmitInfos but with a fence, followed by a WaitForFences call."); |
| 4093 | |
| 4094 | m_errorMonitor->ExpectSuccess(); |
| 4095 | |
| 4096 | VkFence fence; |
| 4097 | VkFenceCreateInfo fence_create_info{}; |
| 4098 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4099 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4100 | |
| 4101 | VkCommandPool command_pool; |
| 4102 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4103 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4104 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4105 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4106 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4107 | &command_pool); |
| 4108 | |
| 4109 | VkCommandBuffer command_buffer[2]; |
| 4110 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4111 | command_buffer_allocate_info.sType = |
| 4112 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4113 | command_buffer_allocate_info.commandPool = command_pool; |
| 4114 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4115 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4116 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4117 | command_buffer); |
| 4118 | |
| 4119 | { |
| 4120 | VkCommandBufferBeginInfo begin_info{}; |
| 4121 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4122 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4123 | |
| 4124 | vkCmdPipelineBarrier(command_buffer[0], |
| 4125 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4126 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4127 | 0, nullptr, 0, nullptr); |
| 4128 | |
| 4129 | VkViewport viewport{}; |
| 4130 | viewport.maxDepth = 1.0f; |
| 4131 | viewport.minDepth = 0.0f; |
| 4132 | viewport.width = 512; |
| 4133 | viewport.height = 512; |
| 4134 | viewport.x = 0; |
| 4135 | viewport.y = 0; |
| 4136 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4137 | vkEndCommandBuffer(command_buffer[0]); |
| 4138 | } |
| 4139 | { |
| 4140 | VkCommandBufferBeginInfo begin_info{}; |
| 4141 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4142 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4143 | |
| 4144 | VkViewport viewport{}; |
| 4145 | viewport.maxDepth = 1.0f; |
| 4146 | viewport.minDepth = 0.0f; |
| 4147 | viewport.width = 512; |
| 4148 | viewport.height = 512; |
| 4149 | viewport.x = 0; |
| 4150 | viewport.y = 0; |
| 4151 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4152 | vkEndCommandBuffer(command_buffer[1]); |
| 4153 | } |
| 4154 | { |
| 4155 | VkSubmitInfo submit_info{}; |
| 4156 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4157 | submit_info.commandBufferCount = 1; |
| 4158 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4159 | submit_info.signalSemaphoreCount = 0; |
| 4160 | submit_info.pSignalSemaphores = VK_NULL_HANDLE; |
| 4161 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4162 | } |
| 4163 | { |
| 4164 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4165 | VkSubmitInfo submit_info{}; |
| 4166 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4167 | submit_info.commandBufferCount = 1; |
| 4168 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4169 | submit_info.waitSemaphoreCount = 0; |
| 4170 | submit_info.pWaitSemaphores = VK_NULL_HANDLE; |
| 4171 | submit_info.pWaitDstStageMask = flags; |
| 4172 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4173 | } |
| 4174 | |
| 4175 | vkQueueSubmit(m_device->m_queue, 0, NULL, fence); |
| 4176 | |
| 4177 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4178 | |
| 4179 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4180 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4181 | &command_buffer[0]); |
| 4182 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4183 | |
| 4184 | m_errorMonitor->VerifyNotFound(); |
| 4185 | } |
| 4186 | |
| 4187 | // This is a positive test. No errors should be generated. |
| 4188 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) { |
| 4189 | |
| 4190 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 4191 | "on the same queue, the second having a fence, followed " |
| 4192 | "by a WaitForFences call."); |
| 4193 | |
| 4194 | m_errorMonitor->ExpectSuccess(); |
| 4195 | |
| 4196 | VkFence fence; |
| 4197 | VkFenceCreateInfo fence_create_info{}; |
| 4198 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4199 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4200 | |
| 4201 | VkCommandPool command_pool; |
| 4202 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4203 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4204 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4205 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4206 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4207 | &command_pool); |
| 4208 | |
| 4209 | VkCommandBuffer command_buffer[2]; |
| 4210 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4211 | command_buffer_allocate_info.sType = |
| 4212 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4213 | command_buffer_allocate_info.commandPool = command_pool; |
| 4214 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4215 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4216 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4217 | command_buffer); |
| 4218 | |
| 4219 | { |
| 4220 | VkCommandBufferBeginInfo begin_info{}; |
| 4221 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4222 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4223 | |
| 4224 | vkCmdPipelineBarrier(command_buffer[0], |
| 4225 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4226 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4227 | 0, nullptr, 0, nullptr); |
| 4228 | |
| 4229 | VkViewport viewport{}; |
| 4230 | viewport.maxDepth = 1.0f; |
| 4231 | viewport.minDepth = 0.0f; |
| 4232 | viewport.width = 512; |
| 4233 | viewport.height = 512; |
| 4234 | viewport.x = 0; |
| 4235 | viewport.y = 0; |
| 4236 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4237 | vkEndCommandBuffer(command_buffer[0]); |
| 4238 | } |
| 4239 | { |
| 4240 | VkCommandBufferBeginInfo begin_info{}; |
| 4241 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4242 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4243 | |
| 4244 | VkViewport viewport{}; |
| 4245 | viewport.maxDepth = 1.0f; |
| 4246 | viewport.minDepth = 0.0f; |
| 4247 | viewport.width = 512; |
| 4248 | viewport.height = 512; |
| 4249 | viewport.x = 0; |
| 4250 | viewport.y = 0; |
| 4251 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4252 | vkEndCommandBuffer(command_buffer[1]); |
| 4253 | } |
| 4254 | { |
| 4255 | VkSubmitInfo submit_info{}; |
| 4256 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4257 | submit_info.commandBufferCount = 1; |
| 4258 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 4259 | submit_info.signalSemaphoreCount = 0; |
| 4260 | submit_info.pSignalSemaphores = VK_NULL_HANDLE; |
| 4261 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 4262 | } |
| 4263 | { |
| 4264 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4265 | VkSubmitInfo submit_info{}; |
| 4266 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4267 | submit_info.commandBufferCount = 1; |
| 4268 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 4269 | submit_info.waitSemaphoreCount = 0; |
| 4270 | submit_info.pWaitSemaphores = VK_NULL_HANDLE; |
| 4271 | submit_info.pWaitDstStageMask = flags; |
| 4272 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 4273 | } |
| 4274 | |
| 4275 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4276 | |
| 4277 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4278 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4279 | &command_buffer[0]); |
| 4280 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 4281 | |
| 4282 | m_errorMonitor->VerifyNotFound(); |
| 4283 | } |
| 4284 | |
| 4285 | // This is a positive test. No errors should be generated. |
| 4286 | TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) { |
| 4287 | |
| 4288 | TEST_DESCRIPTION( |
| 4289 | "Two command buffers each in a separate SubmitInfo sent in a single " |
| 4290 | "QueueSubmit call followed by a WaitForFences call."); |
| 4291 | |
| 4292 | m_errorMonitor->ExpectSuccess(); |
| 4293 | |
| 4294 | VkFence fence; |
| 4295 | VkFenceCreateInfo fence_create_info{}; |
| 4296 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4297 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 4298 | |
| 4299 | VkSemaphore semaphore; |
| 4300 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 4301 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 4302 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 4303 | &semaphore); |
| 4304 | |
| 4305 | VkCommandPool command_pool; |
| 4306 | VkCommandPoolCreateInfo pool_create_info{}; |
| 4307 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 4308 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 4309 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 4310 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 4311 | &command_pool); |
| 4312 | |
| 4313 | VkCommandBuffer command_buffer[2]; |
| 4314 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 4315 | command_buffer_allocate_info.sType = |
| 4316 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 4317 | command_buffer_allocate_info.commandPool = command_pool; |
| 4318 | command_buffer_allocate_info.commandBufferCount = 2; |
| 4319 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 4320 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 4321 | command_buffer); |
| 4322 | |
| 4323 | { |
| 4324 | VkCommandBufferBeginInfo begin_info{}; |
| 4325 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4326 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 4327 | |
| 4328 | vkCmdPipelineBarrier(command_buffer[0], |
| 4329 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 4330 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 4331 | 0, nullptr, 0, nullptr); |
| 4332 | |
| 4333 | VkViewport viewport{}; |
| 4334 | viewport.maxDepth = 1.0f; |
| 4335 | viewport.minDepth = 0.0f; |
| 4336 | viewport.width = 512; |
| 4337 | viewport.height = 512; |
| 4338 | viewport.x = 0; |
| 4339 | viewport.y = 0; |
| 4340 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 4341 | vkEndCommandBuffer(command_buffer[0]); |
| 4342 | } |
| 4343 | { |
| 4344 | VkCommandBufferBeginInfo begin_info{}; |
| 4345 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 4346 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 4347 | |
| 4348 | VkViewport viewport{}; |
| 4349 | viewport.maxDepth = 1.0f; |
| 4350 | viewport.minDepth = 0.0f; |
| 4351 | viewport.width = 512; |
| 4352 | viewport.height = 512; |
| 4353 | viewport.x = 0; |
| 4354 | viewport.y = 0; |
| 4355 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 4356 | vkEndCommandBuffer(command_buffer[1]); |
| 4357 | } |
| 4358 | { |
| 4359 | VkSubmitInfo submit_info[2]; |
| 4360 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 4361 | |
| 4362 | submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4363 | submit_info[0].pNext = NULL; |
| 4364 | submit_info[0].commandBufferCount = 1; |
| 4365 | submit_info[0].pCommandBuffers = &command_buffer[0]; |
| 4366 | submit_info[0].signalSemaphoreCount = 1; |
| 4367 | submit_info[0].pSignalSemaphores = &semaphore; |
| 4368 | submit_info[0].waitSemaphoreCount = 0; |
| 4369 | submit_info[0].pWaitSemaphores = NULL; |
| 4370 | submit_info[0].pWaitDstStageMask = 0; |
| 4371 | |
| 4372 | submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4373 | submit_info[1].pNext = NULL; |
| 4374 | submit_info[1].commandBufferCount = 1; |
| 4375 | submit_info[1].pCommandBuffers = &command_buffer[1]; |
| 4376 | submit_info[1].waitSemaphoreCount = 1; |
| 4377 | submit_info[1].pWaitSemaphores = &semaphore; |
| 4378 | submit_info[1].pWaitDstStageMask = flags; |
| 4379 | submit_info[1].signalSemaphoreCount = 0; |
| 4380 | submit_info[1].pSignalSemaphores = NULL; |
| 4381 | vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence); |
| 4382 | } |
| 4383 | |
| 4384 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 4385 | |
| 4386 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 4387 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 4388 | &command_buffer[0]); |
| 4389 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 4390 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 4391 | |
| 4392 | m_errorMonitor->VerifyNotFound(); |
| 4393 | } |
| 4394 | |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4395 | TEST_F(VkLayerTest, DynamicDepthBiasNotBound) { |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4396 | TEST_DESCRIPTION( |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4397 | "Run a simple draw calls to validate failure when Depth Bias dynamic " |
| 4398 | "state is required but not correctly bound."); |
| 4399 | |
| 4400 | // Dynamic depth bias |
| 4401 | m_errorMonitor->SetDesiredFailureMsg( |
| 4402 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4403 | "Dynamic depth bias state not set for this command buffer"); |
| 4404 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4405 | BsoFailDepthBias); |
| 4406 | m_errorMonitor->VerifyFound(); |
| 4407 | } |
| 4408 | |
| 4409 | TEST_F(VkLayerTest, DynamicLineWidthNotBound) { |
| 4410 | TEST_DESCRIPTION( |
| 4411 | "Run a simple draw calls to validate failure when Line Width dynamic " |
| 4412 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4413 | |
| 4414 | // Dynamic line width |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4415 | m_errorMonitor->SetDesiredFailureMsg( |
| 4416 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4417 | "Dynamic line width state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4418 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4419 | BsoFailLineWidth); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4420 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4421 | } |
| 4422 | |
| 4423 | TEST_F(VkLayerTest, DynamicViewportNotBound) { |
| 4424 | TEST_DESCRIPTION( |
| 4425 | "Run a simple draw calls to validate failure when Viewport dynamic " |
| 4426 | "state is required but not correctly bound."); |
| 4427 | |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4428 | // Dynamic viewport state |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4429 | m_errorMonitor->SetDesiredFailureMsg( |
| 4430 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4431 | "Dynamic viewport state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4432 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4433 | BsoFailViewport); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4434 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4435 | } |
| 4436 | |
| 4437 | TEST_F(VkLayerTest, DynamicScissorNotBound) { |
| 4438 | TEST_DESCRIPTION( |
| 4439 | "Run a simple draw calls to validate failure when Scissor dynamic " |
| 4440 | "state is required but not correctly bound."); |
| 4441 | |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4442 | // Dynamic scissor state |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4443 | m_errorMonitor->SetDesiredFailureMsg( |
| 4444 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4445 | "Dynamic scissor state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4446 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4447 | BsoFailScissor); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4448 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4449 | } |
| 4450 | |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 4451 | TEST_F(VkLayerTest, DynamiBlendConstantsNotBound) { |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4452 | TEST_DESCRIPTION( |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 4453 | "Run a simple draw calls to validate failure when Blend Constants " |
| 4454 | "dynamic state is required but not correctly bound."); |
| 4455 | // Dynamic blend constant state |
| 4456 | m_errorMonitor->SetDesiredFailureMsg( |
| 4457 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4458 | "Dynamic blend constants state not set for this command buffer"); |
| 4459 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4460 | BsoFailBlend); |
| 4461 | m_errorMonitor->VerifyFound(); |
| 4462 | } |
| 4463 | |
| 4464 | TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) { |
| 4465 | TEST_DESCRIPTION( |
| 4466 | "Run a simple draw calls to validate failure when Depth Bounds dynamic " |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4467 | "state is required but not correctly bound."); |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 4468 | if (!m_device->phy().features().depthBounds) { |
| 4469 | printf("Device does not support depthBounds test; skipped.\n"); |
| 4470 | return; |
| 4471 | } |
| 4472 | // Dynamic depth bounds |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4473 | m_errorMonitor->SetDesiredFailureMsg( |
| 4474 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4475 | "Dynamic depth bounds state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4476 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4477 | BsoFailDepthBounds); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4478 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4479 | } |
| 4480 | |
| 4481 | TEST_F(VkLayerTest, DynamicStencilReadNotBound) { |
| 4482 | TEST_DESCRIPTION( |
| 4483 | "Run a simple draw calls to validate failure when Stencil Read dynamic " |
| 4484 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4485 | // Dynamic stencil read mask |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4486 | m_errorMonitor->SetDesiredFailureMsg( |
| 4487 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4488 | "Dynamic stencil read mask state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4489 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4490 | BsoFailStencilReadMask); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4491 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4492 | } |
| 4493 | |
| 4494 | TEST_F(VkLayerTest, DynamicStencilWriteNotBound) { |
| 4495 | TEST_DESCRIPTION( |
| 4496 | "Run a simple draw calls to validate failure when Stencil Write dynamic" |
| 4497 | " state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4498 | // Dynamic stencil write mask |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4499 | m_errorMonitor->SetDesiredFailureMsg( |
| 4500 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4501 | "Dynamic stencil write mask state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4502 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4503 | BsoFailStencilWriteMask); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4504 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4505 | } |
| 4506 | |
| 4507 | TEST_F(VkLayerTest, DynamicStencilRefNotBound) { |
| 4508 | TEST_DESCRIPTION( |
| 4509 | "Run a simple draw calls to validate failure when Stencil Ref dynamic " |
| 4510 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4511 | // Dynamic stencil reference |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4512 | m_errorMonitor->SetDesiredFailureMsg( |
| 4513 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4514 | "Dynamic stencil reference state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4515 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4516 | BsoFailStencilReference); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4517 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 963a404 | 2015-09-29 08:18:34 -0600 | [diff] [blame] | 4518 | } |
| 4519 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4520 | TEST_F(VkLayerTest, CommandBufferTwoSubmits) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4521 | m_errorMonitor->SetDesiredFailureMsg( |
| 4522 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4523 | "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has " |
| 4524 | "been submitted"); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4525 | |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4526 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4527 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 4528 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 4529 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4530 | // We luck out b/c by default the framework creates CB w/ the |
| 4531 | // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4532 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4533 | m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 4534 | m_stencil_clear_color, NULL); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4535 | EndCommandBuffer(); |
| 4536 | |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4537 | // Bypass framework since it does the waits automatically |
| 4538 | VkResult err = VK_SUCCESS; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 4539 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 4540 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4541 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 4542 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 4543 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 4544 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 4545 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 4546 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 4547 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 4548 | submit_info.pSignalSemaphores = NULL; |
| 4549 | |
Chris Forbes | 40028e2 | 2016-06-13 09:59:34 +1200 | [diff] [blame] | 4550 | err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4551 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4552 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4553 | // Cause validation error by re-submitting cmd buffer that should only be |
| 4554 | // submitted once |
Chris Forbes | 40028e2 | 2016-06-13 09:59:34 +1200 | [diff] [blame] | 4555 | err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4556 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4557 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4558 | } |
| 4559 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4560 | TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) { |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4561 | // Initiate Draw w/o a PSO bound |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4562 | VkResult err; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4563 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 4564 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4565 | "Unable to allocate 1 descriptors of " |
| 4566 | "type " |
| 4567 | "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4568 | |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4569 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4570 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4571 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4572 | // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer |
| 4573 | // descriptor from it |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 4574 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4575 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 4576 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4577 | |
| 4578 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4579 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 4580 | ds_pool_ci.pNext = NULL; |
| 4581 | ds_pool_ci.flags = 0; |
| 4582 | ds_pool_ci.maxSets = 1; |
| 4583 | ds_pool_ci.poolSizeCount = 1; |
| 4584 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4585 | |
| 4586 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4587 | err = |
| 4588 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4589 | ASSERT_VK_SUCCESS(err); |
| 4590 | |
| 4591 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4592 | dsl_binding.binding = 0; |
| 4593 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4594 | dsl_binding.descriptorCount = 1; |
| 4595 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 4596 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4597 | |
| 4598 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4599 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4600 | ds_layout_ci.pNext = NULL; |
| 4601 | ds_layout_ci.bindingCount = 1; |
| 4602 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4603 | |
| 4604 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4605 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 4606 | &ds_layout); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4607 | ASSERT_VK_SUCCESS(err); |
| 4608 | |
| 4609 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 4610 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 4611 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4612 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 4613 | alloc_info.descriptorPool = ds_pool; |
| 4614 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4615 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 4616 | &descriptorSet); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4617 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4618 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4619 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 4620 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 4621 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4622 | } |
| 4623 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4624 | TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) { |
| 4625 | VkResult err; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4626 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4627 | m_errorMonitor->SetDesiredFailureMsg( |
| 4628 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4629 | "It is invalid to call vkFreeDescriptorSets() with a pool created " |
| 4630 | "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4631 | |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4632 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4633 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4634 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 4635 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4636 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4637 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4638 | |
| 4639 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4640 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 4641 | ds_pool_ci.pNext = NULL; |
| 4642 | ds_pool_ci.maxSets = 1; |
| 4643 | ds_pool_ci.poolSizeCount = 1; |
| 4644 | ds_pool_ci.flags = 0; |
| 4645 | // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means |
| 4646 | // app can only call vkResetDescriptorPool on this pool.; |
| 4647 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4648 | |
| 4649 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4650 | err = |
| 4651 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4652 | ASSERT_VK_SUCCESS(err); |
| 4653 | |
| 4654 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4655 | dsl_binding.binding = 0; |
| 4656 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4657 | dsl_binding.descriptorCount = 1; |
| 4658 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 4659 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4660 | |
| 4661 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4662 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4663 | ds_layout_ci.pNext = NULL; |
| 4664 | ds_layout_ci.bindingCount = 1; |
| 4665 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4666 | |
| 4667 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4668 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 4669 | &ds_layout); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4670 | ASSERT_VK_SUCCESS(err); |
| 4671 | |
| 4672 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 4673 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 4674 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4675 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 4676 | alloc_info.descriptorPool = ds_pool; |
| 4677 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4678 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 4679 | &descriptorSet); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4680 | ASSERT_VK_SUCCESS(err); |
| 4681 | |
| 4682 | err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4683 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4684 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 4685 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 4686 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4687 | } |
| 4688 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4689 | TEST_F(VkLayerTest, InvalidDescriptorPool) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4690 | // Attempt to clear Descriptor Pool with bad object. |
| 4691 | // ObjectTracker should catch this. |
| 4692 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4693 | "Invalid VkDescriptorPool Object 0xbaad6001"); |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4694 | uint64_t fake_pool_handle = 0xbaad6001; |
| 4695 | VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle); |
| 4696 | vkResetDescriptorPool(device(), bad_pool, 0); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4697 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4698 | } |
| 4699 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4700 | TEST_F(VkLayerTest, InvalidDescriptorSet) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4701 | // Attempt to bind an invalid Descriptor Set to a valid Command Buffer |
| 4702 | // ObjectTracker should catch this. |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4703 | // Create a valid cmd buffer |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4704 | // call vkCmdBindDescriptorSets w/ false Descriptor Set |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4705 | |
| 4706 | uint64_t fake_set_handle = 0xbaad6001; |
| 4707 | VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4708 | VkResult err; |
| 4709 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4710 | "Invalid VkDescriptorSet Object 0xbaad6001"); |
| 4711 | |
| 4712 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4713 | |
| 4714 | VkDescriptorSetLayoutBinding layout_bindings[1] = {}; |
| 4715 | layout_bindings[0].binding = 0; |
| 4716 | layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4717 | layout_bindings[0].descriptorCount = 1; |
| 4718 | layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; |
| 4719 | layout_bindings[0].pImmutableSamplers = NULL; |
| 4720 | |
| 4721 | VkDescriptorSetLayout descriptor_set_layout; |
| 4722 | VkDescriptorSetLayoutCreateInfo dslci = {}; |
| 4723 | dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4724 | dslci.pNext = NULL; |
| 4725 | dslci.bindingCount = 1; |
| 4726 | dslci.pBindings = layout_bindings; |
| 4727 | err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout); |
Karl Schultz | 5cb2111 | 2016-04-21 17:17:40 -0600 | [diff] [blame] | 4728 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4729 | |
| 4730 | VkPipelineLayout pipeline_layout; |
| 4731 | VkPipelineLayoutCreateInfo plci = {}; |
| 4732 | plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 4733 | plci.pNext = NULL; |
| 4734 | plci.setLayoutCount = 1; |
| 4735 | plci.pSetLayouts = &descriptor_set_layout; |
| 4736 | err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout); |
Karl Schultz | 5cb2111 | 2016-04-21 17:17:40 -0600 | [diff] [blame] | 4737 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4738 | |
| 4739 | BeginCommandBuffer(); |
| 4740 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4741 | pipeline_layout, 0, 1, &bad_set, 0, NULL); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4742 | m_errorMonitor->VerifyFound(); |
| 4743 | EndCommandBuffer(); |
| 4744 | vkDestroyPipelineLayout(device(), pipeline_layout, NULL); |
| 4745 | vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4746 | } |
| 4747 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4748 | TEST_F(VkLayerTest, InvalidDescriptorSetLayout) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4749 | // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout. |
| 4750 | // ObjectTracker should catch this. |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4751 | uint64_t fake_layout_handle = 0xbaad6001; |
| 4752 | VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4753 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4754 | "Invalid VkDescriptorSetLayout Object 0xbaad6001"); |
| 4755 | |
| 4756 | VkPipelineLayout pipeline_layout; |
| 4757 | VkPipelineLayoutCreateInfo plci = {}; |
| 4758 | plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 4759 | plci.pNext = NULL; |
| 4760 | plci.setLayoutCount = 1; |
| 4761 | plci.pSetLayouts = &bad_layout; |
| 4762 | vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout); |
| 4763 | |
| 4764 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4765 | } |
| 4766 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4767 | TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) { |
| 4768 | TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec " |
| 4769 | "1) A uniform buffer update must have a valid buffer index." |
| 4770 | "2) When using an array of descriptors in a single WriteDescriptor," |
| 4771 | " the descriptor types and stageflags must all be the same." |
| 4772 | "3) Immutable Sampler state must match across descriptors"); |
| 4773 | |
| 4774 | const char *invalid_BufferInfo_ErrorMessage = |
| 4775 | "vkUpdateDescriptorSets: if pDescriptorWrites[0].descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, " |
| 4776 | "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or " |
| 4777 | "VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pDescriptorWrites[0].pBufferInfo must not be NULL"; |
| 4778 | const char *stateFlag_ErrorMessage = |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 4779 | "Attempting write update to descriptor set "; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4780 | const char *immutable_ErrorMessage = |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 4781 | "Attempting write update to descriptor set "; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4782 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4783 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_BufferInfo_ErrorMessage); |
| 4784 | |
| 4785 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4786 | VkDescriptorPoolSize ds_type_count[4] = {}; |
| 4787 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4788 | ds_type_count[0].descriptorCount = 1; |
| 4789 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 4790 | ds_type_count[1].descriptorCount = 1; |
| 4791 | ds_type_count[2].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 4792 | ds_type_count[2].descriptorCount = 1; |
| 4793 | ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 4794 | ds_type_count[3].descriptorCount = 1; |
| 4795 | |
| 4796 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 4797 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 4798 | ds_pool_ci.maxSets = 1; |
| 4799 | ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize); |
| 4800 | ds_pool_ci.pPoolSizes = ds_type_count; |
| 4801 | |
| 4802 | VkDescriptorPool ds_pool; |
| 4803 | VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 4804 | ASSERT_VK_SUCCESS(err); |
| 4805 | |
Mark Mueller | b989672 | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 4806 | VkDescriptorSetLayoutBinding layout_binding[3] = {}; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4807 | layout_binding[0].binding = 0; |
| 4808 | layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4809 | layout_binding[0].descriptorCount = 1; |
| 4810 | layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 4811 | layout_binding[0].pImmutableSamplers = NULL; |
| 4812 | |
| 4813 | layout_binding[1].binding = 1; |
| 4814 | layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 4815 | layout_binding[1].descriptorCount = 1; |
| 4816 | layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; |
| 4817 | layout_binding[1].pImmutableSamplers = NULL; |
| 4818 | |
| 4819 | VkSamplerCreateInfo sampler_ci = {}; |
| 4820 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 4821 | sampler_ci.pNext = NULL; |
| 4822 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 4823 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 4824 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 4825 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 4826 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 4827 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 4828 | sampler_ci.mipLodBias = 1.0; |
| 4829 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 4830 | sampler_ci.maxAnisotropy = 1; |
| 4831 | sampler_ci.compareEnable = VK_FALSE; |
| 4832 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 4833 | sampler_ci.minLod = 1.0; |
| 4834 | sampler_ci.maxLod = 1.0; |
| 4835 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 4836 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
| 4837 | VkSampler sampler; |
| 4838 | |
| 4839 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
| 4840 | ASSERT_VK_SUCCESS(err); |
| 4841 | |
| 4842 | layout_binding[2].binding = 2; |
| 4843 | layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 4844 | layout_binding[2].descriptorCount = 1; |
| 4845 | layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; |
| 4846 | layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler); |
| 4847 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4848 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 4849 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4850 | ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding); |
| 4851 | ds_layout_ci.pBindings = layout_binding; |
| 4852 | VkDescriptorSetLayout ds_layout; |
| 4853 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout); |
| 4854 | ASSERT_VK_SUCCESS(err); |
| 4855 | |
| 4856 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 4857 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 4858 | alloc_info.descriptorSetCount = 1; |
| 4859 | alloc_info.descriptorPool = ds_pool; |
| 4860 | alloc_info.pSetLayouts = &ds_layout; |
| 4861 | VkDescriptorSet descriptorSet; |
| 4862 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet); |
| 4863 | ASSERT_VK_SUCCESS(err); |
| 4864 | |
| 4865 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 4866 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 4867 | pipeline_layout_ci.pNext = NULL; |
| 4868 | pipeline_layout_ci.setLayoutCount = 1; |
| 4869 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 4870 | |
| 4871 | VkPipelineLayout pipeline_layout; |
| 4872 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout); |
| 4873 | ASSERT_VK_SUCCESS(err); |
| 4874 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 4875 | VkWriteDescriptorSet descriptor_write = {}; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4876 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 4877 | descriptor_write.dstSet = descriptorSet; |
| 4878 | descriptor_write.dstBinding = 0; |
| 4879 | descriptor_write.descriptorCount = 1; |
| 4880 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4881 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 4882 | // 1) The uniform buffer is intentionally invalid here |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4883 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 4884 | m_errorMonitor->VerifyFound(); |
| 4885 | |
| 4886 | // Create a buffer to update the descriptor with |
| 4887 | uint32_t qfi = 0; |
| 4888 | VkBufferCreateInfo buffCI = {}; |
| 4889 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 4890 | buffCI.size = 1024; |
| 4891 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 4892 | buffCI.queueFamilyIndexCount = 1; |
| 4893 | buffCI.pQueueFamilyIndices = &qfi; |
| 4894 | |
| 4895 | VkBuffer dyub; |
| 4896 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 4897 | ASSERT_VK_SUCCESS(err); |
| 4898 | VkDescriptorBufferInfo buffInfo = {}; |
| 4899 | buffInfo.buffer = dyub; |
| 4900 | buffInfo.offset = 0; |
| 4901 | buffInfo.range = 1024; |
| 4902 | |
| 4903 | descriptor_write.pBufferInfo = &buffInfo; |
| 4904 | descriptor_write.descriptorCount = 2; |
| 4905 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 4906 | // 2) The stateFlags don't match between the first and second descriptor |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4907 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, stateFlag_ErrorMessage); |
| 4908 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 4909 | m_errorMonitor->VerifyFound(); |
| 4910 | |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 4911 | // 3) The second descriptor has a null_ptr pImmutableSamplers and |
| 4912 | // the third descriptor contains an immutable sampler |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4913 | descriptor_write.dstBinding = 1; |
| 4914 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Mark Mueller | 5c838ce | 2016-06-16 09:54:29 -0600 | [diff] [blame] | 4915 | |
| 4916 | |
| 4917 | // Make pImageInfo index non-null to avoid complaints of it missing |
| 4918 | VkDescriptorImageInfo imageInfo = {}; |
| 4919 | imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 4920 | descriptor_write.pImageInfo = &imageInfo; |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4921 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, immutable_ErrorMessage); |
| 4922 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 4923 | m_errorMonitor->VerifyFound(); |
| 4924 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 4925 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
| 4926 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 4927 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 4928 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 4929 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 4930 | } |
| 4931 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4932 | TEST_F(VkLayerTest, InvalidPipeline) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4933 | // Attempt to bind an invalid Pipeline to a valid Command Buffer |
| 4934 | // ObjectTracker should catch this. |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4935 | // Create a valid cmd buffer |
| 4936 | // call vkCmdBindPipeline w/ false Pipeline |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4937 | uint64_t fake_pipeline_handle = 0xbaad6001; |
| 4938 | VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4939 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4940 | "Invalid VkPipeline Object 0xbaad6001"); |
| 4941 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4942 | BeginCommandBuffer(); |
| 4943 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 4944 | VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline); |
| 4945 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 4946 | // Now issue a draw call with no pipeline bound |
| 4947 | m_errorMonitor->SetDesiredFailureMsg( |
| 4948 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4949 | "At Draw/Dispatch time no valid VkPipeline is bound!"); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 4950 | |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 4951 | BeginCommandBuffer(); |
| 4952 | Draw(1, 0, 0, 0); |
| 4953 | m_errorMonitor->VerifyFound(); |
| 4954 | // Finally same check once more but with Dispatch/Compute |
| 4955 | m_errorMonitor->SetDesiredFailureMsg( |
| 4956 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4957 | "At Draw/Dispatch time no valid VkPipeline is bound!"); |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 4958 | BeginCommandBuffer(); |
| 4959 | vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0); |
| 4960 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4961 | } |
| 4962 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4963 | TEST_F(VkLayerTest, DescriptorSetNotUpdated) { |
| 4964 | // Create and update CommandBuffer then call QueueSubmit w/o calling End on |
| 4965 | // CommandBuffer |
| 4966 | VkResult err; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 4967 | |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 4968 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4969 | " bound but it was never updated. "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4970 | |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 4971 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 4972 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 4973 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 4974 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4975 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4976 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 4977 | |
| 4978 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4979 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 4980 | ds_pool_ci.pNext = NULL; |
| 4981 | ds_pool_ci.maxSets = 1; |
| 4982 | ds_pool_ci.poolSizeCount = 1; |
| 4983 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 4984 | |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 4985 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4986 | err = |
| 4987 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 4988 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 4989 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 4990 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4991 | dsl_binding.binding = 0; |
| 4992 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4993 | dsl_binding.descriptorCount = 1; |
| 4994 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 4995 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 4996 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 4997 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4998 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4999 | ds_layout_ci.pNext = NULL; |
| 5000 | ds_layout_ci.bindingCount = 1; |
| 5001 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5002 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5003 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5004 | &ds_layout); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5005 | ASSERT_VK_SUCCESS(err); |
| 5006 | |
| 5007 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5008 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5009 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5010 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 5011 | alloc_info.descriptorPool = ds_pool; |
| 5012 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5013 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5014 | &descriptorSet); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5015 | ASSERT_VK_SUCCESS(err); |
| 5016 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5017 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5018 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5019 | pipeline_layout_ci.pNext = NULL; |
| 5020 | pipeline_layout_ci.setLayoutCount = 1; |
| 5021 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5022 | |
| 5023 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5024 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5025 | &pipeline_layout); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5026 | ASSERT_VK_SUCCESS(err); |
| 5027 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5028 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 5029 | VK_SHADER_STAGE_VERTEX_BIT, this); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5030 | // 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] | 5031 | // on more devices |
| 5032 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 5033 | VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5034 | |
Tony Barbour | c95e4ac | 2015-08-04 17:05:26 -0600 | [diff] [blame] | 5035 | VkPipelineObj pipe(m_device); |
| 5036 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 5037 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 5038 | pipe.AddColorAttachment(); |
Tony Barbour | c95e4ac | 2015-08-04 17:05:26 -0600 | [diff] [blame] | 5039 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 5040 | |
| 5041 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5042 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 5043 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 5044 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5045 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5046 | 1, &descriptorSet, 0, NULL); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5047 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5048 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 5049 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 5050 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5051 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5052 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 5053 | } |
| 5054 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5055 | TEST_F(VkLayerTest, InvalidBufferViewObject) { |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5056 | // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5057 | VkResult err; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5058 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5059 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5060 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer " |
| 5061 | "descriptor with invalid buffer view"); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5062 | |
| 5063 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5064 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5065 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5066 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5067 | |
| 5068 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5069 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5070 | ds_pool_ci.pNext = NULL; |
| 5071 | ds_pool_ci.maxSets = 1; |
| 5072 | ds_pool_ci.poolSizeCount = 1; |
| 5073 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5074 | |
| 5075 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5076 | err = |
| 5077 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5078 | ASSERT_VK_SUCCESS(err); |
| 5079 | |
| 5080 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5081 | dsl_binding.binding = 0; |
| 5082 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5083 | dsl_binding.descriptorCount = 1; |
| 5084 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5085 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5086 | |
| 5087 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5088 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5089 | ds_layout_ci.pNext = NULL; |
| 5090 | ds_layout_ci.bindingCount = 1; |
| 5091 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5092 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5093 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5094 | &ds_layout); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5095 | ASSERT_VK_SUCCESS(err); |
| 5096 | |
| 5097 | VkDescriptorSet descriptorSet; |
| 5098 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5099 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5100 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5101 | alloc_info.descriptorPool = ds_pool; |
| 5102 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5103 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5104 | &descriptorSet); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5105 | ASSERT_VK_SUCCESS(err); |
| 5106 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5107 | VkBufferView view = |
| 5108 | (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5109 | VkWriteDescriptorSet descriptor_write; |
| 5110 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 5111 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5112 | descriptor_write.dstSet = descriptorSet; |
| 5113 | descriptor_write.dstBinding = 0; |
| 5114 | descriptor_write.descriptorCount = 1; |
| 5115 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 5116 | descriptor_write.pTexelBufferView = &view; |
| 5117 | |
| 5118 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5119 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5120 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 5121 | |
| 5122 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5123 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 5124 | } |
| 5125 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5126 | TEST_F(VkLayerTest, InvalidDynamicOffsetCases) { |
| 5127 | // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error |
| 5128 | // cases: |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5129 | // 1. No dynamicOffset supplied |
| 5130 | // 2. Too many dynamicOffsets supplied |
| 5131 | // 3. Dynamic offset oversteps buffer being updated |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5132 | VkResult err; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 5133 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5134 | " requires 1 dynamicOffsets, but only " |
| 5135 | "0 dynamicOffsets are left in " |
| 5136 | "pDynamicOffsets "); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5137 | |
| 5138 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5139 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5140 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5141 | |
| 5142 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5143 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 5144 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5145 | |
| 5146 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5147 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5148 | ds_pool_ci.pNext = NULL; |
| 5149 | ds_pool_ci.maxSets = 1; |
| 5150 | ds_pool_ci.poolSizeCount = 1; |
| 5151 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5152 | |
| 5153 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5154 | err = |
| 5155 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5156 | ASSERT_VK_SUCCESS(err); |
| 5157 | |
| 5158 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5159 | dsl_binding.binding = 0; |
| 5160 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 5161 | dsl_binding.descriptorCount = 1; |
| 5162 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5163 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5164 | |
| 5165 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5166 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5167 | ds_layout_ci.pNext = NULL; |
| 5168 | ds_layout_ci.bindingCount = 1; |
| 5169 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5170 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5171 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5172 | &ds_layout); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5173 | ASSERT_VK_SUCCESS(err); |
| 5174 | |
| 5175 | VkDescriptorSet descriptorSet; |
| 5176 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5177 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5178 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5179 | alloc_info.descriptorPool = ds_pool; |
| 5180 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5181 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5182 | &descriptorSet); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5183 | ASSERT_VK_SUCCESS(err); |
| 5184 | |
| 5185 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5186 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5187 | pipeline_layout_ci.pNext = NULL; |
| 5188 | pipeline_layout_ci.setLayoutCount = 1; |
| 5189 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5190 | |
| 5191 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5192 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5193 | &pipeline_layout); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5194 | ASSERT_VK_SUCCESS(err); |
| 5195 | |
| 5196 | // Create a buffer to update the descriptor with |
| 5197 | uint32_t qfi = 0; |
| 5198 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5199 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 5200 | buffCI.size = 1024; |
| 5201 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 5202 | buffCI.queueFamilyIndexCount = 1; |
| 5203 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5204 | |
| 5205 | VkBuffer dyub; |
| 5206 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 5207 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5208 | // Allocate memory and bind to buffer so we can make it to the appropriate |
| 5209 | // error |
| 5210 | VkMemoryAllocateInfo mem_alloc = {}; |
| 5211 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 5212 | mem_alloc.pNext = NULL; |
| 5213 | mem_alloc.allocationSize = 1024; |
Chris Forbes | b6116cc | 2016-05-08 11:39:59 +1200 | [diff] [blame] | 5214 | mem_alloc.memoryTypeIndex = 0; |
| 5215 | |
| 5216 | VkMemoryRequirements memReqs; |
| 5217 | vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs); |
| 5218 | bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, |
| 5219 | 0); |
| 5220 | if (!pass) { |
| 5221 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
| 5222 | return; |
| 5223 | } |
| 5224 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5225 | VkDeviceMemory mem; |
| 5226 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 5227 | ASSERT_VK_SUCCESS(err); |
| 5228 | err = vkBindBufferMemory(m_device->device(), dyub, mem, 0); |
| 5229 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5230 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 5231 | VkDescriptorBufferInfo buffInfo = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5232 | buffInfo.buffer = dyub; |
| 5233 | buffInfo.offset = 0; |
| 5234 | buffInfo.range = 1024; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5235 | |
| 5236 | VkWriteDescriptorSet descriptor_write; |
| 5237 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 5238 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5239 | descriptor_write.dstSet = descriptorSet; |
| 5240 | descriptor_write.dstBinding = 0; |
| 5241 | descriptor_write.descriptorCount = 1; |
| 5242 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 5243 | descriptor_write.pBufferInfo = &buffInfo; |
| 5244 | |
| 5245 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 5246 | |
| 5247 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5248 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5249 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5250 | 1, &descriptorSet, 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5251 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5252 | uint32_t pDynOff[2] = {512, 756}; |
| 5253 | // 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] | 5254 | m_errorMonitor->SetDesiredFailureMsg( |
| 5255 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5256 | "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5257 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5258 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5259 | 1, &descriptorSet, 2, pDynOff); |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5260 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5261 | // Finally cause error due to dynamicOffset being too big |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5262 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5263 | " dynamic offset 512 combined with " |
| 5264 | "offset 0 and range 1024 that " |
| 5265 | "oversteps the buffer size of 1024"); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5266 | // Create PSO to be used for draw-time errors below |
| 5267 | char const *vsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5268 | "#version 450\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5269 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 5270 | "out gl_PerVertex { \n" |
| 5271 | " vec4 gl_Position;\n" |
| 5272 | "};\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5273 | "void main(){\n" |
| 5274 | " gl_Position = vec4(1);\n" |
| 5275 | "}\n"; |
| 5276 | char const *fsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5277 | "#version 450\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5278 | "\n" |
| 5279 | "layout(location=0) out vec4 x;\n" |
| 5280 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 5281 | "void main(){\n" |
| 5282 | " x = vec4(bar.y);\n" |
| 5283 | "}\n"; |
| 5284 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 5285 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 5286 | VkPipelineObj pipe(m_device); |
| 5287 | pipe.AddShader(&vs); |
| 5288 | pipe.AddShader(&fs); |
| 5289 | pipe.AddColorAttachment(); |
| 5290 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 5291 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5292 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 5293 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 5294 | // This update should succeed, but offset size of 512 will overstep buffer |
| 5295 | // /w range 1024 & size 1024 |
| 5296 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5297 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5298 | 1, &descriptorSet, 1, pDynOff); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 5299 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5300 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5301 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5302 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
Tobin Ehlis | 512098e | 2016-05-05 09:06:12 -0600 | [diff] [blame] | 5303 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5304 | |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5305 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 5306 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 5307 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 5308 | } |
| 5309 | |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5310 | TEST_F(VkLayerTest, InvalidPushConstants) { |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5311 | VkResult err; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5312 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5313 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5314 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5315 | |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5316 | VkPipelineLayout pipeline_layout; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5317 | VkPushConstantRange pc_range = {}; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5318 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 5319 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5320 | pipeline_layout_ci.pushConstantRangeCount = 1; |
| 5321 | pipeline_layout_ci.pPushConstantRanges = &pc_range; |
| 5322 | |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5323 | // |
| 5324 | // Check for invalid push constant ranges in pipeline layouts. |
| 5325 | // |
| 5326 | struct PipelineLayoutTestCase { |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5327 | VkPushConstantRange const range; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5328 | char const *msg; |
| 5329 | }; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5330 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5331 | const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4; |
| 5332 | const std::array<PipelineLayoutTestCase, 10> range_tests = {{ |
| 5333 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, |
| 5334 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5335 | "size 0."}, |
| 5336 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1}, |
| 5337 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5338 | "size 1."}, |
| 5339 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1}, |
| 5340 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5341 | "size 1."}, |
| 5342 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0}, |
| 5343 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5344 | "size 0."}, |
| 5345 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4}, |
| 5346 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 5347 | "offset 1. Offset must"}, |
| 5348 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big}, |
| 5349 | "vkCreatePipelineLayout() call has push constants index 0 " |
| 5350 | "with offset "}, |
| 5351 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big}, |
| 5352 | "vkCreatePipelineLayout() call has push constants " |
| 5353 | "index 0 with offset "}, |
| 5354 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0}, |
| 5355 | "vkCreatePipelineLayout() call has push constants index 0 " |
| 5356 | "with offset "}, |
| 5357 | {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020}, |
| 5358 | "vkCreatePipelineLayout() call has push " |
| 5359 | "constants index 0 with offset "}, |
| 5360 | {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0}, |
| 5361 | "vkCreatePipelineLayout() call has push " |
| 5362 | "constants index 0 with offset "}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5363 | }}; |
| 5364 | |
| 5365 | // Check for invalid offset and size |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5366 | for (const auto &iter : range_tests) { |
| 5367 | pc_range = iter.range; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5368 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5369 | iter.msg); |
| 5370 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 5371 | NULL, &pipeline_layout); |
| 5372 | m_errorMonitor->VerifyFound(); |
| 5373 | if (VK_SUCCESS == err) { |
| 5374 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5375 | } |
| 5376 | } |
| 5377 | |
| 5378 | // Check for invalid stage flag |
| 5379 | pc_range.offset = 0; |
| 5380 | pc_range.size = 16; |
| 5381 | pc_range.stageFlags = 0; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5382 | m_errorMonitor->SetDesiredFailureMsg( |
| 5383 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5384 | "vkCreatePipelineLayout() call has no stageFlags set."); |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5385 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5386 | &pipeline_layout); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5387 | m_errorMonitor->VerifyFound(); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5388 | if (VK_SUCCESS == err) { |
| 5389 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5390 | } |
| 5391 | |
| 5392 | // Check for overlapping ranges |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5393 | const uint32_t ranges_per_test = 5; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5394 | struct OverlappingRangeTestCase { |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5395 | VkPushConstantRange const ranges[ranges_per_test]; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5396 | char const *msg; |
| 5397 | }; |
| 5398 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5399 | const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5400 | {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5401 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5402 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5403 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5404 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5405 | "vkCreatePipelineLayout() call has push constants with overlapping " |
| 5406 | "ranges: 0:[0, 4), 1:[0, 4)"}, |
| 5407 | { |
| 5408 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5409 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5410 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5411 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 5412 | {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}}, |
| 5413 | "vkCreatePipelineLayout() call has push constants with " |
| 5414 | "overlapping " |
| 5415 | "ranges: 3:[12, 20), 4:[16, 20)", |
| 5416 | }, |
| 5417 | { |
| 5418 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5419 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 5420 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5421 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5422 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5423 | "vkCreatePipelineLayout() call has push constants with " |
| 5424 | "overlapping " |
| 5425 | "ranges: 0:[16, 20), 1:[12, 20)", |
| 5426 | }, |
| 5427 | { |
| 5428 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5429 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5430 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5431 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 5432 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5433 | "vkCreatePipelineLayout() call has push constants with " |
| 5434 | "overlapping " |
| 5435 | "ranges: 0:[16, 20), 3:[12, 20)", |
| 5436 | }, |
| 5437 | { |
| 5438 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5439 | {VK_SHADER_STAGE_VERTEX_BIT, 32, 4}, |
| 5440 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 96}, |
| 5441 | {VK_SHADER_STAGE_VERTEX_BIT, 40, 8}, |
| 5442 | {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}}, |
| 5443 | "vkCreatePipelineLayout() call has push constants with " |
| 5444 | "overlapping " |
| 5445 | "ranges: 0:[16, 20), 2:[4, 100)", |
| 5446 | }}}; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5447 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5448 | for (const auto &iter : overlapping_range_tests) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5449 | pipeline_layout_ci.pPushConstantRanges = iter.ranges; |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5450 | pipeline_layout_ci.pushConstantRangeCount = ranges_per_test; |
| 5451 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5452 | iter.msg); |
| 5453 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 5454 | NULL, &pipeline_layout); |
| 5455 | m_errorMonitor->VerifyFound(); |
| 5456 | if (VK_SUCCESS == err) { |
| 5457 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5458 | } |
| 5459 | } |
| 5460 | |
| 5461 | // 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] | 5462 | const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = |
| 5463 | {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5464 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 5465 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 5466 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 4}, |
| 5467 | {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}}, |
| 5468 | ""}, |
| 5469 | {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24}, |
| 5470 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 4}, |
| 5471 | {VK_SHADER_STAGE_VERTEX_BIT, 64, 8}, |
| 5472 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 16}, |
| 5473 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 5474 | ""}}}; |
| 5475 | for (const auto &iter : overlapping_range_tests_pos) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5476 | pipeline_layout_ci.pPushConstantRanges = iter.ranges; |
| 5477 | m_errorMonitor->ExpectSuccess(); |
| 5478 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 5479 | NULL, &pipeline_layout); |
| 5480 | m_errorMonitor->VerifyNotFound(); |
| 5481 | if (VK_SUCCESS == err) { |
| 5482 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5483 | } |
| 5484 | } |
| 5485 | |
| 5486 | // |
| 5487 | // CmdPushConstants tests |
| 5488 | // |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5489 | const uint8_t dummy_values[100] = {}; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5490 | |
| 5491 | // 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] | 5492 | const std::array<PipelineLayoutTestCase, 16> cmd_range_tests = {{ |
| 5493 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, |
| 5494 | "vkCmdPushConstants() call has push constants with size 0. Size " |
| 5495 | "must be greater than zero and a multiple of 4."}, |
| 5496 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1}, |
| 5497 | "vkCmdPushConstants() call has push constants with size 1. Size " |
| 5498 | "must be greater than zero and a multiple of 4."}, |
| 5499 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1}, |
| 5500 | "vkCmdPushConstants() call has push constants with size 1. Size " |
| 5501 | "must be greater than zero and a multiple of 4."}, |
| 5502 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0}, |
| 5503 | "vkCmdPushConstants() call has push constants with offset 1. " |
| 5504 | "Offset must be a multiple of 4."}, |
| 5505 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4}, |
| 5506 | "vkCmdPushConstants() call has push constants with offset 1. " |
| 5507 | "Offset must be a multiple of 4."}, |
| 5508 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20}, |
| 5509 | "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = " |
| 5510 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5511 | {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8}, |
| 5512 | "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = " |
| 5513 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5514 | {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8}, |
| 5515 | "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = " |
| 5516 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5517 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80}, |
| 5518 | "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = " |
| 5519 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5520 | {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4}, |
| 5521 | "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in " |
| 5522 | "any of the ranges in pipeline layout"}, |
| 5523 | {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, |
| 5524 | 0, 16}, |
| 5525 | "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in " |
| 5526 | "any of the ranges in pipeline layout"}, |
| 5527 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5528 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5529 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5530 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5531 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5532 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5533 | {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5534 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5535 | {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5536 | "vkCmdPushConstants() call has push constants with offset "}, |
| 5537 | }}; |
| 5538 | |
| 5539 | // Two ranges for testing robustness |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5540 | const VkPushConstantRange pc_range2[] = { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5541 | {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5542 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5543 | }; |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5544 | pipeline_layout_ci.pushConstantRangeCount = |
| 5545 | sizeof(pc_range2) / sizeof(VkPushConstantRange); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5546 | pipeline_layout_ci.pPushConstantRanges = pc_range2; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5547 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5548 | &pipeline_layout); |
| 5549 | ASSERT_VK_SUCCESS(err); |
| 5550 | BeginCommandBuffer(); |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5551 | for (const auto &iter : cmd_range_tests) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5552 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5553 | iter.msg); |
| 5554 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5555 | iter.range.stageFlags, iter.range.offset, |
| 5556 | iter.range.size, dummy_values); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5557 | m_errorMonitor->VerifyFound(); |
| 5558 | } |
| 5559 | |
| 5560 | // Check for invalid stage flag |
| 5561 | m_errorMonitor->SetDesiredFailureMsg( |
| 5562 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5563 | "vkCmdPushConstants() call has no stageFlags set."); |
| 5564 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5565 | 0, 16, dummy_values); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5566 | m_errorMonitor->VerifyFound(); |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5567 | EndCommandBuffer(); |
| 5568 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
| 5569 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 5570 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 5571 | // overlapping range tests with cmd |
| 5572 | const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{ |
| 5573 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20}, |
| 5574 | "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = " |
| 5575 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5576 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 5577 | "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = " |
| 5578 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5579 | {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16}, |
| 5580 | "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = " |
| 5581 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 5582 | }}; |
| 5583 | const VkPushConstantRange pc_range3[] = { |
| 5584 | {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, |
| 5585 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
| 5586 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5587 | {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, |
| 5588 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, |
| 5589 | {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, |
| 5590 | {VK_SHADER_STAGE_VERTEX_BIT, 56, 28}, |
| 5591 | }; |
| 5592 | pipeline_layout_ci.pushConstantRangeCount = |
| 5593 | sizeof(pc_range3) / sizeof(VkPushConstantRange); |
| 5594 | pipeline_layout_ci.pPushConstantRanges = pc_range3; |
| 5595 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5596 | &pipeline_layout); |
| 5597 | ASSERT_VK_SUCCESS(err); |
| 5598 | BeginCommandBuffer(); |
| 5599 | for (const auto &iter : cmd_overlap_tests) { |
| 5600 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5601 | iter.msg); |
| 5602 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
| 5603 | iter.range.stageFlags, iter.range.offset, |
| 5604 | iter.range.size, dummy_values); |
| 5605 | m_errorMonitor->VerifyFound(); |
| 5606 | } |
| 5607 | EndCommandBuffer(); |
| 5608 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
| 5609 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5610 | |
| 5611 | // positive overlapping range tests with cmd |
| 5612 | const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{ |
| 5613 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""}, |
| 5614 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""}, |
| 5615 | {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""}, |
| 5616 | {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""}, |
| 5617 | }}; |
| 5618 | const VkPushConstantRange pc_range4[] = { |
| 5619 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 64}, |
| 5620 | {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, |
| 5621 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
| 5622 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 5623 | {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, |
| 5624 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, |
| 5625 | {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, |
| 5626 | {VK_SHADER_STAGE_VERTEX_BIT, 56, 28}, |
| 5627 | }; |
| 5628 | pipeline_layout_ci.pushConstantRangeCount = |
| 5629 | sizeof(pc_range4) / sizeof(VkPushConstantRange); |
| 5630 | pipeline_layout_ci.pPushConstantRanges = pc_range4; |
| 5631 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5632 | &pipeline_layout); |
| 5633 | ASSERT_VK_SUCCESS(err); |
| 5634 | BeginCommandBuffer(); |
| 5635 | for (const auto &iter : cmd_overlap_tests_pos) { |
| 5636 | m_errorMonitor->ExpectSuccess(); |
| 5637 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
| 5638 | iter.range.stageFlags, iter.range.offset, |
| 5639 | iter.range.size, dummy_values); |
| 5640 | m_errorMonitor->VerifyNotFound(); |
| 5641 | } |
| 5642 | EndCommandBuffer(); |
| 5643 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5644 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5645 | } |
| 5646 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5647 | TEST_F(VkLayerTest, DescriptorSetCompatibility) { |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5648 | // Test various desriptorSet errors with bad binding combinations |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5649 | VkResult err; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5650 | |
| 5651 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5652 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5653 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5654 | |
| 5655 | static const uint32_t NUM_DESCRIPTOR_TYPES = 5; |
| 5656 | VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5657 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5658 | ds_type_count[0].descriptorCount = 10; |
| 5659 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 5660 | ds_type_count[1].descriptorCount = 2; |
| 5661 | ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
| 5662 | ds_type_count[2].descriptorCount = 2; |
| 5663 | ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 5664 | ds_type_count[3].descriptorCount = 5; |
| 5665 | // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT |
| 5666 | // type |
| 5667 | // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 5668 | ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
| 5669 | ds_type_count[4].descriptorCount = 2; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5670 | |
| 5671 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5672 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5673 | ds_pool_ci.pNext = NULL; |
| 5674 | ds_pool_ci.maxSets = 5; |
| 5675 | ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES; |
| 5676 | ds_pool_ci.pPoolSizes = ds_type_count; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5677 | |
| 5678 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5679 | err = |
| 5680 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5681 | ASSERT_VK_SUCCESS(err); |
| 5682 | |
| 5683 | static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2; |
| 5684 | VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5685 | dsl_binding[0].binding = 0; |
| 5686 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5687 | dsl_binding[0].descriptorCount = 5; |
| 5688 | dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 5689 | dsl_binding[0].pImmutableSamplers = NULL; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5690 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5691 | // Create layout identical to set0 layout but w/ different stageFlags |
| 5692 | VkDescriptorSetLayoutBinding dsl_fs_stage_only = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5693 | dsl_fs_stage_only.binding = 0; |
| 5694 | dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5695 | dsl_fs_stage_only.descriptorCount = 5; |
| 5696 | dsl_fs_stage_only.stageFlags = |
| 5697 | VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at |
| 5698 | // bind time |
| 5699 | dsl_fs_stage_only.pImmutableSamplers = NULL; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5700 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5701 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5702 | ds_layout_ci.pNext = NULL; |
| 5703 | ds_layout_ci.bindingCount = 1; |
| 5704 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5705 | static const uint32_t NUM_LAYOUTS = 4; |
| 5706 | VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5707 | VkDescriptorSetLayout ds_layout_fs_only = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5708 | // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only |
| 5709 | // layout for error case |
| 5710 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5711 | &ds_layout[0]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5712 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 5713 | ds_layout_ci.pBindings = &dsl_fs_stage_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5714 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5715 | &ds_layout_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5716 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5717 | dsl_binding[0].binding = 0; |
| 5718 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5719 | dsl_binding[0].descriptorCount = 2; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 5720 | dsl_binding[1].binding = 1; |
| 5721 | dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
| 5722 | dsl_binding[1].descriptorCount = 2; |
| 5723 | dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL; |
| 5724 | dsl_binding[1].pImmutableSamplers = NULL; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 5725 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5726 | ds_layout_ci.bindingCount = 2; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5727 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5728 | &ds_layout[1]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5729 | ASSERT_VK_SUCCESS(err); |
| 5730 | dsl_binding[0].binding = 0; |
| 5731 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5732 | dsl_binding[0].descriptorCount = 5; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5733 | ds_layout_ci.bindingCount = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5734 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5735 | &ds_layout[2]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5736 | ASSERT_VK_SUCCESS(err); |
| 5737 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5738 | dsl_binding[0].descriptorCount = 2; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5739 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5740 | &ds_layout[3]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5741 | ASSERT_VK_SUCCESS(err); |
| 5742 | |
| 5743 | static const uint32_t NUM_SETS = 4; |
| 5744 | VkDescriptorSet descriptorSet[NUM_SETS] = {}; |
| 5745 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5746 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5747 | alloc_info.descriptorSetCount = NUM_LAYOUTS; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5748 | alloc_info.descriptorPool = ds_pool; |
| 5749 | alloc_info.pSetLayouts = ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5750 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5751 | descriptorSet); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5752 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5753 | VkDescriptorSet ds0_fs_only = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5754 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5755 | alloc_info.pSetLayouts = &ds_layout_fs_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5756 | err = |
| 5757 | vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5758 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5759 | |
| 5760 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5761 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5762 | pipeline_layout_ci.pNext = NULL; |
| 5763 | pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS; |
| 5764 | pipeline_layout_ci.pSetLayouts = ds_layout; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5765 | |
| 5766 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5767 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5768 | &pipeline_layout); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5769 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5770 | // Create pipelineLayout with only one setLayout |
| 5771 | pipeline_layout_ci.setLayoutCount = 1; |
| 5772 | VkPipelineLayout single_pipe_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5773 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5774 | &single_pipe_layout); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5775 | ASSERT_VK_SUCCESS(err); |
| 5776 | // Create pipelineLayout with 2 descriptor setLayout at index 0 |
| 5777 | pipeline_layout_ci.pSetLayouts = &ds_layout[3]; |
| 5778 | VkPipelineLayout pipe_layout_one_desc; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5779 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5780 | &pipe_layout_one_desc); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5781 | ASSERT_VK_SUCCESS(err); |
| 5782 | // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0 |
| 5783 | pipeline_layout_ci.pSetLayouts = &ds_layout[2]; |
| 5784 | VkPipelineLayout pipe_layout_five_samp; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5785 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5786 | &pipe_layout_five_samp); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5787 | ASSERT_VK_SUCCESS(err); |
| 5788 | // Create pipelineLayout with UB type, but stageFlags for FS only |
| 5789 | pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only; |
| 5790 | VkPipelineLayout pipe_layout_fs_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5791 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5792 | &pipe_layout_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5793 | ASSERT_VK_SUCCESS(err); |
| 5794 | // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine |
| 5795 | VkDescriptorSetLayout pl_bad_s0[2] = {}; |
| 5796 | pl_bad_s0[0] = ds_layout_fs_only; |
| 5797 | pl_bad_s0[1] = ds_layout[1]; |
| 5798 | pipeline_layout_ci.setLayoutCount = 2; |
| 5799 | pipeline_layout_ci.pSetLayouts = pl_bad_s0; |
| 5800 | VkPipelineLayout pipe_layout_bad_set0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5801 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5802 | &pipe_layout_bad_set0); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5803 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5804 | |
| 5805 | // Create a buffer to update the descriptor with |
| 5806 | uint32_t qfi = 0; |
| 5807 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5808 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 5809 | buffCI.size = 1024; |
| 5810 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 5811 | buffCI.queueFamilyIndexCount = 1; |
| 5812 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5813 | |
| 5814 | VkBuffer dyub; |
| 5815 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 5816 | ASSERT_VK_SUCCESS(err); |
| 5817 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 5818 | static const uint32_t NUM_BUFFS = 5; |
| 5819 | VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5820 | for (uint32_t i = 0; i < NUM_BUFFS; ++i) { |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5821 | buffInfo[i].buffer = dyub; |
| 5822 | buffInfo[i].offset = 0; |
| 5823 | buffInfo[i].range = 1024; |
| 5824 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5825 | VkImage image; |
| 5826 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 5827 | const int32_t tex_width = 32; |
| 5828 | const int32_t tex_height = 32; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5829 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5830 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 5831 | image_create_info.pNext = NULL; |
| 5832 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 5833 | image_create_info.format = tex_format; |
| 5834 | image_create_info.extent.width = tex_width; |
| 5835 | image_create_info.extent.height = tex_height; |
| 5836 | image_create_info.extent.depth = 1; |
| 5837 | image_create_info.mipLevels = 1; |
| 5838 | image_create_info.arrayLayers = 1; |
| 5839 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 5840 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 5841 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 5842 | image_create_info.flags = 0; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5843 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 5844 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5845 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5846 | VkMemoryRequirements memReqs; |
| 5847 | VkDeviceMemory imageMem; |
| 5848 | bool pass; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 5849 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5850 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 5851 | memAlloc.pNext = NULL; |
| 5852 | memAlloc.allocationSize = 0; |
| 5853 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 5854 | vkGetImageMemoryRequirements(m_device->device(), image, &memReqs); |
| 5855 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5856 | pass = |
| 5857 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 5858 | ASSERT_TRUE(pass); |
| 5859 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem); |
| 5860 | ASSERT_VK_SUCCESS(err); |
| 5861 | err = vkBindImageMemory(m_device->device(), image, imageMem, 0); |
| 5862 | ASSERT_VK_SUCCESS(err); |
| 5863 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5864 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5865 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 5866 | image_view_create_info.image = image; |
| 5867 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 5868 | image_view_create_info.format = tex_format; |
| 5869 | image_view_create_info.subresourceRange.layerCount = 1; |
| 5870 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 5871 | image_view_create_info.subresourceRange.levelCount = 1; |
| 5872 | image_view_create_info.subresourceRange.aspectMask = |
| 5873 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5874 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5875 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5876 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 5877 | &view); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5878 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 5879 | VkDescriptorImageInfo imageInfo[4] = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5880 | imageInfo[0].imageView = view; |
| 5881 | imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 5882 | imageInfo[1].imageView = view; |
| 5883 | imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 5884 | imageInfo[2].imageView = view; |
| 5885 | imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 5886 | imageInfo[3].imageView = view; |
| 5887 | imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5888 | |
| 5889 | static const uint32_t NUM_SET_UPDATES = 3; |
| 5890 | VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {}; |
| 5891 | descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5892 | descriptor_write[0].dstSet = descriptorSet[0]; |
| 5893 | descriptor_write[0].dstBinding = 0; |
| 5894 | descriptor_write[0].descriptorCount = 5; |
| 5895 | descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5896 | descriptor_write[0].pBufferInfo = buffInfo; |
| 5897 | descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5898 | descriptor_write[1].dstSet = descriptorSet[1]; |
| 5899 | descriptor_write[1].dstBinding = 0; |
| 5900 | descriptor_write[1].descriptorCount = 2; |
| 5901 | descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 5902 | descriptor_write[1].pImageInfo = imageInfo; |
| 5903 | descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5904 | descriptor_write[2].dstSet = descriptorSet[1]; |
| 5905 | descriptor_write[2].dstBinding = 1; |
| 5906 | descriptor_write[2].descriptorCount = 2; |
| 5907 | descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 5908 | descriptor_write[2].pImageInfo = &imageInfo[2]; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5909 | |
| 5910 | vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5911 | |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 5912 | // Create PSO to be used for draw-time errors below |
| 5913 | char const *vsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5914 | "#version 450\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 5915 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 5916 | "out gl_PerVertex {\n" |
| 5917 | " vec4 gl_Position;\n" |
| 5918 | "};\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 5919 | "void main(){\n" |
| 5920 | " gl_Position = vec4(1);\n" |
| 5921 | "}\n"; |
| 5922 | char const *fsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5923 | "#version 450\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 5924 | "\n" |
| 5925 | "layout(location=0) out vec4 x;\n" |
| 5926 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 5927 | "void main(){\n" |
| 5928 | " x = vec4(bar.y);\n" |
| 5929 | "}\n"; |
| 5930 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 5931 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5932 | VkPipelineObj pipe(m_device); |
| 5933 | pipe.AddShader(&vs); |
| 5934 | pipe.AddShader(&fs); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 5935 | pipe.AddColorAttachment(); |
| 5936 | pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass()); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5937 | |
| 5938 | BeginCommandBuffer(); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 5939 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5940 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 5941 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 5942 | // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding |
| 5943 | // of PSO |
| 5944 | // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of |
| 5945 | // cmd_pipeline.c |
| 5946 | // due to the fact that cmd_alloc_dset_data() has not been called in |
| 5947 | // cmd_bind_graphics_pipeline() |
| 5948 | // TODO : Want to cause various binding incompatibility issues here to test |
| 5949 | // DrawState |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5950 | // First cause various verify_layout_compatibility() fails |
| 5951 | // Second disturb early and late sets and verify INFO msgs |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5952 | // verify_set_layout_compatibility fail cases: |
| 5953 | // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5954 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5955 | " due to: invalid VkPipelineLayout "); |
| 5956 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5957 | VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 5958 | (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, |
| 5959 | &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5960 | m_errorMonitor->VerifyFound(); |
| 5961 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5962 | // 2. layoutIndex exceeds # of layouts in layout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5963 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5964 | " attempting to bind set to index 1"); |
| 5965 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5966 | VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, |
| 5967 | 0, 2, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5968 | m_errorMonitor->VerifyFound(); |
| 5969 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5970 | vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5971 | // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5 |
| 5972 | // descriptors |
| 5973 | m_errorMonitor->SetDesiredFailureMsg( |
| 5974 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 5975 | " has 2 descriptors, but DescriptorSetLayout "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5976 | vkCmdBindDescriptorSets( |
| 5977 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 5978 | pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5979 | m_errorMonitor->VerifyFound(); |
| 5980 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5981 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL); |
| 5982 | // 4. same # of descriptors but mismatch in type |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5983 | m_errorMonitor->SetDesiredFailureMsg( |
| 5984 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 5985 | " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5986 | vkCmdBindDescriptorSets( |
| 5987 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 5988 | pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5989 | m_errorMonitor->VerifyFound(); |
| 5990 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5991 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL); |
| 5992 | // 5. same # of descriptors but mismatch in stageFlags |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5993 | m_errorMonitor->SetDesiredFailureMsg( |
| 5994 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 5995 | " has stageFlags 16 but binding 0 for DescriptorSetLayout "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5996 | vkCmdBindDescriptorSets( |
| 5997 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 5998 | pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5999 | m_errorMonitor->VerifyFound(); |
| 6000 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6001 | // Cause INFO messages due to disturbing previously bound Sets |
| 6002 | // First bind sets 0 & 1 |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6003 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6004 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6005 | 2, &descriptorSet[0], 0, NULL); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6006 | // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6007 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 6008 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6009 | " previously bound as set #0 was disturbed "); |
| 6010 | vkCmdBindDescriptorSets( |
| 6011 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6012 | pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6013 | m_errorMonitor->VerifyFound(); |
| 6014 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6015 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6016 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6017 | 2, &descriptorSet[0], 0, NULL); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6018 | // 2. Disturb set after last bound set |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 6019 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6020 | " newly bound as set #0 so set #1 and " |
| 6021 | "any subsequent sets were disturbed "); |
| 6022 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6023 | VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6024 | pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6025 | m_errorMonitor->VerifyFound(); |
| 6026 | |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6027 | // Cause draw-time errors due to PSO incompatibilities |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6028 | // 1. Error due to not binding required set (we actually use same code as |
| 6029 | // above to disturb set0) |
| 6030 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6031 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6032 | 2, &descriptorSet[0], 0, NULL); |
| 6033 | vkCmdBindDescriptorSets( |
| 6034 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 6035 | pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL); |
| 6036 | m_errorMonitor->SetDesiredFailureMsg( |
| 6037 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6038 | " uses set #0 but that set is not bound."); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6039 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6040 | m_errorMonitor->VerifyFound(); |
| 6041 | |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 6042 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6043 | // 2. Error due to bound set not being compatible with PSO's |
| 6044 | // VkPipelineLayout (diff stageFlags in this case) |
| 6045 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 6046 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 6047 | 2, &descriptorSet[0], 0, NULL); |
| 6048 | m_errorMonitor->SetDesiredFailureMsg( |
| 6049 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6050 | " bound as set #0 is not compatible with "); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 6051 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6052 | m_errorMonitor->VerifyFound(); |
| 6053 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6054 | // Remaining clean-up |
| 6055 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6056 | for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) { |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6057 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL); |
| 6058 | } |
| 6059 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL); |
Tobin Ehlis | 9bfd449 | 2016-05-05 15:09:11 -0600 | [diff] [blame] | 6060 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only); |
| 6061 | vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 6062 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6063 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6064 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 6065 | vkFreeMemory(m_device->device(), imageMem, NULL); |
| 6066 | vkDestroyImage(m_device->device(), image, NULL); |
| 6067 | vkDestroyImageView(m_device->device(), view, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6068 | } |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 6069 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6070 | TEST_F(VkLayerTest, NoBeginCommandBuffer) { |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6071 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6072 | m_errorMonitor->SetDesiredFailureMsg( |
| 6073 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6074 | "You must call vkBeginCommandBuffer() before this call to "); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6075 | |
| 6076 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6077 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6078 | // Call EndCommandBuffer() w/o calling BeginCommandBuffer() |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6079 | vkEndCommandBuffer(commandBuffer.GetBufferHandle()); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6080 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6081 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6082 | } |
| 6083 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6084 | TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) { |
| 6085 | VkResult err; |
| 6086 | VkCommandBuffer draw_cmd; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6087 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6088 | m_errorMonitor->SetDesiredFailureMsg( |
| 6089 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 61b36f3 | 2015-12-16 08:19:42 -0700 | [diff] [blame] | 6090 | " must specify a valid renderpass parameter."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6091 | |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6092 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6093 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6094 | VkCommandBufferAllocateInfo cmd = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6095 | cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6096 | cmd.pNext = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6097 | cmd.commandPool = m_commandPool; |
| 6098 | cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6099 | cmd.commandBufferCount = 1; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6100 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6101 | err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 6102 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6103 | |
| 6104 | // Force the failure by not setting the Renderpass and Framebuffer fields |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6105 | VkCommandBufferBeginInfo cmd_buf_info = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6106 | VkCommandBufferInheritanceInfo cmd_buf_hinfo = {}; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6107 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 6108 | cmd_buf_info.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6109 | cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | |
| 6110 | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6111 | cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo; |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6112 | |
| 6113 | // The error should be caught by validation of the BeginCommandBuffer call |
| 6114 | vkBeginCommandBuffer(draw_cmd, &cmd_buf_info); |
| 6115 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6116 | m_errorMonitor->VerifyFound(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6117 | vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 6118 | } |
| 6119 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6120 | TEST_F(VkLayerTest, CommandBufferResetErrors) { |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6121 | // Cause error due to Begin while recording CB |
| 6122 | // Then cause 2 errors for attempting to reset CB w/o having |
| 6123 | // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from |
| 6124 | // which CBs were allocated. Note that this bit is off by default. |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 6125 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6126 | "Cannot call Begin on CB"); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6127 | |
| 6128 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6129 | |
| 6130 | // Calls AllocateCommandBuffers |
| 6131 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
| 6132 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6133 | // Force the failure by setting the Renderpass and Framebuffer fields with |
| 6134 | // (fake) data |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6135 | VkCommandBufferBeginInfo cmd_buf_info = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6136 | VkCommandBufferInheritanceInfo cmd_buf_hinfo = {}; |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6137 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 6138 | cmd_buf_info.pNext = NULL; |
| 6139 | cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6140 | cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo; |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6141 | |
| 6142 | // Begin CB to transition to recording state |
| 6143 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
| 6144 | // Can't re-begin. This should trigger error |
| 6145 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6146 | m_errorMonitor->VerifyFound(); |
| 6147 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6148 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6149 | "Attempt to reset command buffer "); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6150 | VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test |
| 6151 | // Reset attempt will trigger error due to incorrect CommandPool state |
| 6152 | vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6153 | m_errorMonitor->VerifyFound(); |
| 6154 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6155 | m_errorMonitor->SetDesiredFailureMsg( |
| 6156 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6157 | " attempts to implicitly reset cmdBuffer created from "); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6158 | // Transition CB to RECORDED state |
| 6159 | vkEndCommandBuffer(commandBuffer.GetBufferHandle()); |
| 6160 | // Now attempting to Begin will implicitly reset, which triggers error |
| 6161 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6162 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 6163 | } |
| 6164 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6165 | TEST_F(VkLayerTest, InvalidPipelineCreateState) { |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6166 | // Attempt to Create Gfx Pipeline w/o a VS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6167 | VkResult err; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6168 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6169 | m_errorMonitor->SetDesiredFailureMsg( |
| 6170 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6171 | "Invalid Pipeline CreateInfo State: Vtx Shader required"); |
| 6172 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6173 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 6174 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 6175 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6176 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6177 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6178 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6179 | |
| 6180 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6181 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6182 | ds_pool_ci.pNext = NULL; |
| 6183 | ds_pool_ci.maxSets = 1; |
| 6184 | ds_pool_ci.poolSizeCount = 1; |
| 6185 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 6186 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6187 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6188 | err = |
| 6189 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6190 | ASSERT_VK_SUCCESS(err); |
| 6191 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6192 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6193 | dsl_binding.binding = 0; |
| 6194 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6195 | dsl_binding.descriptorCount = 1; |
| 6196 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 6197 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6198 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6199 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6200 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6201 | ds_layout_ci.pNext = NULL; |
| 6202 | ds_layout_ci.bindingCount = 1; |
| 6203 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6204 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6205 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6206 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6207 | &ds_layout); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6208 | ASSERT_VK_SUCCESS(err); |
| 6209 | |
| 6210 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6211 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6212 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6213 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6214 | alloc_info.descriptorPool = ds_pool; |
| 6215 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6216 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6217 | &descriptorSet); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6218 | ASSERT_VK_SUCCESS(err); |
| 6219 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6220 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6221 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6222 | pipeline_layout_ci.setLayoutCount = 1; |
| 6223 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6224 | |
| 6225 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6226 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6227 | &pipeline_layout); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6228 | ASSERT_VK_SUCCESS(err); |
| 6229 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6230 | VkViewport vp = {}; // Just need dummy vp to point to |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6231 | VkRect2D sc = {}; // dummy scissor to point to |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6232 | |
| 6233 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6234 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 6235 | vp_state_ci.scissorCount = 1; |
| 6236 | vp_state_ci.pScissors = ≻ |
| 6237 | vp_state_ci.viewportCount = 1; |
| 6238 | vp_state_ci.pViewports = &vp; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6239 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6240 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 6241 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 6242 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 6243 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 6244 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 6245 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 6246 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 6247 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 6248 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6249 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6250 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6251 | gp_ci.pViewportState = &vp_state_ci; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6252 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6253 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6254 | gp_ci.layout = pipeline_layout; |
| 6255 | gp_ci.renderPass = renderPass(); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6256 | |
| 6257 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6258 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 6259 | pc_ci.initialDataSize = 0; |
| 6260 | pc_ci.pInitialData = 0; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6261 | |
| 6262 | VkPipeline pipeline; |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 6263 | VkPipelineCache pipelineCache; |
| 6264 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6265 | err = |
| 6266 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 6267 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6268 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6269 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 6270 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6271 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 6272 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6273 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6274 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6275 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6276 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6277 | } |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6278 | /*// TODO : This test should be good, but needs Tess support in compiler to run |
| 6279 | TEST_F(VkLayerTest, InvalidPatchControlPoints) |
| 6280 | { |
| 6281 | // Attempt to Create Gfx Pipeline w/o a VS |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6282 | VkResult err; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6283 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 6284 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6285 | "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH |
| 6286 | primitive "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6287 | |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6288 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6289 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6290 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6291 | VkDescriptorPoolSize ds_type_count = {}; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6292 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6293 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6294 | |
| 6295 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 6296 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6297 | ds_pool_ci.pNext = NULL; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6298 | ds_pool_ci.poolSizeCount = 1; |
| 6299 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6300 | |
| 6301 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6302 | err = vkCreateDescriptorPool(m_device->device(), |
| 6303 | 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] | 6304 | ASSERT_VK_SUCCESS(err); |
| 6305 | |
| 6306 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6307 | dsl_binding.binding = 0; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6308 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | 0212448 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 6309 | dsl_binding.descriptorCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6310 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 6311 | dsl_binding.pImmutableSamplers = NULL; |
| 6312 | |
| 6313 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6314 | ds_layout_ci.sType = |
| 6315 | VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6316 | ds_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6317 | ds_layout_ci.bindingCount = 1; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 6318 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6319 | |
| 6320 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6321 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6322 | &ds_layout); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6323 | ASSERT_VK_SUCCESS(err); |
| 6324 | |
| 6325 | VkDescriptorSet descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6326 | err = vkAllocateDescriptorSets(m_device->device(), ds_pool, |
| 6327 | VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6328 | ASSERT_VK_SUCCESS(err); |
| 6329 | |
| 6330 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6331 | pipeline_layout_ci.sType = |
| 6332 | VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6333 | pipeline_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6334 | pipeline_layout_ci.setLayoutCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6335 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 6336 | |
| 6337 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6338 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6339 | &pipeline_layout); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6340 | ASSERT_VK_SUCCESS(err); |
| 6341 | |
| 6342 | VkPipelineShaderStageCreateInfo shaderStages[3]; |
| 6343 | memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 6344 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6345 | VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, |
| 6346 | this); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6347 | // 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] | 6348 | VkShaderObj |
| 6349 | tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, |
| 6350 | this); |
| 6351 | VkShaderObj |
| 6352 | te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, |
| 6353 | this); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6354 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6355 | shaderStages[0].sType = |
| 6356 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 6357 | shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6358 | shaderStages[0].shader = vs.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6359 | shaderStages[1].sType = |
| 6360 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 6361 | shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6362 | shaderStages[1].shader = tc.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6363 | shaderStages[2].sType = |
| 6364 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 6365 | shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6366 | shaderStages[2].shader = te.handle(); |
| 6367 | |
| 6368 | VkPipelineInputAssemblyStateCreateInfo iaCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6369 | iaCI.sType = |
| 6370 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
Chia-I Wu | 515eb8f | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6371 | iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6372 | |
| 6373 | VkPipelineTessellationStateCreateInfo tsCI = {}; |
| 6374 | tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO; |
| 6375 | tsCI.patchControlPoints = 0; // This will cause an error |
| 6376 | |
| 6377 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 6378 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6379 | gp_ci.pNext = NULL; |
| 6380 | gp_ci.stageCount = 3; |
| 6381 | gp_ci.pStages = shaderStages; |
| 6382 | gp_ci.pVertexInputState = NULL; |
| 6383 | gp_ci.pInputAssemblyState = &iaCI; |
| 6384 | gp_ci.pTessellationState = &tsCI; |
| 6385 | gp_ci.pViewportState = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6386 | gp_ci.pRasterizationState = NULL; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6387 | gp_ci.pMultisampleState = NULL; |
| 6388 | gp_ci.pDepthStencilState = NULL; |
| 6389 | gp_ci.pColorBlendState = NULL; |
| 6390 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6391 | gp_ci.layout = pipeline_layout; |
| 6392 | gp_ci.renderPass = renderPass(); |
| 6393 | |
| 6394 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 6395 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 6396 | pc_ci.pNext = NULL; |
| 6397 | pc_ci.initialSize = 0; |
| 6398 | pc_ci.initialData = 0; |
| 6399 | pc_ci.maxSize = 0; |
| 6400 | |
| 6401 | VkPipeline pipeline; |
| 6402 | VkPipelineCache pipelineCache; |
| 6403 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6404 | err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, |
| 6405 | &pipelineCache); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6406 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6407 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6408 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6409 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6410 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 6411 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6412 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6413 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6414 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6415 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 6416 | } |
| 6417 | */ |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6418 | // Set scissor and viewport counts to different numbers |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6419 | TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6420 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6421 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6422 | m_errorMonitor->SetDesiredFailureMsg( |
| 6423 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6424 | "Gfx Pipeline viewport count (1) must match scissor count (0)."); |
| 6425 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6426 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6427 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6428 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6429 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6430 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6431 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6432 | |
| 6433 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6434 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6435 | ds_pool_ci.maxSets = 1; |
| 6436 | ds_pool_ci.poolSizeCount = 1; |
| 6437 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6438 | |
| 6439 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6440 | err = |
| 6441 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6442 | ASSERT_VK_SUCCESS(err); |
| 6443 | |
| 6444 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6445 | dsl_binding.binding = 0; |
| 6446 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6447 | dsl_binding.descriptorCount = 1; |
| 6448 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6449 | |
| 6450 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6451 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6452 | ds_layout_ci.bindingCount = 1; |
| 6453 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6454 | |
| 6455 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6456 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6457 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6458 | ASSERT_VK_SUCCESS(err); |
| 6459 | |
| 6460 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6461 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6462 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6463 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6464 | alloc_info.descriptorPool = ds_pool; |
| 6465 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6466 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6467 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6468 | ASSERT_VK_SUCCESS(err); |
| 6469 | |
| 6470 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6471 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6472 | pipeline_layout_ci.setLayoutCount = 1; |
| 6473 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6474 | |
| 6475 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6476 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6477 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6478 | ASSERT_VK_SUCCESS(err); |
| 6479 | |
| 6480 | VkViewport vp = {}; // Just need dummy vp to point to |
| 6481 | |
| 6482 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6483 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 6484 | vp_state_ci.scissorCount = 0; |
| 6485 | vp_state_ci.viewportCount = 1; // Count mismatch should cause error |
| 6486 | vp_state_ci.pViewports = &vp; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6487 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6488 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 6489 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 6490 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 6491 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 6492 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 6493 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 6494 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 6495 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 6496 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 6497 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6498 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6499 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6500 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 6501 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6502 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 6503 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6504 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6505 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6506 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 6507 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6508 | |
| 6509 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6510 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6511 | gp_ci.stageCount = 2; |
| 6512 | gp_ci.pStages = shaderStages; |
| 6513 | gp_ci.pViewportState = &vp_state_ci; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6514 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6515 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6516 | gp_ci.layout = pipeline_layout; |
| 6517 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6518 | |
| 6519 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6520 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6521 | |
| 6522 | VkPipeline pipeline; |
| 6523 | VkPipelineCache pipelineCache; |
| 6524 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6525 | err = |
| 6526 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6527 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6528 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6529 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6530 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6531 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6532 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6533 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6534 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6535 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6536 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6537 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6538 | // Don't set viewport state in PSO. This is an error b/c we always need this |
| 6539 | // state |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 6540 | // 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] | 6541 | TEST_F(VkLayerTest, PSOViewportStateNotSet) { |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6542 | // Attempt to Create Gfx Pipeline w/o a VS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6543 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6544 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6545 | m_errorMonitor->SetDesiredFailureMsg( |
| 6546 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6547 | "Gfx Pipeline pViewportState is null. Even if "); |
| 6548 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6549 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6550 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6551 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6552 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6553 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6554 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6555 | |
| 6556 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6557 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6558 | ds_pool_ci.maxSets = 1; |
| 6559 | ds_pool_ci.poolSizeCount = 1; |
| 6560 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6561 | |
| 6562 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6563 | err = |
| 6564 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6565 | ASSERT_VK_SUCCESS(err); |
| 6566 | |
| 6567 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6568 | dsl_binding.binding = 0; |
| 6569 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6570 | dsl_binding.descriptorCount = 1; |
| 6571 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6572 | |
| 6573 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6574 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6575 | ds_layout_ci.bindingCount = 1; |
| 6576 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6577 | |
| 6578 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6579 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6580 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6581 | ASSERT_VK_SUCCESS(err); |
| 6582 | |
| 6583 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6584 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6585 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6586 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6587 | alloc_info.descriptorPool = ds_pool; |
| 6588 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6589 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6590 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6591 | ASSERT_VK_SUCCESS(err); |
| 6592 | |
| 6593 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6594 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6595 | pipeline_layout_ci.setLayoutCount = 1; |
| 6596 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6597 | |
| 6598 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6599 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6600 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6601 | ASSERT_VK_SUCCESS(err); |
| 6602 | |
| 6603 | VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR; |
| 6604 | // Set scissor as dynamic to avoid second error |
| 6605 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6606 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 6607 | dyn_state_ci.dynamicStateCount = 1; |
| 6608 | dyn_state_ci.pDynamicStates = &sc_state; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6609 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 6610 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6611 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6612 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6613 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 6614 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6615 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 6616 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6617 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6618 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6619 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 6620 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6621 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6622 | |
| 6623 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 6624 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 6625 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 6626 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 6627 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 6628 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 6629 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 6630 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 6631 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6632 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6633 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6634 | gp_ci.stageCount = 2; |
| 6635 | gp_ci.pStages = shaderStages; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 6636 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6637 | gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state |
| 6638 | // should cause validation error |
| 6639 | gp_ci.pDynamicState = &dyn_state_ci; |
| 6640 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6641 | gp_ci.layout = pipeline_layout; |
| 6642 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6643 | |
| 6644 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6645 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6646 | |
| 6647 | VkPipeline pipeline; |
| 6648 | VkPipelineCache pipelineCache; |
| 6649 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6650 | err = |
| 6651 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6652 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6653 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6654 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6655 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6656 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6657 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6658 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6659 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6660 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6661 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6662 | } |
| 6663 | // Create PSO w/o non-zero viewportCount but no viewport data |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6664 | // Then run second test where dynamic scissor count doesn't match PSO scissor |
| 6665 | // count |
| 6666 | TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) { |
| 6667 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6668 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6669 | m_errorMonitor->SetDesiredFailureMsg( |
| 6670 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6671 | "Gfx Pipeline viewportCount is 1, but pViewports is NULL. "); |
| 6672 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6673 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6674 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6675 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6676 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6677 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6678 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6679 | |
| 6680 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6681 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6682 | ds_pool_ci.maxSets = 1; |
| 6683 | ds_pool_ci.poolSizeCount = 1; |
| 6684 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6685 | |
| 6686 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6687 | err = |
| 6688 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6689 | ASSERT_VK_SUCCESS(err); |
| 6690 | |
| 6691 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6692 | dsl_binding.binding = 0; |
| 6693 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6694 | dsl_binding.descriptorCount = 1; |
| 6695 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6696 | |
| 6697 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6698 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6699 | ds_layout_ci.bindingCount = 1; |
| 6700 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6701 | |
| 6702 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6703 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6704 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6705 | ASSERT_VK_SUCCESS(err); |
| 6706 | |
| 6707 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6708 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6709 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6710 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6711 | alloc_info.descriptorPool = ds_pool; |
| 6712 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6713 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6714 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6715 | ASSERT_VK_SUCCESS(err); |
| 6716 | |
| 6717 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6718 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6719 | pipeline_layout_ci.setLayoutCount = 1; |
| 6720 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6721 | |
| 6722 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6723 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6724 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6725 | ASSERT_VK_SUCCESS(err); |
| 6726 | |
| 6727 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6728 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 6729 | vp_state_ci.viewportCount = 1; |
| 6730 | vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error |
| 6731 | vp_state_ci.scissorCount = 1; |
| 6732 | vp_state_ci.pScissors = |
| 6733 | NULL; // Scissor is dynamic (below) so this won't cause error |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6734 | |
| 6735 | VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR; |
| 6736 | // Set scissor as dynamic to avoid that error |
| 6737 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6738 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 6739 | dyn_state_ci.dynamicStateCount = 1; |
| 6740 | dyn_state_ci.pDynamicStates = &sc_state; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6741 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 6742 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6743 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6744 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6745 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 6746 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6747 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 6748 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6749 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6750 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6751 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 6752 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6753 | |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6754 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 6755 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 6756 | vi_ci.pNext = nullptr; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6757 | vi_ci.vertexBindingDescriptionCount = 0; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6758 | vi_ci.pVertexBindingDescriptions = nullptr; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6759 | vi_ci.vertexAttributeDescriptionCount = 0; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6760 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 6761 | |
| 6762 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 6763 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 6764 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 6765 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6766 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6767 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6768 | rs_ci.pNext = nullptr; |
| 6769 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 6770 | VkPipelineColorBlendAttachmentState att = {}; |
| 6771 | att.blendEnable = VK_FALSE; |
| 6772 | att.colorWriteMask = 0xf; |
| 6773 | |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6774 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 6775 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 6776 | cb_ci.pNext = nullptr; |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 6777 | cb_ci.attachmentCount = 1; |
| 6778 | cb_ci.pAttachments = &att; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6779 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6780 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6781 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6782 | gp_ci.stageCount = 2; |
| 6783 | gp_ci.pStages = shaderStages; |
| 6784 | gp_ci.pVertexInputState = &vi_ci; |
| 6785 | gp_ci.pInputAssemblyState = &ia_ci; |
| 6786 | gp_ci.pViewportState = &vp_state_ci; |
| 6787 | gp_ci.pRasterizationState = &rs_ci; |
| 6788 | gp_ci.pColorBlendState = &cb_ci; |
| 6789 | gp_ci.pDynamicState = &dyn_state_ci; |
| 6790 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6791 | gp_ci.layout = pipeline_layout; |
| 6792 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6793 | |
| 6794 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6795 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6796 | |
| 6797 | VkPipeline pipeline; |
| 6798 | VkPipelineCache pipelineCache; |
| 6799 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6800 | err = |
| 6801 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6802 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6803 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6804 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6805 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6806 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6807 | |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 6808 | // 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] | 6809 | // First need to successfully create the PSO from above by setting |
| 6810 | // pViewports |
| 6811 | m_errorMonitor->SetDesiredFailureMsg( |
| 6812 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6813 | "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO " |
| 6814 | "scissorCount is 1. These counts must match."); |
| 6815 | |
| 6816 | VkViewport vp = {}; // Just need dummy vp to point to |
| 6817 | vp_state_ci.pViewports = &vp; |
| 6818 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6819 | &gp_ci, NULL, &pipeline); |
| 6820 | ASSERT_VK_SUCCESS(err); |
| 6821 | BeginCommandBuffer(); |
| 6822 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 6823 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 6824 | VkRect2D scissors[2] = {}; // don't care about data |
| 6825 | // Count of 2 doesn't match PSO count of 1 |
| 6826 | vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors); |
| 6827 | Draw(1, 0, 0, 0); |
| 6828 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6829 | m_errorMonitor->VerifyFound(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6830 | |
| 6831 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6832 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6833 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6834 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 6835 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6836 | } |
| 6837 | // Create PSO w/o non-zero scissorCount but no scissor data |
| 6838 | // Then run second test where dynamic viewportCount doesn't match PSO |
| 6839 | // viewportCount |
| 6840 | TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) { |
| 6841 | VkResult err; |
| 6842 | |
| 6843 | m_errorMonitor->SetDesiredFailureMsg( |
| 6844 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6845 | "Gfx Pipeline scissorCount is 1, but pScissors is NULL. "); |
| 6846 | |
| 6847 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6848 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 6849 | |
| 6850 | VkDescriptorPoolSize ds_type_count = {}; |
| 6851 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6852 | ds_type_count.descriptorCount = 1; |
| 6853 | |
| 6854 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 6855 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6856 | ds_pool_ci.maxSets = 1; |
| 6857 | ds_pool_ci.poolSizeCount = 1; |
| 6858 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 6859 | |
| 6860 | VkDescriptorPool ds_pool; |
| 6861 | err = |
| 6862 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 6863 | ASSERT_VK_SUCCESS(err); |
| 6864 | |
| 6865 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 6866 | dsl_binding.binding = 0; |
| 6867 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6868 | dsl_binding.descriptorCount = 1; |
| 6869 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 6870 | |
| 6871 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 6872 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6873 | ds_layout_ci.bindingCount = 1; |
| 6874 | ds_layout_ci.pBindings = &dsl_binding; |
| 6875 | |
| 6876 | VkDescriptorSetLayout ds_layout; |
| 6877 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6878 | &ds_layout); |
| 6879 | ASSERT_VK_SUCCESS(err); |
| 6880 | |
| 6881 | VkDescriptorSet descriptorSet; |
| 6882 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 6883 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 6884 | alloc_info.descriptorSetCount = 1; |
| 6885 | alloc_info.descriptorPool = ds_pool; |
| 6886 | alloc_info.pSetLayouts = &ds_layout; |
| 6887 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6888 | &descriptorSet); |
| 6889 | ASSERT_VK_SUCCESS(err); |
| 6890 | |
| 6891 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 6892 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6893 | pipeline_layout_ci.setLayoutCount = 1; |
| 6894 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 6895 | |
| 6896 | VkPipelineLayout pipeline_layout; |
| 6897 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6898 | &pipeline_layout); |
| 6899 | ASSERT_VK_SUCCESS(err); |
| 6900 | |
| 6901 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 6902 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 6903 | vp_state_ci.scissorCount = 1; |
| 6904 | vp_state_ci.pScissors = |
| 6905 | NULL; // Null scissor w/ count of 1 should cause error |
| 6906 | vp_state_ci.viewportCount = 1; |
| 6907 | vp_state_ci.pViewports = |
| 6908 | NULL; // vp is dynamic (below) so this won't cause error |
| 6909 | |
| 6910 | VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT; |
| 6911 | // Set scissor as dynamic to avoid that error |
| 6912 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
| 6913 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 6914 | dyn_state_ci.dynamicStateCount = 1; |
| 6915 | dyn_state_ci.pDynamicStates = &vp_state; |
| 6916 | |
| 6917 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
| 6918 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 6919 | |
| 6920 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 6921 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6922 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 6923 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6924 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6925 | // but add it to be able to run on more devices |
| 6926 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 6927 | shaderStages[1] = fs.GetStageCreateInfo(); |
| 6928 | |
| 6929 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 6930 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 6931 | vi_ci.pNext = nullptr; |
| 6932 | vi_ci.vertexBindingDescriptionCount = 0; |
| 6933 | vi_ci.pVertexBindingDescriptions = nullptr; |
| 6934 | vi_ci.vertexAttributeDescriptionCount = 0; |
| 6935 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 6936 | |
| 6937 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 6938 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 6939 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 6940 | |
| 6941 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
| 6942 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 6943 | rs_ci.pNext = nullptr; |
| 6944 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 6945 | VkPipelineColorBlendAttachmentState att = {}; |
| 6946 | att.blendEnable = VK_FALSE; |
| 6947 | att.colorWriteMask = 0xf; |
| 6948 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6949 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 6950 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 6951 | cb_ci.pNext = nullptr; |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 6952 | cb_ci.attachmentCount = 1; |
| 6953 | cb_ci.pAttachments = &att; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6954 | |
| 6955 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 6956 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6957 | gp_ci.stageCount = 2; |
| 6958 | gp_ci.pStages = shaderStages; |
| 6959 | gp_ci.pVertexInputState = &vi_ci; |
| 6960 | gp_ci.pInputAssemblyState = &ia_ci; |
| 6961 | gp_ci.pViewportState = &vp_state_ci; |
| 6962 | gp_ci.pRasterizationState = &rs_ci; |
| 6963 | gp_ci.pColorBlendState = &cb_ci; |
| 6964 | gp_ci.pDynamicState = &dyn_state_ci; |
| 6965 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6966 | gp_ci.layout = pipeline_layout; |
| 6967 | gp_ci.renderPass = renderPass(); |
| 6968 | |
| 6969 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 6970 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 6971 | |
| 6972 | VkPipeline pipeline; |
| 6973 | VkPipelineCache pipelineCache; |
| 6974 | |
| 6975 | err = |
| 6976 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 6977 | ASSERT_VK_SUCCESS(err); |
| 6978 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6979 | &gp_ci, NULL, &pipeline); |
| 6980 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6981 | m_errorMonitor->VerifyFound(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6982 | |
| 6983 | // Now hit second fail case where we set scissor w/ different count than PSO |
| 6984 | // First need to successfully create the PSO from above by setting |
| 6985 | // pViewports |
| 6986 | m_errorMonitor->SetDesiredFailureMsg( |
| 6987 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6988 | "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO " |
| 6989 | "viewportCount is 1. These counts must match."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6990 | |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 6991 | VkRect2D sc = {}; // Just need dummy vp to point to |
| 6992 | vp_state_ci.pScissors = ≻ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6993 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6994 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 6995 | ASSERT_VK_SUCCESS(err); |
| 6996 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6997 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 6998 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 6999 | VkViewport viewports[2] = {}; // don't care about data |
| 7000 | // Count of 2 doesn't match PSO count of 1 |
Jon Ashburn | 19d3bf1 | 2015-12-30 14:06:55 -0700 | [diff] [blame] | 7001 | vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 7002 | Draw(1, 0, 0, 0); |
| 7003 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7004 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7005 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7006 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7007 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7008 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7009 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7010 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 7011 | } |
| 7012 | |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7013 | TEST_F(VkLayerTest, PSOLineWidthInvalid) { |
| 7014 | VkResult err; |
| 7015 | |
| 7016 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7017 | "Attempt to set lineWidth to -1"); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7018 | |
| 7019 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7020 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7021 | |
| 7022 | VkDescriptorPoolSize ds_type_count = {}; |
| 7023 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7024 | ds_type_count.descriptorCount = 1; |
| 7025 | |
| 7026 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 7027 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7028 | ds_pool_ci.maxSets = 1; |
| 7029 | ds_pool_ci.poolSizeCount = 1; |
| 7030 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 7031 | |
| 7032 | VkDescriptorPool ds_pool; |
| 7033 | err = |
| 7034 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 7035 | ASSERT_VK_SUCCESS(err); |
| 7036 | |
| 7037 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 7038 | dsl_binding.binding = 0; |
| 7039 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7040 | dsl_binding.descriptorCount = 1; |
| 7041 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7042 | |
| 7043 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 7044 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7045 | ds_layout_ci.bindingCount = 1; |
| 7046 | ds_layout_ci.pBindings = &dsl_binding; |
| 7047 | |
| 7048 | VkDescriptorSetLayout ds_layout; |
| 7049 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7050 | &ds_layout); |
| 7051 | ASSERT_VK_SUCCESS(err); |
| 7052 | |
| 7053 | VkDescriptorSet descriptorSet; |
| 7054 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 7055 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 7056 | alloc_info.descriptorSetCount = 1; |
| 7057 | alloc_info.descriptorPool = ds_pool; |
| 7058 | alloc_info.pSetLayouts = &ds_layout; |
| 7059 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7060 | &descriptorSet); |
| 7061 | ASSERT_VK_SUCCESS(err); |
| 7062 | |
| 7063 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 7064 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7065 | pipeline_layout_ci.setLayoutCount = 1; |
| 7066 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 7067 | |
| 7068 | VkPipelineLayout pipeline_layout; |
| 7069 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7070 | &pipeline_layout); |
| 7071 | ASSERT_VK_SUCCESS(err); |
| 7072 | |
| 7073 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 7074 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 7075 | vp_state_ci.scissorCount = 1; |
| 7076 | vp_state_ci.pScissors = NULL; |
| 7077 | vp_state_ci.viewportCount = 1; |
| 7078 | vp_state_ci.pViewports = NULL; |
| 7079 | |
| 7080 | VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, |
| 7081 | VK_DYNAMIC_STATE_SCISSOR, |
| 7082 | VK_DYNAMIC_STATE_LINE_WIDTH}; |
| 7083 | // Set scissor as dynamic to avoid that error |
| 7084 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
| 7085 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 7086 | dyn_state_ci.dynamicStateCount = 2; |
| 7087 | dyn_state_ci.pDynamicStates = dynamic_states; |
| 7088 | |
| 7089 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
| 7090 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 7091 | |
| 7092 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7093 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7094 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7095 | VK_SHADER_STAGE_FRAGMENT_BIT, |
| 7096 | this); // TODO - We shouldn't need a fragment shader |
| 7097 | // but add it to be able to run on more devices |
| 7098 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 7099 | shaderStages[1] = fs.GetStageCreateInfo(); |
| 7100 | |
| 7101 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 7102 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 7103 | vi_ci.pNext = nullptr; |
| 7104 | vi_ci.vertexBindingDescriptionCount = 0; |
| 7105 | vi_ci.pVertexBindingDescriptions = nullptr; |
| 7106 | vi_ci.vertexAttributeDescriptionCount = 0; |
| 7107 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 7108 | |
| 7109 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 7110 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 7111 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 7112 | |
| 7113 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
| 7114 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 7115 | rs_ci.pNext = nullptr; |
| 7116 | |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7117 | // Check too low (line width of -1.0f). |
| 7118 | rs_ci.lineWidth = -1.0f; |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7119 | |
| 7120 | VkPipelineColorBlendAttachmentState att = {}; |
| 7121 | att.blendEnable = VK_FALSE; |
| 7122 | att.colorWriteMask = 0xf; |
| 7123 | |
| 7124 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 7125 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 7126 | cb_ci.pNext = nullptr; |
| 7127 | cb_ci.attachmentCount = 1; |
| 7128 | cb_ci.pAttachments = &att; |
| 7129 | |
| 7130 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 7131 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 7132 | gp_ci.stageCount = 2; |
| 7133 | gp_ci.pStages = shaderStages; |
| 7134 | gp_ci.pVertexInputState = &vi_ci; |
| 7135 | gp_ci.pInputAssemblyState = &ia_ci; |
| 7136 | gp_ci.pViewportState = &vp_state_ci; |
| 7137 | gp_ci.pRasterizationState = &rs_ci; |
| 7138 | gp_ci.pColorBlendState = &cb_ci; |
| 7139 | gp_ci.pDynamicState = &dyn_state_ci; |
| 7140 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 7141 | gp_ci.layout = pipeline_layout; |
| 7142 | gp_ci.renderPass = renderPass(); |
| 7143 | |
| 7144 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 7145 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 7146 | |
| 7147 | VkPipeline pipeline; |
| 7148 | VkPipelineCache pipelineCache; |
| 7149 | |
| 7150 | err = |
| 7151 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7152 | ASSERT_VK_SUCCESS(err); |
| 7153 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7154 | &gp_ci, NULL, &pipeline); |
| 7155 | |
| 7156 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7157 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7158 | |
| 7159 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7160 | "Attempt to set lineWidth to 65536"); |
| 7161 | |
| 7162 | // Check too high (line width of 65536.0f). |
| 7163 | rs_ci.lineWidth = 65536.0f; |
| 7164 | |
| 7165 | err = |
| 7166 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7167 | ASSERT_VK_SUCCESS(err); |
| 7168 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7169 | &gp_ci, NULL, &pipeline); |
| 7170 | |
| 7171 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7172 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7173 | |
| 7174 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7175 | "Attempt to set lineWidth to -1"); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7176 | |
| 7177 | dyn_state_ci.dynamicStateCount = 3; |
| 7178 | |
| 7179 | rs_ci.lineWidth = 1.0f; |
| 7180 | |
| 7181 | err = |
| 7182 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 7183 | ASSERT_VK_SUCCESS(err); |
| 7184 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 7185 | &gp_ci, NULL, &pipeline); |
| 7186 | BeginCommandBuffer(); |
| 7187 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7188 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 7189 | |
| 7190 | // Check too low with dynamic setting. |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 7191 | vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7192 | m_errorMonitor->VerifyFound(); |
| 7193 | |
| 7194 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7195 | "Attempt to set lineWidth to 65536"); |
| 7196 | |
| 7197 | // Check too high with dynamic setting. |
| 7198 | vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f); |
| 7199 | m_errorMonitor->VerifyFound(); |
| 7200 | EndCommandBuffer(); |
| 7201 | |
| 7202 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 7203 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 7204 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7205 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7206 | vkDestroyPipeline(m_device->device(), pipeline, NULL); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 7207 | } |
| 7208 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7209 | TEST_F(VkLayerTest, NullRenderPass) { |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7210 | // Bind a NULL RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7211 | m_errorMonitor->SetDesiredFailureMsg( |
| 7212 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7213 | "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()"); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7214 | |
| 7215 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7216 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7217 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 7218 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7219 | // Don't care about RenderPass handle b/c error should be flagged before |
| 7220 | // that |
| 7221 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, |
| 7222 | VK_SUBPASS_CONTENTS_INLINE); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7223 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7224 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 7225 | } |
| 7226 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7227 | TEST_F(VkLayerTest, RenderPassWithinRenderPass) { |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7228 | // Bind a BeginRenderPass within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7229 | m_errorMonitor->SetDesiredFailureMsg( |
| 7230 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7231 | "It is invalid to issue this call inside an active render pass"); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7232 | |
| 7233 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7234 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7235 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 7236 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7237 | // Just create a dummy Renderpass that's non-NULL so we can get to the |
| 7238 | // proper error |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7239 | VkRenderPassBeginInfo rp_begin = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7240 | rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 7241 | rp_begin.pNext = NULL; |
| 7242 | rp_begin.renderPass = renderPass(); |
| 7243 | rp_begin.framebuffer = framebuffer(); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 7244 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7245 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, |
| 7246 | VK_SUBPASS_CONTENTS_INLINE); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 7247 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7248 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 7249 | } |
| 7250 | |
Tobin Ehlis | 5a1c033 | 2016-05-31 13:59:26 -0600 | [diff] [blame] | 7251 | TEST_F(VkLayerTest, RenderPassClearOpMismatch) { |
| 7252 | TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than" |
| 7253 | "the number of renderPass attachments that use loadOp" |
| 7254 | "VK_ATTACHMENT_LOAD_OP_CLEAR."); |
| 7255 | |
| 7256 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7257 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7258 | |
| 7259 | // Create a renderPass with a single attachment that uses loadOp CLEAR |
| 7260 | VkAttachmentReference attach = {}; |
| 7261 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 7262 | VkSubpassDescription subpass = {}; |
| 7263 | subpass.inputAttachmentCount = 1; |
| 7264 | subpass.pInputAttachments = &attach; |
| 7265 | VkRenderPassCreateInfo rpci = {}; |
| 7266 | rpci.subpassCount = 1; |
| 7267 | rpci.pSubpasses = &subpass; |
| 7268 | rpci.attachmentCount = 1; |
| 7269 | VkAttachmentDescription attach_desc = {}; |
| 7270 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 7271 | // Set loadOp to CLEAR |
| 7272 | attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 7273 | rpci.pAttachments = &attach_desc; |
| 7274 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 7275 | VkRenderPass rp; |
| 7276 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 7277 | |
| 7278 | VkCommandBufferInheritanceInfo hinfo = {}; |
| 7279 | hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; |
| 7280 | hinfo.renderPass = VK_NULL_HANDLE; |
| 7281 | hinfo.subpass = 0; |
| 7282 | hinfo.framebuffer = VK_NULL_HANDLE; |
| 7283 | hinfo.occlusionQueryEnable = VK_FALSE; |
| 7284 | hinfo.queryFlags = 0; |
| 7285 | hinfo.pipelineStatistics = 0; |
| 7286 | VkCommandBufferBeginInfo info = {}; |
| 7287 | info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
| 7288 | info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 7289 | info.pInheritanceInfo = &hinfo; |
| 7290 | |
| 7291 | vkBeginCommandBuffer(m_commandBuffer->handle(), &info); |
| 7292 | VkRenderPassBeginInfo rp_begin = {}; |
| 7293 | rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 7294 | rp_begin.pNext = NULL; |
| 7295 | rp_begin.renderPass = renderPass(); |
| 7296 | rp_begin.framebuffer = framebuffer(); |
| 7297 | rp_begin.clearValueCount = 0; // Should be 1 |
| 7298 | |
| 7299 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7300 | " has a clearValueCount of 0 but the " |
| 7301 | "actual number of attachments in " |
| 7302 | "renderPass "); |
| 7303 | |
| 7304 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, |
| 7305 | VK_SUBPASS_CONTENTS_INLINE); |
| 7306 | |
| 7307 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 5c70ebd | 2016-06-09 13:45:00 -0600 | [diff] [blame] | 7308 | |
| 7309 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
Tobin Ehlis | 5a1c033 | 2016-05-31 13:59:26 -0600 | [diff] [blame] | 7310 | } |
| 7311 | |
Cody Northrop | 3bb4d96 | 2016-05-09 16:15:57 -0600 | [diff] [blame] | 7312 | TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) { |
| 7313 | |
| 7314 | TEST_DESCRIPTION("End a command buffer with an active render pass"); |
| 7315 | |
| 7316 | m_errorMonitor->SetDesiredFailureMsg( |
| 7317 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7318 | "It is invalid to issue this call inside an active render pass"); |
| 7319 | |
| 7320 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7321 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7322 | |
| 7323 | // The framework's BeginCommandBuffer calls CreateRenderPass |
| 7324 | BeginCommandBuffer(); |
| 7325 | |
| 7326 | // Call directly into vkEndCommandBuffer instead of the |
| 7327 | // the framework's EndCommandBuffer, which inserts a |
| 7328 | // vkEndRenderPass |
| 7329 | vkEndCommandBuffer(m_commandBuffer->GetBufferHandle()); |
| 7330 | |
| 7331 | m_errorMonitor->VerifyFound(); |
| 7332 | |
| 7333 | // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY |
| 7334 | // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT |
| 7335 | } |
| 7336 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7337 | TEST_F(VkLayerTest, FillBufferWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7338 | // Call CmdFillBuffer within an active renderpass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7339 | m_errorMonitor->SetDesiredFailureMsg( |
| 7340 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7341 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7342 | |
| 7343 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7344 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7345 | |
| 7346 | // Renderpass is started here |
| 7347 | BeginCommandBuffer(); |
| 7348 | |
| 7349 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7350 | vk_testing::Buffer dstBuffer; |
| 7351 | dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7352 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7353 | m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7354 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7355 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7356 | } |
| 7357 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7358 | TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7359 | // Call CmdUpdateBuffer within an active renderpass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7360 | m_errorMonitor->SetDesiredFailureMsg( |
| 7361 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7362 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7363 | |
| 7364 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7365 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7366 | |
| 7367 | // Renderpass is started here |
| 7368 | BeginCommandBuffer(); |
| 7369 | |
| 7370 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7371 | vk_testing::Buffer dstBuffer; |
| 7372 | dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7373 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7374 | VkDeviceSize dstOffset = 0; |
| 7375 | VkDeviceSize dataSize = 1024; |
| 7376 | const uint32_t *pData = NULL; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7377 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7378 | vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), |
| 7379 | dstOffset, dataSize, pData); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7380 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7381 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7382 | } |
| 7383 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7384 | TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7385 | // Call CmdClearColorImage within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7386 | m_errorMonitor->SetDesiredFailureMsg( |
| 7387 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7388 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7389 | |
| 7390 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7391 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7392 | |
| 7393 | // Renderpass is started here |
| 7394 | BeginCommandBuffer(); |
| 7395 | |
Michael Lentine | 0a369f6 | 2016-02-03 16:51:46 -0600 | [diff] [blame] | 7396 | VkClearColorValue clear_color; |
| 7397 | memset(clear_color.uint32, 0, sizeof(uint32_t) * 4); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7398 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 7399 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 7400 | const int32_t tex_width = 32; |
| 7401 | const int32_t tex_height = 32; |
| 7402 | VkImageCreateInfo image_create_info = {}; |
| 7403 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 7404 | image_create_info.pNext = NULL; |
| 7405 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 7406 | image_create_info.format = tex_format; |
| 7407 | image_create_info.extent.width = tex_width; |
| 7408 | image_create_info.extent.height = tex_height; |
| 7409 | image_create_info.extent.depth = 1; |
| 7410 | image_create_info.mipLevels = 1; |
| 7411 | image_create_info.arrayLayers = 1; |
| 7412 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 7413 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 7414 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7415 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7416 | vk_testing::Image dstImage; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7417 | dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 7418 | reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7419 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7420 | const VkImageSubresourceRange range = vk_testing::Image::subresource_range( |
| 7421 | image_create_info, VK_IMAGE_ASPECT_COLOR_BIT); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7422 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7423 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), |
| 7424 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7425 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7426 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7427 | } |
| 7428 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7429 | TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7430 | // Call CmdClearDepthStencilImage within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7431 | m_errorMonitor->SetDesiredFailureMsg( |
| 7432 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7433 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7434 | |
| 7435 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7436 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7437 | |
| 7438 | // Renderpass is started here |
| 7439 | BeginCommandBuffer(); |
| 7440 | |
| 7441 | VkClearDepthStencilValue clear_value = {0}; |
Dustin Graves | a2e5c94 | 2016-02-11 18:28:06 -0700 | [diff] [blame] | 7442 | VkMemoryPropertyFlags reqs = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7443 | VkImageCreateInfo image_create_info = vk_testing::Image::create_info(); |
| 7444 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 7445 | image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 7446 | image_create_info.extent.width = 64; |
| 7447 | image_create_info.extent.height = 64; |
| 7448 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 7449 | image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7450 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7451 | vk_testing::Image dstImage; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7452 | dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 7453 | reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7454 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7455 | const VkImageSubresourceRange range = vk_testing::Image::subresource_range( |
| 7456 | image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7457 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7458 | vkCmdClearDepthStencilImage( |
| 7459 | m_commandBuffer->GetBufferHandle(), dstImage.handle(), |
| 7460 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, |
| 7461 | &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, ClearColorAttachmentsOutsideRenderPass) { |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 7467 | // Call CmdClearAttachmentss outside of an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7468 | VkResult err; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7469 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 7470 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7471 | "vkCmdClearAttachments: This call " |
| 7472 | "must be issued inside an active " |
| 7473 | "render pass"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7474 | |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7475 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7476 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7477 | |
| 7478 | // Start no RenderPass |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7479 | err = m_commandBuffer->BeginCommandBuffer(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7480 | ASSERT_VK_SUCCESS(err); |
| 7481 | |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 7482 | VkClearAttachment color_attachment; |
| 7483 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 7484 | color_attachment.clearValue.color.float32[0] = 0; |
| 7485 | color_attachment.clearValue.color.float32[1] = 0; |
| 7486 | color_attachment.clearValue.color.float32[2] = 0; |
| 7487 | color_attachment.clearValue.color.float32[3] = 0; |
| 7488 | color_attachment.colorAttachment = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7489 | VkClearRect clear_rect = {{{0, 0}, {32, 32}}}; |
| 7490 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 7491 | &color_attachment, 1, &clear_rect); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7492 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7493 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 7494 | } |
| 7495 | |
Karl Schultz | 9e66a29 | 2016-04-21 15:57:51 -0600 | [diff] [blame] | 7496 | TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) { |
| 7497 | // Try to add a buffer memory barrier with no buffer. |
| 7498 | m_errorMonitor->SetDesiredFailureMsg( |
| 7499 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7500 | "required parameter pBufferMemoryBarriers[i].buffer specified as VK_NULL_HANDLE"); |
| 7501 | |
| 7502 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7503 | BeginCommandBuffer(); |
| 7504 | |
| 7505 | VkBufferMemoryBarrier buf_barrier = {}; |
| 7506 | buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; |
| 7507 | buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 7508 | buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 7509 | buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7510 | buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7511 | buf_barrier.buffer = VK_NULL_HANDLE; |
| 7512 | buf_barrier.offset = 0; |
| 7513 | buf_barrier.size = VK_WHOLE_SIZE; |
| 7514 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7515 | VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, |
| 7516 | 0, 0, nullptr, 1, &buf_barrier, 0, nullptr); |
| 7517 | |
| 7518 | m_errorMonitor->VerifyFound(); |
| 7519 | } |
| 7520 | |
Tony Barbour | 7fd5c0f | 2016-05-03 16:11:53 -0600 | [diff] [blame] | 7521 | TEST_F(VkLayerTest, InvalidBarriers) { |
| 7522 | TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER "); |
| 7523 | |
| 7524 | m_errorMonitor->SetDesiredFailureMsg( |
| 7525 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass"); |
| 7526 | |
| 7527 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7528 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7529 | |
| 7530 | VkMemoryBarrier mem_barrier = {}; |
| 7531 | mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER; |
| 7532 | mem_barrier.pNext = NULL; |
| 7533 | mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 7534 | mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 7535 | BeginCommandBuffer(); |
| 7536 | // BeginCommandBuffer() starts a render pass |
| 7537 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7538 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7539 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1, |
| 7540 | &mem_barrier, 0, nullptr, 0, nullptr); |
| 7541 | m_errorMonitor->VerifyFound(); |
| 7542 | |
| 7543 | m_errorMonitor->SetDesiredFailureMsg( |
| 7544 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7545 | "Image Layout cannot be transitioned to UNDEFINED"); |
| 7546 | VkImageObj image(m_device); |
| 7547 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 7548 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 7549 | ASSERT_TRUE(image.initialized()); |
| 7550 | VkImageMemoryBarrier img_barrier = {}; |
| 7551 | img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 7552 | img_barrier.pNext = NULL; |
| 7553 | img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 7554 | img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 7555 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 7556 | // New layout can't be UNDEFINED |
| 7557 | img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 7558 | img_barrier.image = image.handle(); |
| 7559 | img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7560 | img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7561 | img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 7562 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 7563 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 7564 | img_barrier.subresourceRange.layerCount = 1; |
| 7565 | img_barrier.subresourceRange.levelCount = 1; |
| 7566 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7567 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7568 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 7569 | nullptr, 1, &img_barrier); |
| 7570 | m_errorMonitor->VerifyFound(); |
| 7571 | img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 7572 | |
| 7573 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7574 | "Subresource must have the sum of the " |
| 7575 | "baseArrayLayer"); |
| 7576 | // baseArrayLayer + layerCount must be <= image's arrayLayers |
| 7577 | img_barrier.subresourceRange.baseArrayLayer = 1; |
| 7578 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7579 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7580 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 7581 | nullptr, 1, &img_barrier); |
| 7582 | m_errorMonitor->VerifyFound(); |
| 7583 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 7584 | |
| 7585 | m_errorMonitor->SetDesiredFailureMsg( |
| 7586 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7587 | "Subresource must have the sum of the baseMipLevel"); |
| 7588 | // baseMipLevel + levelCount must be <= image's mipLevels |
| 7589 | img_barrier.subresourceRange.baseMipLevel = 1; |
| 7590 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7591 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7592 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 7593 | nullptr, 1, &img_barrier); |
| 7594 | m_errorMonitor->VerifyFound(); |
| 7595 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 7596 | |
| 7597 | m_errorMonitor->SetDesiredFailureMsg( |
| 7598 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7599 | "Buffer Barriers cannot be used during a render pass"); |
| 7600 | vk_testing::Buffer buffer; |
| 7601 | buffer.init(*m_device, 256); |
| 7602 | VkBufferMemoryBarrier buf_barrier = {}; |
| 7603 | buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; |
| 7604 | buf_barrier.pNext = NULL; |
| 7605 | buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 7606 | buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 7607 | buf_barrier.buffer = buffer.handle(); |
| 7608 | buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7609 | buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 7610 | buf_barrier.offset = 0; |
| 7611 | buf_barrier.size = VK_WHOLE_SIZE; |
| 7612 | // Can't send buffer barrier during a render pass |
| 7613 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7614 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7615 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 7616 | &buf_barrier, 0, nullptr); |
| 7617 | m_errorMonitor->VerifyFound(); |
| 7618 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 7619 | |
| 7620 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7621 | "which is not less than total size"); |
| 7622 | buf_barrier.offset = 257; |
| 7623 | // Offset greater than total size |
| 7624 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7625 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7626 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 7627 | &buf_barrier, 0, nullptr); |
| 7628 | m_errorMonitor->VerifyFound(); |
| 7629 | buf_barrier.offset = 0; |
| 7630 | |
| 7631 | m_errorMonitor->SetDesiredFailureMsg( |
| 7632 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size"); |
| 7633 | buf_barrier.size = 257; |
| 7634 | // Size greater than total size |
| 7635 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7636 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7637 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 7638 | &buf_barrier, 0, nullptr); |
| 7639 | m_errorMonitor->VerifyFound(); |
| 7640 | buf_barrier.size = VK_WHOLE_SIZE; |
| 7641 | |
| 7642 | m_errorMonitor->SetDesiredFailureMsg( |
| 7643 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7644 | "Image is a depth and stencil format and thus must " |
| 7645 | "have both VK_IMAGE_ASPECT_DEPTH_BIT and " |
| 7646 | "VK_IMAGE_ASPECT_STENCIL_BIT set."); |
| 7647 | VkDepthStencilObj ds_image(m_device); |
| 7648 | ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT); |
| 7649 | ASSERT_TRUE(ds_image.initialized()); |
| 7650 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 7651 | img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 7652 | img_barrier.image = ds_image.handle(); |
| 7653 | // Leave aspectMask at COLOR on purpose |
| 7654 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 7655 | VK_PIPELINE_STAGE_HOST_BIT, |
| 7656 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 7657 | nullptr, 1, &img_barrier); |
| 7658 | m_errorMonitor->VerifyFound(); |
| 7659 | } |
| 7660 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7661 | TEST_F(VkLayerTest, IdxBufferAlignmentError) { |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7662 | // Bind a BeginRenderPass within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7663 | VkResult err; |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7664 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7665 | m_errorMonitor->SetDesiredFailureMsg( |
| 7666 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7667 | "vkCmdBindIndexBuffer() offset (0x7) does not fall on "); |
| 7668 | |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7669 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7670 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7671 | uint32_t qfi = 0; |
| 7672 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7673 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 7674 | buffCI.size = 1024; |
| 7675 | buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; |
| 7676 | buffCI.queueFamilyIndexCount = 1; |
| 7677 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7678 | |
| 7679 | VkBuffer ib; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7680 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7681 | ASSERT_VK_SUCCESS(err); |
| 7682 | |
| 7683 | BeginCommandBuffer(); |
| 7684 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7685 | // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 7686 | // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7687 | // 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] | 7688 | vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, |
| 7689 | VK_INDEX_TYPE_UINT16); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7690 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7691 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 7692 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7693 | vkDestroyBuffer(m_device->device(), ib, NULL); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 7694 | } |
| 7695 | |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 7696 | TEST_F(VkLayerTest, InvalidQueueFamilyIndex) { |
| 7697 | // Create an out-of-range queueFamilyIndex |
| 7698 | m_errorMonitor->SetDesiredFailureMsg( |
| 7699 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Dustin Graves | de62853 | 2016-04-21 16:30:17 -0600 | [diff] [blame] | 7700 | "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one " |
| 7701 | "of the indices specified when the device was created, via the " |
| 7702 | "VkDeviceQueueCreateInfo structure."); |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 7703 | |
| 7704 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7705 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 7706 | VkBufferCreateInfo buffCI = {}; |
| 7707 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 7708 | buffCI.size = 1024; |
| 7709 | buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; |
| 7710 | buffCI.queueFamilyIndexCount = 1; |
| 7711 | // Introduce failure by specifying invalid queue_family_index |
| 7712 | uint32_t qfi = 777; |
| 7713 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 24aab04 | 2016-03-24 10:54:18 -0600 | [diff] [blame] | 7714 | buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 7715 | |
| 7716 | VkBuffer ib; |
| 7717 | vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib); |
| 7718 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7719 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7720 | vkDestroyBuffer(m_device->device(), ib, NULL); |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 7721 | } |
| 7722 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7723 | TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) { |
| 7724 | // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be |
| 7725 | // secondary) |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7726 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7727 | m_errorMonitor->SetDesiredFailureMsg( |
| 7728 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7729 | "vkCmdExecuteCommands() called w/ Primary Cmd Buffer "); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 7730 | |
| 7731 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7732 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 7733 | |
| 7734 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7735 | // ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7736 | VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle(); |
| 7737 | vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 7738 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7739 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 7740 | } |
| 7741 | |
Tobin Ehlis | 17826bd | 2016-05-25 11:12:50 -0600 | [diff] [blame] | 7742 | TEST_F(VkLayerTest, DSUsageBitsErrors) { |
| 7743 | TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers " |
| 7744 | "that do not have correct usage bits sets."); |
| 7745 | VkResult err; |
| 7746 | |
| 7747 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7748 | VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {}; |
| 7749 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 7750 | ds_type_count[i].type = VkDescriptorType(i); |
| 7751 | ds_type_count[i].descriptorCount = 1; |
| 7752 | } |
| 7753 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 7754 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7755 | ds_pool_ci.pNext = NULL; |
| 7756 | ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 7757 | ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 7758 | ds_pool_ci.pPoolSizes = ds_type_count; |
| 7759 | |
| 7760 | VkDescriptorPool ds_pool; |
| 7761 | err = |
| 7762 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 7763 | ASSERT_VK_SUCCESS(err); |
| 7764 | |
| 7765 | // Create 10 layouts where each has a single descriptor of different type |
| 7766 | VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = |
| 7767 | {}; |
| 7768 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 7769 | dsl_binding[i].binding = 0; |
| 7770 | dsl_binding[i].descriptorType = VkDescriptorType(i); |
| 7771 | dsl_binding[i].descriptorCount = 1; |
| 7772 | dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL; |
| 7773 | dsl_binding[i].pImmutableSamplers = NULL; |
| 7774 | } |
| 7775 | |
| 7776 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 7777 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7778 | ds_layout_ci.pNext = NULL; |
| 7779 | ds_layout_ci.bindingCount = 1; |
| 7780 | VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE]; |
| 7781 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 7782 | ds_layout_ci.pBindings = dsl_binding + i; |
| 7783 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, |
| 7784 | NULL, ds_layouts + i); |
| 7785 | ASSERT_VK_SUCCESS(err); |
| 7786 | } |
| 7787 | VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {}; |
| 7788 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 7789 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 7790 | alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 7791 | alloc_info.descriptorPool = ds_pool; |
| 7792 | alloc_info.pSetLayouts = ds_layouts; |
| 7793 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7794 | descriptor_sets); |
| 7795 | ASSERT_VK_SUCCESS(err); |
| 7796 | |
| 7797 | // Create a buffer & bufferView to be used for invalid updates |
| 7798 | VkBufferCreateInfo buff_ci = {}; |
| 7799 | buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 7800 | // This usage is not valid for any descriptor type |
| 7801 | buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; |
| 7802 | buff_ci.size = 256; |
| 7803 | buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 7804 | VkBuffer buffer; |
| 7805 | err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer); |
| 7806 | ASSERT_VK_SUCCESS(err); |
| 7807 | |
| 7808 | VkBufferViewCreateInfo buff_view_ci = {}; |
| 7809 | buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; |
| 7810 | buff_view_ci.buffer = buffer; |
| 7811 | buff_view_ci.format = VK_FORMAT_R8_UNORM; |
| 7812 | buff_view_ci.range = VK_WHOLE_SIZE; |
| 7813 | VkBufferView buff_view; |
| 7814 | err = |
| 7815 | vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view); |
| 7816 | ASSERT_VK_SUCCESS(err); |
| 7817 | |
| 7818 | // Create an image to be used for invalid updates |
| 7819 | VkImageCreateInfo image_ci = {}; |
| 7820 | image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 7821 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 7822 | image_ci.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 7823 | image_ci.extent.width = 64; |
| 7824 | image_ci.extent.height = 64; |
| 7825 | image_ci.extent.depth = 1; |
| 7826 | image_ci.mipLevels = 1; |
| 7827 | image_ci.arrayLayers = 1; |
| 7828 | image_ci.samples = VK_SAMPLE_COUNT_1_BIT; |
| 7829 | image_ci.tiling = VK_IMAGE_TILING_LINEAR; |
| 7830 | image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 7831 | // This usage is not valid for any descriptor type |
| 7832 | image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 7833 | image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 7834 | VkImage image; |
| 7835 | err = vkCreateImage(m_device->device(), &image_ci, NULL, &image); |
| 7836 | ASSERT_VK_SUCCESS(err); |
| 7837 | // Bind memory to image |
| 7838 | VkMemoryRequirements mem_reqs; |
| 7839 | VkDeviceMemory image_mem; |
| 7840 | bool pass; |
| 7841 | VkMemoryAllocateInfo mem_alloc = {}; |
| 7842 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 7843 | mem_alloc.pNext = NULL; |
| 7844 | mem_alloc.allocationSize = 0; |
| 7845 | mem_alloc.memoryTypeIndex = 0; |
| 7846 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 7847 | mem_alloc.allocationSize = mem_reqs.size; |
| 7848 | pass = |
| 7849 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 7850 | ASSERT_TRUE(pass); |
| 7851 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem); |
| 7852 | ASSERT_VK_SUCCESS(err); |
| 7853 | err = vkBindImageMemory(m_device->device(), image, image_mem, 0); |
| 7854 | ASSERT_VK_SUCCESS(err); |
| 7855 | // Now create view for image |
| 7856 | VkImageViewCreateInfo image_view_ci = {}; |
| 7857 | image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 7858 | image_view_ci.image = image; |
| 7859 | image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 7860 | image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 7861 | image_view_ci.subresourceRange.layerCount = 1; |
| 7862 | image_view_ci.subresourceRange.baseArrayLayer = 0; |
| 7863 | image_view_ci.subresourceRange.levelCount = 1; |
| 7864 | image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 7865 | VkImageView image_view; |
| 7866 | err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, |
| 7867 | &image_view); |
| 7868 | ASSERT_VK_SUCCESS(err); |
| 7869 | |
| 7870 | VkDescriptorBufferInfo buff_info = {}; |
| 7871 | buff_info.buffer = buffer; |
| 7872 | VkDescriptorImageInfo img_info = {}; |
| 7873 | img_info.imageView = image_view; |
| 7874 | VkWriteDescriptorSet descriptor_write = {}; |
| 7875 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 7876 | descriptor_write.dstBinding = 0; |
| 7877 | descriptor_write.descriptorCount = 1; |
| 7878 | descriptor_write.pTexelBufferView = &buff_view; |
| 7879 | descriptor_write.pBufferInfo = &buff_info; |
| 7880 | descriptor_write.pImageInfo = &img_info; |
| 7881 | |
| 7882 | // These error messages align with VkDescriptorType struct |
| 7883 | const char *error_msgs[] = { |
| 7884 | "", // placeholder, no error for SAMPLER descriptor |
| 7885 | " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.", |
| 7886 | " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.", |
| 7887 | " does not have VK_IMAGE_USAGE_STORAGE_BIT set.", |
| 7888 | " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.", |
| 7889 | " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.", |
| 7890 | " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.", |
| 7891 | " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.", |
| 7892 | " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.", |
| 7893 | " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.", |
| 7894 | " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."}; |
| 7895 | // Start loop at 1 as SAMPLER desc type has no usage bit error |
| 7896 | for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 7897 | descriptor_write.descriptorType = VkDescriptorType(i); |
| 7898 | descriptor_write.dstSet = descriptor_sets[i]; |
| 7899 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7900 | error_msgs[i]); |
| 7901 | |
| 7902 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, |
| 7903 | NULL); |
| 7904 | |
| 7905 | m_errorMonitor->VerifyFound(); |
| 7906 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL); |
| 7907 | } |
| 7908 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL); |
| 7909 | vkDestroyImage(m_device->device(), image, NULL); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 7910 | vkFreeMemory(m_device->device(), image_mem, NULL); |
Tobin Ehlis | 17826bd | 2016-05-25 11:12:50 -0600 | [diff] [blame] | 7911 | vkDestroyImageView(m_device->device(), image_view, NULL); |
| 7912 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 7913 | vkDestroyBufferView(m_device->device(), buff_view, NULL); |
| 7914 | vkFreeDescriptorSets(m_device->device(), ds_pool, |
| 7915 | VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets); |
| 7916 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 7917 | } |
| 7918 | |
Tobin Ehlis | 2fc296b | 2016-06-15 14:05:27 -0600 | [diff] [blame] | 7919 | TEST_F(VkLayerTest, DSAspectBitsErrors) { |
| 7920 | // TODO : Initially only catching case where DEPTH & STENCIL aspect bits |
| 7921 | // are set, but could expand this test to hit more cases. |
| 7922 | TEST_DESCRIPTION("Attempt to update descriptor sets for images " |
| 7923 | "that do not have correct aspect bits sets."); |
| 7924 | VkResult err; |
| 7925 | |
| 7926 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7927 | VkDescriptorPoolSize ds_type_count = {}; |
| 7928 | ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 7929 | ds_type_count.descriptorCount = 1; |
| 7930 | |
| 7931 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 7932 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7933 | ds_pool_ci.pNext = NULL; |
| 7934 | ds_pool_ci.maxSets = 5; |
| 7935 | ds_pool_ci.poolSizeCount = 1; |
| 7936 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 7937 | |
| 7938 | VkDescriptorPool ds_pool; |
| 7939 | err = |
| 7940 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 7941 | ASSERT_VK_SUCCESS(err); |
| 7942 | |
| 7943 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 7944 | dsl_binding.binding = 0; |
| 7945 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 7946 | dsl_binding.descriptorCount = 1; |
| 7947 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7948 | dsl_binding.pImmutableSamplers = NULL; |
| 7949 | |
| 7950 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 7951 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7952 | ds_layout_ci.pNext = NULL; |
| 7953 | ds_layout_ci.bindingCount = 1; |
| 7954 | ds_layout_ci.pBindings = &dsl_binding; |
| 7955 | VkDescriptorSetLayout ds_layout; |
| 7956 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7957 | &ds_layout); |
| 7958 | ASSERT_VK_SUCCESS(err); |
| 7959 | |
| 7960 | VkDescriptorSet descriptor_set = {}; |
| 7961 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 7962 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 7963 | alloc_info.descriptorSetCount = 1; |
| 7964 | alloc_info.descriptorPool = ds_pool; |
| 7965 | alloc_info.pSetLayouts = &ds_layout; |
| 7966 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7967 | &descriptor_set); |
| 7968 | ASSERT_VK_SUCCESS(err); |
| 7969 | |
| 7970 | // Create an image to be used for invalid updates |
| 7971 | VkImageCreateInfo image_ci = {}; |
| 7972 | image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 7973 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 7974 | image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 7975 | image_ci.extent.width = 64; |
| 7976 | image_ci.extent.height = 64; |
| 7977 | image_ci.extent.depth = 1; |
| 7978 | image_ci.mipLevels = 1; |
| 7979 | image_ci.arrayLayers = 1; |
| 7980 | image_ci.samples = VK_SAMPLE_COUNT_1_BIT; |
| 7981 | image_ci.tiling = VK_IMAGE_TILING_LINEAR; |
| 7982 | image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 7983 | image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 7984 | image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 7985 | VkImage image; |
| 7986 | err = vkCreateImage(m_device->device(), &image_ci, NULL, &image); |
| 7987 | ASSERT_VK_SUCCESS(err); |
| 7988 | // Bind memory to image |
| 7989 | VkMemoryRequirements mem_reqs; |
| 7990 | VkDeviceMemory image_mem; |
| 7991 | bool pass; |
| 7992 | VkMemoryAllocateInfo mem_alloc = {}; |
| 7993 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 7994 | mem_alloc.pNext = NULL; |
| 7995 | mem_alloc.allocationSize = 0; |
| 7996 | mem_alloc.memoryTypeIndex = 0; |
| 7997 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 7998 | mem_alloc.allocationSize = mem_reqs.size; |
| 7999 | pass = |
| 8000 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 8001 | ASSERT_TRUE(pass); |
| 8002 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem); |
| 8003 | ASSERT_VK_SUCCESS(err); |
| 8004 | err = vkBindImageMemory(m_device->device(), image, image_mem, 0); |
| 8005 | ASSERT_VK_SUCCESS(err); |
| 8006 | // Now create view for image |
| 8007 | VkImageViewCreateInfo image_view_ci = {}; |
| 8008 | image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 8009 | image_view_ci.image = image; |
| 8010 | image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 8011 | image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 8012 | image_view_ci.subresourceRange.layerCount = 1; |
| 8013 | image_view_ci.subresourceRange.baseArrayLayer = 0; |
| 8014 | image_view_ci.subresourceRange.levelCount = 1; |
| 8015 | // Setting both depth & stencil aspect bits is illegal for descriptor |
| 8016 | image_view_ci.subresourceRange.aspectMask = |
| 8017 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
| 8018 | |
| 8019 | VkImageView image_view; |
| 8020 | err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, |
| 8021 | &image_view); |
| 8022 | ASSERT_VK_SUCCESS(err); |
| 8023 | |
| 8024 | VkDescriptorImageInfo img_info = {}; |
| 8025 | img_info.imageView = image_view; |
| 8026 | VkWriteDescriptorSet descriptor_write = {}; |
| 8027 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 8028 | descriptor_write.dstBinding = 0; |
| 8029 | descriptor_write.descriptorCount = 1; |
| 8030 | descriptor_write.pTexelBufferView = NULL; |
| 8031 | descriptor_write.pBufferInfo = NULL; |
| 8032 | descriptor_write.pImageInfo = &img_info; |
| 8033 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 8034 | descriptor_write.dstSet = descriptor_set; |
| 8035 | const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT " |
| 8036 | "or VK_IMAGE_ASPECT_STENCIL_BIT "; |
| 8037 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8038 | error_msg); |
| 8039 | |
| 8040 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8041 | |
| 8042 | m_errorMonitor->VerifyFound(); |
| 8043 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8044 | vkDestroyImage(m_device->device(), image, NULL); |
| 8045 | vkFreeMemory(m_device->device(), image_mem, NULL); |
| 8046 | vkDestroyImageView(m_device->device(), image_view, NULL); |
| 8047 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set); |
| 8048 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 8049 | } |
| 8050 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8051 | TEST_F(VkLayerTest, DSTypeMismatch) { |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8052 | // 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] | 8053 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8054 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8055 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8056 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8057 | " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update " |
| 8058 | "type is VK_DESCRIPTOR_TYPE_SAMPLER"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8059 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8060 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8061 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8062 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8063 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8064 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8065 | |
| 8066 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8067 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8068 | ds_pool_ci.pNext = NULL; |
| 8069 | ds_pool_ci.maxSets = 1; |
| 8070 | ds_pool_ci.poolSizeCount = 1; |
| 8071 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8072 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8073 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8074 | err = |
| 8075 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8076 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8077 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8078 | dsl_binding.binding = 0; |
| 8079 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8080 | dsl_binding.descriptorCount = 1; |
| 8081 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8082 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8083 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8084 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8085 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8086 | ds_layout_ci.pNext = NULL; |
| 8087 | ds_layout_ci.bindingCount = 1; |
| 8088 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8089 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8090 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8091 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8092 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8093 | ASSERT_VK_SUCCESS(err); |
| 8094 | |
| 8095 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8096 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8097 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8098 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8099 | alloc_info.descriptorPool = ds_pool; |
| 8100 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8101 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8102 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8103 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8104 | |
Tobin Ehlis | 30db8f8 | 2016-05-05 08:19:48 -0600 | [diff] [blame] | 8105 | VkSamplerCreateInfo sampler_ci = {}; |
| 8106 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8107 | sampler_ci.pNext = NULL; |
| 8108 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8109 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8110 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8111 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8112 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8113 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8114 | sampler_ci.mipLodBias = 1.0; |
| 8115 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8116 | sampler_ci.maxAnisotropy = 1; |
| 8117 | sampler_ci.compareEnable = VK_FALSE; |
| 8118 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8119 | sampler_ci.minLod = 1.0; |
| 8120 | sampler_ci.maxLod = 1.0; |
| 8121 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8122 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
| 8123 | VkSampler sampler; |
| 8124 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
| 8125 | ASSERT_VK_SUCCESS(err); |
| 8126 | |
| 8127 | VkDescriptorImageInfo info = {}; |
| 8128 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8129 | |
| 8130 | VkWriteDescriptorSet descriptor_write; |
| 8131 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8132 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8133 | descriptor_write.dstSet = descriptorSet; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8134 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8135 | // This is a mismatched type for the layout which expects BUFFER |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8136 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8137 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8138 | |
| 8139 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8140 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8141 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8142 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8143 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8144 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8145 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8146 | } |
| 8147 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8148 | TEST_F(VkLayerTest, DSUpdateOutOfBounds) { |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8149 | // For overlapping Update, have arrayIndex exceed that of layout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8150 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8151 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8152 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8153 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8154 | " binding #0 with 1 total descriptors but update of 1 descriptors " |
| 8155 | "starting at binding offset of 0 combined with update array element " |
| 8156 | "offset of 1 oversteps the size of this descriptor set."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8157 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8158 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8159 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8160 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8161 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8162 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8163 | |
| 8164 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8165 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8166 | ds_pool_ci.pNext = NULL; |
| 8167 | ds_pool_ci.maxSets = 1; |
| 8168 | ds_pool_ci.poolSizeCount = 1; |
| 8169 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8170 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8171 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8172 | err = |
| 8173 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8174 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8175 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8176 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8177 | dsl_binding.binding = 0; |
| 8178 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8179 | dsl_binding.descriptorCount = 1; |
| 8180 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8181 | dsl_binding.pImmutableSamplers = NULL; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8182 | |
| 8183 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8184 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8185 | ds_layout_ci.pNext = NULL; |
| 8186 | ds_layout_ci.bindingCount = 1; |
| 8187 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8188 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8189 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8190 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8191 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8192 | ASSERT_VK_SUCCESS(err); |
| 8193 | |
| 8194 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8195 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8196 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8197 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8198 | alloc_info.descriptorPool = ds_pool; |
| 8199 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8200 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8201 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8202 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8203 | |
Tobin Ehlis | 30db8f8 | 2016-05-05 08:19:48 -0600 | [diff] [blame] | 8204 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 8205 | VkDescriptorBufferInfo buff_info = {}; |
| 8206 | buff_info.buffer = |
| 8207 | VkBuffer(0); // Don't care about buffer handle for this test |
| 8208 | buff_info.offset = 0; |
| 8209 | buff_info.range = 1024; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8210 | |
| 8211 | VkWriteDescriptorSet descriptor_write; |
| 8212 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8213 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8214 | descriptor_write.dstSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8215 | descriptor_write.dstArrayElement = |
| 8216 | 1; /* This index out of bounds for the update */ |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8217 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8218 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8219 | descriptor_write.pBufferInfo = &buff_info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8220 | |
| 8221 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8222 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8223 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8224 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8225 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8226 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8227 | } |
| 8228 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8229 | TEST_F(VkLayerTest, InvalidDSUpdateIndex) { |
| 8230 | // Create layout w/ count of 1 and attempt update to that layout w/ binding |
| 8231 | // index 2 |
| 8232 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8233 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8234 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8235 | " does not have binding 2."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8236 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8237 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8238 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8239 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8240 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8241 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8242 | |
| 8243 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8244 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8245 | ds_pool_ci.pNext = NULL; |
| 8246 | ds_pool_ci.maxSets = 1; |
| 8247 | ds_pool_ci.poolSizeCount = 1; |
| 8248 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 8249 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8250 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8251 | err = |
| 8252 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8253 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8254 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8255 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8256 | dsl_binding.binding = 0; |
| 8257 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8258 | dsl_binding.descriptorCount = 1; |
| 8259 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8260 | dsl_binding.pImmutableSamplers = NULL; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8261 | |
| 8262 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8263 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8264 | ds_layout_ci.pNext = NULL; |
| 8265 | ds_layout_ci.bindingCount = 1; |
| 8266 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8267 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8268 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8269 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8270 | ASSERT_VK_SUCCESS(err); |
| 8271 | |
| 8272 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8273 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8274 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8275 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8276 | alloc_info.descriptorPool = ds_pool; |
| 8277 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8278 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8279 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8280 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8281 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8282 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8283 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8284 | sampler_ci.pNext = NULL; |
| 8285 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8286 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8287 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8288 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8289 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8290 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8291 | sampler_ci.mipLodBias = 1.0; |
| 8292 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8293 | sampler_ci.maxAnisotropy = 1; |
| 8294 | sampler_ci.compareEnable = VK_FALSE; |
| 8295 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8296 | sampler_ci.minLod = 1.0; |
| 8297 | sampler_ci.maxLod = 1.0; |
| 8298 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8299 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8300 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8301 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8302 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8303 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8304 | |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8305 | VkDescriptorImageInfo info = {}; |
| 8306 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8307 | |
| 8308 | VkWriteDescriptorSet descriptor_write; |
| 8309 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8310 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8311 | descriptor_write.dstSet = descriptorSet; |
| 8312 | descriptor_write.dstBinding = 2; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8313 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8314 | // 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] | 8315 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8316 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8317 | |
| 8318 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8319 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8320 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8321 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8322 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8323 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8324 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8325 | } |
| 8326 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8327 | TEST_F(VkLayerTest, InvalidDSUpdateStruct) { |
| 8328 | // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* |
| 8329 | // types |
| 8330 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8331 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 8332 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 660bcdc | 2016-05-17 10:39:46 -0600 | [diff] [blame] | 8333 | ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8334 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8335 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 8336 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8337 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8338 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8339 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8340 | |
| 8341 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8342 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8343 | ds_pool_ci.pNext = NULL; |
| 8344 | ds_pool_ci.maxSets = 1; |
| 8345 | ds_pool_ci.poolSizeCount = 1; |
| 8346 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 8347 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8348 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8349 | err = |
| 8350 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8351 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8352 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8353 | dsl_binding.binding = 0; |
| 8354 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8355 | dsl_binding.descriptorCount = 1; |
| 8356 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8357 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8358 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8359 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8360 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8361 | ds_layout_ci.pNext = NULL; |
| 8362 | ds_layout_ci.bindingCount = 1; |
| 8363 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8364 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8365 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8366 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8367 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8368 | ASSERT_VK_SUCCESS(err); |
| 8369 | |
| 8370 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8371 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8372 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8373 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8374 | alloc_info.descriptorPool = ds_pool; |
| 8375 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8376 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8377 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8378 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8379 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8380 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8381 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8382 | sampler_ci.pNext = NULL; |
| 8383 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8384 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8385 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8386 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8387 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8388 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8389 | sampler_ci.mipLodBias = 1.0; |
| 8390 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8391 | sampler_ci.maxAnisotropy = 1; |
| 8392 | sampler_ci.compareEnable = VK_FALSE; |
| 8393 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8394 | sampler_ci.minLod = 1.0; |
| 8395 | sampler_ci.maxLod = 1.0; |
| 8396 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8397 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8398 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8399 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8400 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8401 | |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8402 | VkDescriptorImageInfo info = {}; |
| 8403 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8404 | |
| 8405 | VkWriteDescriptorSet descriptor_write; |
| 8406 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8407 | descriptor_write.sType = |
| 8408 | (VkStructureType)0x99999999; /* Intentionally broken struct type */ |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8409 | descriptor_write.dstSet = descriptorSet; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8410 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8411 | // 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] | 8412 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 8413 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 8414 | |
| 8415 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8416 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8417 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8418 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8419 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8420 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8421 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8422 | } |
| 8423 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8424 | TEST_F(VkLayerTest, SampleDescriptorUpdateError) { |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8425 | // Create a single Sampler descriptor and send it an invalid Sampler |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8426 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8427 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8428 | m_errorMonitor->SetDesiredFailureMsg( |
| 8429 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8430 | "Attempted write update to sampler descriptor with invalid sampler"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8431 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8432 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8433 | // TODO : Farm Descriptor setup code to helper function(s) to reduce copied |
| 8434 | // code |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8435 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8436 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8437 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8438 | |
| 8439 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8440 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8441 | ds_pool_ci.pNext = NULL; |
| 8442 | ds_pool_ci.maxSets = 1; |
| 8443 | ds_pool_ci.poolSizeCount = 1; |
| 8444 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8445 | |
| 8446 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8447 | err = |
| 8448 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8449 | ASSERT_VK_SUCCESS(err); |
| 8450 | |
| 8451 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8452 | dsl_binding.binding = 0; |
| 8453 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8454 | dsl_binding.descriptorCount = 1; |
| 8455 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8456 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8457 | |
| 8458 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8459 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8460 | ds_layout_ci.pNext = NULL; |
| 8461 | ds_layout_ci.bindingCount = 1; |
| 8462 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8463 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8464 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8465 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8466 | ASSERT_VK_SUCCESS(err); |
| 8467 | |
| 8468 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8469 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8470 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8471 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8472 | alloc_info.descriptorPool = ds_pool; |
| 8473 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8474 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8475 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8476 | ASSERT_VK_SUCCESS(err); |
| 8477 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8478 | VkSampler sampler = |
| 8479 | (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8480 | |
| 8481 | VkDescriptorImageInfo descriptor_info; |
| 8482 | memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo)); |
| 8483 | descriptor_info.sampler = sampler; |
| 8484 | |
| 8485 | VkWriteDescriptorSet descriptor_write; |
| 8486 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8487 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8488 | descriptor_write.dstSet = descriptorSet; |
| 8489 | descriptor_write.dstBinding = 0; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8490 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8491 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8492 | descriptor_write.pImageInfo = &descriptor_info; |
| 8493 | |
| 8494 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8495 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8496 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8497 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8498 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8499 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8500 | } |
| 8501 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8502 | TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) { |
| 8503 | // Create a single combined Image/Sampler descriptor and send it an invalid |
| 8504 | // imageView |
| 8505 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8506 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8507 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8508 | "Attempted write update to combined " |
| 8509 | "image sampler descriptor failed due " |
Tobin Ehlis | 63c4b8a | 2016-05-09 10:29:34 -0600 | [diff] [blame] | 8510 | "to: Invalid VkImageView:"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8511 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8512 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8513 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8514 | ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 8515 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8516 | |
| 8517 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8518 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8519 | ds_pool_ci.pNext = NULL; |
| 8520 | ds_pool_ci.maxSets = 1; |
| 8521 | ds_pool_ci.poolSizeCount = 1; |
| 8522 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8523 | |
| 8524 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8525 | err = |
| 8526 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8527 | ASSERT_VK_SUCCESS(err); |
| 8528 | |
| 8529 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8530 | dsl_binding.binding = 0; |
| 8531 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 8532 | dsl_binding.descriptorCount = 1; |
| 8533 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8534 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8535 | |
| 8536 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8537 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8538 | ds_layout_ci.pNext = NULL; |
| 8539 | ds_layout_ci.bindingCount = 1; |
| 8540 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8541 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8542 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8543 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8544 | ASSERT_VK_SUCCESS(err); |
| 8545 | |
| 8546 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8547 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8548 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8549 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8550 | alloc_info.descriptorPool = ds_pool; |
| 8551 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8552 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8553 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8554 | ASSERT_VK_SUCCESS(err); |
| 8555 | |
| 8556 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8557 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8558 | sampler_ci.pNext = NULL; |
| 8559 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8560 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8561 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8562 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8563 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8564 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8565 | sampler_ci.mipLodBias = 1.0; |
| 8566 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8567 | sampler_ci.maxAnisotropy = 1; |
| 8568 | sampler_ci.compareEnable = VK_FALSE; |
| 8569 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8570 | sampler_ci.minLod = 1.0; |
| 8571 | sampler_ci.maxLod = 1.0; |
| 8572 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8573 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8574 | |
| 8575 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8576 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8577 | ASSERT_VK_SUCCESS(err); |
| 8578 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8579 | VkImageView view = |
| 8580 | (VkImageView)((size_t)0xbaadbeef); // invalid imageView object |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8581 | |
| 8582 | VkDescriptorImageInfo descriptor_info; |
| 8583 | memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo)); |
| 8584 | descriptor_info.sampler = sampler; |
| 8585 | descriptor_info.imageView = view; |
| 8586 | |
| 8587 | VkWriteDescriptorSet descriptor_write; |
| 8588 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 8589 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8590 | descriptor_write.dstSet = descriptorSet; |
| 8591 | descriptor_write.dstBinding = 0; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8592 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8593 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 8594 | descriptor_write.pImageInfo = &descriptor_info; |
| 8595 | |
| 8596 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8597 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8598 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8599 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8600 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8601 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8602 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 8603 | } |
| 8604 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8605 | TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) { |
| 8606 | // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update |
| 8607 | // into the other |
| 8608 | VkResult err; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8609 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8610 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8611 | " binding #1 with type " |
| 8612 | "VK_DESCRIPTOR_TYPE_SAMPLER. Types do " |
| 8613 | "not match."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8614 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8615 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8616 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8617 | VkDescriptorPoolSize ds_type_count[2] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8618 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8619 | ds_type_count[0].descriptorCount = 1; |
| 8620 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8621 | ds_type_count[1].descriptorCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8622 | |
| 8623 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8624 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8625 | ds_pool_ci.pNext = NULL; |
| 8626 | ds_pool_ci.maxSets = 1; |
| 8627 | ds_pool_ci.poolSizeCount = 2; |
| 8628 | ds_pool_ci.pPoolSizes = ds_type_count; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8629 | |
| 8630 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8631 | err = |
| 8632 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8633 | ASSERT_VK_SUCCESS(err); |
| 8634 | VkDescriptorSetLayoutBinding dsl_binding[2] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8635 | dsl_binding[0].binding = 0; |
| 8636 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8637 | dsl_binding[0].descriptorCount = 1; |
| 8638 | dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 8639 | dsl_binding[0].pImmutableSamplers = NULL; |
| 8640 | dsl_binding[1].binding = 1; |
| 8641 | dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8642 | dsl_binding[1].descriptorCount = 1; |
| 8643 | dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL; |
| 8644 | dsl_binding[1].pImmutableSamplers = NULL; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8645 | |
| 8646 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8647 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8648 | ds_layout_ci.pNext = NULL; |
| 8649 | ds_layout_ci.bindingCount = 2; |
| 8650 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8651 | |
| 8652 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8653 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8654 | &ds_layout); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8655 | ASSERT_VK_SUCCESS(err); |
| 8656 | |
| 8657 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8658 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8659 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8660 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8661 | alloc_info.descriptorPool = ds_pool; |
| 8662 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8663 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8664 | &descriptorSet); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8665 | ASSERT_VK_SUCCESS(err); |
| 8666 | |
| 8667 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8668 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 8669 | sampler_ci.pNext = NULL; |
| 8670 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 8671 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 8672 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 8673 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8674 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8675 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 8676 | sampler_ci.mipLodBias = 1.0; |
| 8677 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 8678 | sampler_ci.maxAnisotropy = 1; |
| 8679 | sampler_ci.compareEnable = VK_FALSE; |
| 8680 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 8681 | sampler_ci.minLod = 1.0; |
| 8682 | sampler_ci.maxLod = 1.0; |
| 8683 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 8684 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8685 | |
| 8686 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8687 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8688 | ASSERT_VK_SUCCESS(err); |
| 8689 | |
| 8690 | VkDescriptorImageInfo info = {}; |
| 8691 | info.sampler = sampler; |
| 8692 | |
| 8693 | VkWriteDescriptorSet descriptor_write; |
| 8694 | memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet)); |
| 8695 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8696 | descriptor_write.dstSet = descriptorSet; |
| 8697 | descriptor_write.dstBinding = 1; // SAMPLER binding from layout above |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8698 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8699 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 8700 | descriptor_write.pImageInfo = &info; |
| 8701 | // This write update should succeed |
| 8702 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 8703 | // Now perform a copy update that fails due to type mismatch |
| 8704 | VkCopyDescriptorSet copy_ds_update; |
| 8705 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 8706 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 8707 | copy_ds_update.srcSet = descriptorSet; |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 8708 | copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8709 | copy_ds_update.dstSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8710 | copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8711 | copy_ds_update.descriptorCount = 1; // copy 1 descriptor |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8712 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 8713 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8714 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8715 | // 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] | 8716 | m_errorMonitor->SetDesiredFailureMsg( |
| 8717 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8718 | " does not have copy update src binding of 3."); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8719 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 8720 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 8721 | copy_ds_update.srcSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8722 | copy_ds_update.srcBinding = |
| 8723 | 3; // ERROR : Invalid binding for matching layout |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8724 | copy_ds_update.dstSet = descriptorSet; |
| 8725 | copy_ds_update.dstBinding = 0; |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 8726 | copy_ds_update.descriptorCount = 1; // Copy 1 descriptor |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8727 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 8728 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8729 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8730 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8731 | // 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] | 8732 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 8733 | VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus " |
| 8734 | "update array offset of 0 and update of " |
| 8735 | "5 descriptors oversteps total number " |
| 8736 | "of descriptors in set: 2."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8737 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8738 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 8739 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 8740 | copy_ds_update.srcSet = descriptorSet; |
| 8741 | copy_ds_update.srcBinding = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8742 | copy_ds_update.dstSet = descriptorSet; |
| 8743 | copy_ds_update.dstBinding = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8744 | copy_ds_update.descriptorCount = |
| 8745 | 5; // ERROR copy 5 descriptors (out of bounds for layout) |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8746 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 8747 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8748 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8749 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8750 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 8751 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8752 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 8753 | } |
| 8754 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8755 | TEST_F(VkLayerTest, NumSamplesMismatch) { |
| 8756 | // Create CommandBuffer where MSAA samples doesn't match RenderPass |
| 8757 | // sampleCount |
| 8758 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8759 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 8760 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8761 | "Num samples mismatch! "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8762 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8763 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8764 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8765 | VkDescriptorPoolSize ds_type_count = {}; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8766 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8767 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8768 | |
| 8769 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8770 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8771 | ds_pool_ci.pNext = NULL; |
| 8772 | ds_pool_ci.maxSets = 1; |
| 8773 | ds_pool_ci.poolSizeCount = 1; |
| 8774 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 8775 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8776 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8777 | err = |
| 8778 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8779 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8780 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8781 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 8782 | dsl_binding.binding = 0; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8783 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | 0212448 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 8784 | dsl_binding.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8785 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8786 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8787 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8788 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 8789 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8790 | ds_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 8791 | ds_layout_ci.bindingCount = 1; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 8792 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8793 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8794 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8795 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8796 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8797 | ASSERT_VK_SUCCESS(err); |
| 8798 | |
| 8799 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8800 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8801 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8802 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8803 | alloc_info.descriptorPool = ds_pool; |
| 8804 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8805 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8806 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8807 | ASSERT_VK_SUCCESS(err); |
| 8808 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8809 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8810 | pipe_ms_state_ci.sType = |
| 8811 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 8812 | pipe_ms_state_ci.pNext = NULL; |
| 8813 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT; |
| 8814 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 8815 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 8816 | pipe_ms_state_ci.pSampleMask = NULL; |
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 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8819 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 8820 | pipeline_layout_ci.pNext = NULL; |
| 8821 | pipeline_layout_ci.setLayoutCount = 1; |
| 8822 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8823 | |
| 8824 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8825 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 8826 | &pipeline_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8827 | ASSERT_VK_SUCCESS(err); |
| 8828 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8829 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 8830 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 8831 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 8832 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 8833 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8834 | // but add it to be able to run on more devices |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 8835 | VkPipelineObj pipe(m_device); |
| 8836 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 8837 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 8838 | pipe.AddColorAttachment(); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 8839 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 8840 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8841 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 8842 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8843 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 8844 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8845 | |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 8846 | // Render triangle (the error should trigger on the attempt to draw). |
| 8847 | Draw(3, 1, 0, 0); |
| 8848 | |
| 8849 | // Finalize recording of the command buffer |
| 8850 | EndCommandBuffer(); |
| 8851 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8852 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8853 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8854 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 8855 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8856 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8857 | } |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 8858 | |
Tobin Ehlis | 85aa15a | 2016-06-15 10:52:37 -0600 | [diff] [blame] | 8859 | TEST_F(VkLayerTest, RenderPassIncompatible) { |
| 8860 | TEST_DESCRIPTION("Hit RenderPass incompatible cases. " |
| 8861 | "Initial case is drawing with an active renderpass that's " |
| 8862 | "not compatible with the bound PSO's creation renderpass"); |
| 8863 | VkResult err; |
| 8864 | |
| 8865 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8866 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8867 | |
| 8868 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 8869 | dsl_binding.binding = 0; |
| 8870 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8871 | dsl_binding.descriptorCount = 1; |
| 8872 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8873 | dsl_binding.pImmutableSamplers = NULL; |
| 8874 | |
| 8875 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 8876 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8877 | ds_layout_ci.pNext = NULL; |
| 8878 | ds_layout_ci.bindingCount = 1; |
| 8879 | ds_layout_ci.pBindings = &dsl_binding; |
| 8880 | |
| 8881 | VkDescriptorSetLayout ds_layout; |
| 8882 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8883 | &ds_layout); |
| 8884 | ASSERT_VK_SUCCESS(err); |
| 8885 | |
| 8886 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 8887 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 8888 | pipeline_layout_ci.pNext = NULL; |
| 8889 | pipeline_layout_ci.setLayoutCount = 1; |
| 8890 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 8891 | |
| 8892 | VkPipelineLayout pipeline_layout; |
| 8893 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 8894 | &pipeline_layout); |
| 8895 | ASSERT_VK_SUCCESS(err); |
| 8896 | |
| 8897 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 8898 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 8899 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 8900 | VK_SHADER_STAGE_FRAGMENT_BIT, |
| 8901 | this); // We shouldn't need a fragment shader |
| 8902 | // but add it to be able to run on more devices |
| 8903 | // Create a renderpass that will be incompatible with default renderpass |
| 8904 | VkAttachmentReference attach = {}; |
| 8905 | attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 8906 | VkAttachmentReference color_att = {}; |
| 8907 | color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 8908 | VkSubpassDescription subpass = {}; |
| 8909 | subpass.inputAttachmentCount = 1; |
| 8910 | subpass.pInputAttachments = &attach; |
| 8911 | subpass.colorAttachmentCount = 1; |
| 8912 | subpass.pColorAttachments = &color_att; |
| 8913 | VkRenderPassCreateInfo rpci = {}; |
| 8914 | rpci.subpassCount = 1; |
| 8915 | rpci.pSubpasses = &subpass; |
| 8916 | rpci.attachmentCount = 1; |
| 8917 | VkAttachmentDescription attach_desc = {}; |
| 8918 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
| 8919 | // Format incompatible with PSO RP color attach format RGBA8_UNORM |
| 8920 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 8921 | rpci.pAttachments = &attach_desc; |
| 8922 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 8923 | VkRenderPass rp; |
| 8924 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 8925 | VkPipelineObj pipe(m_device); |
| 8926 | pipe.AddShader(&vs); |
| 8927 | pipe.AddShader(&fs); |
| 8928 | pipe.AddColorAttachment(); |
| 8929 | VkViewport view_port = {}; |
| 8930 | m_viewports.push_back(view_port); |
| 8931 | pipe.SetViewport(m_viewports); |
| 8932 | VkRect2D rect = {}; |
| 8933 | m_scissors.push_back(rect); |
| 8934 | pipe.SetScissor(m_scissors); |
| 8935 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 8936 | |
| 8937 | VkCommandBufferInheritanceInfo cbii = {}; |
| 8938 | cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; |
| 8939 | cbii.renderPass = rp; |
| 8940 | cbii.subpass = 0; |
| 8941 | VkCommandBufferBeginInfo cbbi = {}; |
| 8942 | cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 8943 | cbbi.pInheritanceInfo = &cbii; |
| 8944 | vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi); |
| 8945 | VkRenderPassBeginInfo rpbi = {}; |
| 8946 | rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 8947 | rpbi.framebuffer = m_framebuffer; |
| 8948 | rpbi.renderPass = rp; |
| 8949 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, |
| 8950 | VK_SUBPASS_CONTENTS_INLINE); |
| 8951 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 8952 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 8953 | |
| 8954 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8955 | " is incompatible w/ gfx pipeline "); |
| 8956 | // Render triangle (the error should trigger on the attempt to draw). |
| 8957 | Draw(3, 1, 0, 0); |
| 8958 | |
| 8959 | // Finalize recording of the command buffer |
| 8960 | EndCommandBuffer(); |
| 8961 | |
| 8962 | m_errorMonitor->VerifyFound(); |
| 8963 | |
| 8964 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 8965 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8966 | vkDestroyRenderPass(m_device->device(), rp, NULL); |
| 8967 | } |
| 8968 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 8969 | TEST_F(VkLayerTest, NumBlendAttachMismatch) { |
| 8970 | // Create Pipeline where the number of blend attachments doesn't match the |
| 8971 | // number of color attachments. In this case, we don't add any color |
| 8972 | // blend attachments even though we have a color attachment. |
| 8973 | VkResult err; |
| 8974 | |
| 8975 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 8976 | "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] | 8977 | |
| 8978 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8979 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8980 | VkDescriptorPoolSize ds_type_count = {}; |
| 8981 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8982 | ds_type_count.descriptorCount = 1; |
| 8983 | |
| 8984 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 8985 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8986 | ds_pool_ci.pNext = NULL; |
| 8987 | ds_pool_ci.maxSets = 1; |
| 8988 | ds_pool_ci.poolSizeCount = 1; |
| 8989 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 8990 | |
| 8991 | VkDescriptorPool ds_pool; |
| 8992 | err = |
| 8993 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 8994 | ASSERT_VK_SUCCESS(err); |
| 8995 | |
| 8996 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 8997 | dsl_binding.binding = 0; |
| 8998 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8999 | dsl_binding.descriptorCount = 1; |
| 9000 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9001 | dsl_binding.pImmutableSamplers = NULL; |
| 9002 | |
| 9003 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 9004 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9005 | ds_layout_ci.pNext = NULL; |
| 9006 | ds_layout_ci.bindingCount = 1; |
| 9007 | ds_layout_ci.pBindings = &dsl_binding; |
| 9008 | |
| 9009 | VkDescriptorSetLayout ds_layout; |
| 9010 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9011 | &ds_layout); |
| 9012 | ASSERT_VK_SUCCESS(err); |
| 9013 | |
| 9014 | VkDescriptorSet descriptorSet; |
| 9015 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 9016 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 9017 | alloc_info.descriptorSetCount = 1; |
| 9018 | alloc_info.descriptorPool = ds_pool; |
| 9019 | alloc_info.pSetLayouts = &ds_layout; |
| 9020 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9021 | &descriptorSet); |
| 9022 | ASSERT_VK_SUCCESS(err); |
| 9023 | |
| 9024 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
| 9025 | pipe_ms_state_ci.sType = |
| 9026 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9027 | pipe_ms_state_ci.pNext = NULL; |
| 9028 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; |
| 9029 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9030 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9031 | pipe_ms_state_ci.pSampleMask = NULL; |
| 9032 | |
| 9033 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 9034 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9035 | pipeline_layout_ci.pNext = NULL; |
| 9036 | pipeline_layout_ci.setLayoutCount = 1; |
| 9037 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 9038 | |
| 9039 | VkPipelineLayout pipeline_layout; |
| 9040 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9041 | &pipeline_layout); |
| 9042 | ASSERT_VK_SUCCESS(err); |
| 9043 | |
| 9044 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9045 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9046 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9047 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9048 | this); // We shouldn't need a fragment shader |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9049 | // but add it to be able to run on more devices |
| 9050 | VkPipelineObj pipe(m_device); |
| 9051 | pipe.AddShader(&vs); |
| 9052 | pipe.AddShader(&fs); |
| 9053 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 9054 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 9055 | |
| 9056 | BeginCommandBuffer(); |
| 9057 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9058 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 9059 | |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9060 | // Render triangle (the error should trigger on the attempt to draw). |
| 9061 | Draw(3, 1, 0, 0); |
| 9062 | |
| 9063 | // Finalize recording of the command buffer |
| 9064 | EndCommandBuffer(); |
| 9065 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9066 | m_errorMonitor->VerifyFound(); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9067 | |
| 9068 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9069 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9070 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 9071 | } |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 9072 | |
Mark Mueller | d491441 | 2016-06-13 17:52:06 -0600 | [diff] [blame] | 9073 | TEST_F(VkLayerTest, MissingClearAttachment) { |
| 9074 | TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment " |
| 9075 | "structure passed to vkCmdClearAttachments"); |
| 9076 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9077 | "vkCmdClearAttachments() attachment index 1 not found in attachment " |
| 9078 | "reference array of active subpass 0"); |
| 9079 | |
| 9080 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments); |
| 9081 | m_errorMonitor->VerifyFound(); |
| 9082 | } |
| 9083 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9084 | TEST_F(VkLayerTest, ClearCmdNoDraw) { |
| 9085 | // Create CommandBuffer where we add ClearCmd for FB Color attachment prior |
| 9086 | // to issuing a Draw |
| 9087 | VkResult err; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9088 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9089 | m_errorMonitor->SetDesiredFailureMsg( |
Tony Barbour | 7e56d30 | 2016-03-02 15:12:01 -0700 | [diff] [blame] | 9090 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9091 | "vkCmdClearAttachments() issued on CB object "); |
| 9092 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9093 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9094 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9095 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9096 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9097 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9098 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9099 | |
| 9100 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9101 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9102 | ds_pool_ci.pNext = NULL; |
| 9103 | ds_pool_ci.maxSets = 1; |
| 9104 | ds_pool_ci.poolSizeCount = 1; |
| 9105 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9106 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9107 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9108 | err = |
| 9109 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9110 | ASSERT_VK_SUCCESS(err); |
| 9111 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9112 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9113 | dsl_binding.binding = 0; |
| 9114 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9115 | dsl_binding.descriptorCount = 1; |
| 9116 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9117 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9118 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9119 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9120 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9121 | ds_layout_ci.pNext = NULL; |
| 9122 | ds_layout_ci.bindingCount = 1; |
| 9123 | ds_layout_ci.pBindings = &dsl_binding; |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9124 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9125 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9126 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9127 | &ds_layout); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9128 | ASSERT_VK_SUCCESS(err); |
| 9129 | |
| 9130 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9131 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9132 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9133 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9134 | alloc_info.descriptorPool = ds_pool; |
| 9135 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9136 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9137 | &descriptorSet); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9138 | ASSERT_VK_SUCCESS(err); |
| 9139 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9140 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9141 | pipe_ms_state_ci.sType = |
| 9142 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9143 | pipe_ms_state_ci.pNext = NULL; |
| 9144 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT; |
| 9145 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9146 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9147 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9148 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9149 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9150 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9151 | pipeline_layout_ci.pNext = NULL; |
| 9152 | pipeline_layout_ci.setLayoutCount = 1; |
| 9153 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9154 | |
| 9155 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9156 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9157 | &pipeline_layout); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9158 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9159 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9160 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9161 | VK_SHADER_STAGE_VERTEX_BIT, this); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9162 | // 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] | 9163 | // on more devices |
| 9164 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9165 | VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9166 | |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9167 | VkPipelineObj pipe(m_device); |
| 9168 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 9169 | pipe.AddShader(&fs); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9170 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 9171 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 9172 | |
| 9173 | BeginCommandBuffer(); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9174 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9175 | // Main thing we care about for this test is that the VkImage obj we're |
| 9176 | // clearing matches Color Attachment of FB |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9177 | // Also pass down other dummy params to keep driver and paramchecker happy |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 9178 | VkClearAttachment color_attachment; |
| 9179 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9180 | color_attachment.clearValue.color.float32[0] = 1.0; |
| 9181 | color_attachment.clearValue.color.float32[1] = 1.0; |
| 9182 | color_attachment.clearValue.color.float32[2] = 1.0; |
| 9183 | color_attachment.clearValue.color.float32[3] = 1.0; |
| 9184 | color_attachment.colorAttachment = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9185 | VkClearRect clear_rect = { |
| 9186 | {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}}; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9187 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9188 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 9189 | &color_attachment, 1, &clear_rect); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9190 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9191 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9192 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9193 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9194 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9195 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 9196 | } |
| 9197 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9198 | TEST_F(VkLayerTest, VtxBufferBadIndex) { |
| 9199 | VkResult err; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9200 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9201 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 9202 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | dfcd9b6 | 2015-12-14 15:14:10 -0700 | [diff] [blame] | 9203 | "but no vertex buffers are attached to this Pipeline State Object"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9204 | |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9205 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 9206 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9207 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9208 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 9209 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9210 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9211 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9212 | |
| 9213 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9214 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 9215 | ds_pool_ci.pNext = NULL; |
| 9216 | ds_pool_ci.maxSets = 1; |
| 9217 | ds_pool_ci.poolSizeCount = 1; |
| 9218 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9219 | |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 9220 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9221 | err = |
| 9222 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9223 | ASSERT_VK_SUCCESS(err); |
| 9224 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9225 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9226 | dsl_binding.binding = 0; |
| 9227 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 9228 | dsl_binding.descriptorCount = 1; |
| 9229 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 9230 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9231 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9232 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9233 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 9234 | ds_layout_ci.pNext = NULL; |
| 9235 | ds_layout_ci.bindingCount = 1; |
| 9236 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9237 | |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9238 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9239 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 9240 | &ds_layout); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9241 | ASSERT_VK_SUCCESS(err); |
| 9242 | |
| 9243 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9244 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 9245 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 9246 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 9247 | alloc_info.descriptorPool = ds_pool; |
| 9248 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9249 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 9250 | &descriptorSet); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9251 | ASSERT_VK_SUCCESS(err); |
| 9252 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9253 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9254 | pipe_ms_state_ci.sType = |
| 9255 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 9256 | pipe_ms_state_ci.pNext = NULL; |
| 9257 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; |
| 9258 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 9259 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 9260 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9261 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 9262 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9263 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 9264 | pipeline_layout_ci.pNext = NULL; |
| 9265 | pipeline_layout_ci.setLayoutCount = 1; |
| 9266 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 9267 | VkPipelineLayout pipeline_layout; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9268 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9269 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 9270 | &pipeline_layout); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9271 | ASSERT_VK_SUCCESS(err); |
| 9272 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9273 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 9274 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9275 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 9276 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 9277 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9278 | // but add it to be able to run on more devices |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9279 | VkPipelineObj pipe(m_device); |
| 9280 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 9281 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 9282 | pipe.AddColorAttachment(); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9283 | pipe.SetMSAA(&pipe_ms_state_ci); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 9284 | pipe.SetViewport(m_viewports); |
| 9285 | pipe.SetScissor(m_scissors); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 9286 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 9287 | |
| 9288 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9289 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 9290 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | f7bf450 | 2015-09-09 15:12:35 -0600 | [diff] [blame] | 9291 | // Don't care about actual data, just need to get to draw to flag error |
| 9292 | static const float vbo_data[3] = {1.f, 0.f, 1.f}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9293 | VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), |
| 9294 | (const void *)&vbo_data); |
Tobin Ehlis | f7bf450 | 2015-09-09 15:12:35 -0600 | [diff] [blame] | 9295 | 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] | 9296 | Draw(1, 0, 0, 0); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9297 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9298 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 9299 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9300 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 9301 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 9302 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 9303 | } |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 9304 | // INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here) |
| 9305 | TEST_F(VkLayerTest, InvalidImageLayout) { |
| 9306 | TEST_DESCRIPTION("Hit all possible validation checks associated with the " |
| 9307 | "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having" |
| 9308 | "images in the wrong layout when they're copied or transitioned."); |
| 9309 | // 3 in ValidateCmdBufImageLayouts |
| 9310 | // * -1 Attempt to submit cmd buf w/ deleted image |
| 9311 | // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource |
| 9312 | // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource |
| 9313 | m_errorMonitor->SetDesiredFailureMsg( |
| 9314 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9315 | "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL."); |
| 9316 | |
| 9317 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9318 | // Create src & dst images to use for copy operations |
| 9319 | VkImage src_image; |
| 9320 | VkImage dst_image; |
| 9321 | |
| 9322 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 9323 | const int32_t tex_width = 32; |
| 9324 | const int32_t tex_height = 32; |
| 9325 | |
| 9326 | VkImageCreateInfo image_create_info = {}; |
| 9327 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 9328 | image_create_info.pNext = NULL; |
| 9329 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 9330 | image_create_info.format = tex_format; |
| 9331 | image_create_info.extent.width = tex_width; |
| 9332 | image_create_info.extent.height = tex_height; |
| 9333 | image_create_info.extent.depth = 1; |
| 9334 | image_create_info.mipLevels = 1; |
| 9335 | image_create_info.arrayLayers = 4; |
| 9336 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 9337 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 9338 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 9339 | image_create_info.flags = 0; |
| 9340 | |
| 9341 | VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image); |
| 9342 | ASSERT_VK_SUCCESS(err); |
| 9343 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image); |
| 9344 | ASSERT_VK_SUCCESS(err); |
| 9345 | |
| 9346 | BeginCommandBuffer(); |
| 9347 | VkImageCopy copyRegion; |
| 9348 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9349 | copyRegion.srcSubresource.mipLevel = 0; |
| 9350 | copyRegion.srcSubresource.baseArrayLayer = 0; |
| 9351 | copyRegion.srcSubresource.layerCount = 1; |
| 9352 | copyRegion.srcOffset.x = 0; |
| 9353 | copyRegion.srcOffset.y = 0; |
| 9354 | copyRegion.srcOffset.z = 0; |
| 9355 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9356 | copyRegion.dstSubresource.mipLevel = 0; |
| 9357 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 9358 | copyRegion.dstSubresource.layerCount = 1; |
| 9359 | copyRegion.dstOffset.x = 0; |
| 9360 | copyRegion.dstOffset.y = 0; |
| 9361 | copyRegion.dstOffset.z = 0; |
| 9362 | copyRegion.extent.width = 1; |
| 9363 | copyRegion.extent.height = 1; |
| 9364 | copyRegion.extent.depth = 1; |
| 9365 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9366 | m_errorMonitor->VerifyFound(); |
| 9367 | // Now cause error due to src image layout changing |
| 9368 | m_errorMonitor->SetDesiredFailureMsg( |
| 9369 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9370 | "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL."); |
| 9371 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9372 | m_errorMonitor->VerifyFound(); |
| 9373 | // Final src error is due to bad layout type |
| 9374 | m_errorMonitor->SetDesiredFailureMsg( |
| 9375 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9376 | "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL."); |
| 9377 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9378 | m_errorMonitor->VerifyFound(); |
| 9379 | // Now verify same checks for dst |
| 9380 | m_errorMonitor->SetDesiredFailureMsg( |
| 9381 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9382 | "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL."); |
| 9383 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 9384 | m_errorMonitor->VerifyFound(); |
| 9385 | // Now cause error due to src image layout changing |
| 9386 | m_errorMonitor->SetDesiredFailureMsg( |
| 9387 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9388 | "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL."); |
| 9389 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, ©Region); |
| 9390 | m_errorMonitor->VerifyFound(); |
| 9391 | m_errorMonitor->SetDesiredFailureMsg( |
| 9392 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9393 | "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL."); |
| 9394 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, ©Region); |
| 9395 | m_errorMonitor->VerifyFound(); |
| 9396 | // Now cause error due to bad image layout transition in PipelineBarrier |
| 9397 | VkImageMemoryBarrier image_barrier[1] = {}; |
| 9398 | image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 9399 | image_barrier[0].image = src_image; |
| 9400 | image_barrier[0].subresourceRange.layerCount = 2; |
| 9401 | image_barrier[0].subresourceRange.levelCount = 2; |
| 9402 | image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 9403 | m_errorMonitor->SetDesiredFailureMsg( |
| 9404 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9405 | "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL."); |
| 9406 | vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier); |
| 9407 | m_errorMonitor->VerifyFound(); |
| 9408 | |
| 9409 | // Finally some layout errors at RenderPass create time |
| 9410 | // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing. |
| 9411 | VkAttachmentReference attach = {}; |
| 9412 | // perf warning for GENERAL layout w/ non-DS input attachment |
| 9413 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 9414 | VkSubpassDescription subpass = {}; |
| 9415 | subpass.inputAttachmentCount = 1; |
| 9416 | subpass.pInputAttachments = &attach; |
| 9417 | VkRenderPassCreateInfo rpci = {}; |
| 9418 | rpci.subpassCount = 1; |
| 9419 | rpci.pSubpasses = &subpass; |
| 9420 | rpci.attachmentCount = 1; |
| 9421 | VkAttachmentDescription attach_desc = {}; |
| 9422 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 9423 | rpci.pAttachments = &attach_desc; |
Tobin Ehlis | 1efce02 | 2016-05-11 10:40:34 -0600 | [diff] [blame] | 9424 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 9425 | VkRenderPass rp; |
| 9426 | m_errorMonitor->SetDesiredFailureMsg( |
| 9427 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9428 | "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL."); |
| 9429 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9430 | m_errorMonitor->VerifyFound(); |
| 9431 | // error w/ non-general layout |
| 9432 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 9433 | |
| 9434 | m_errorMonitor->SetDesiredFailureMsg( |
| 9435 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9436 | "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL."); |
| 9437 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9438 | m_errorMonitor->VerifyFound(); |
| 9439 | subpass.inputAttachmentCount = 0; |
| 9440 | subpass.colorAttachmentCount = 1; |
| 9441 | subpass.pColorAttachments = &attach; |
| 9442 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 9443 | // perf warning for GENERAL layout on color attachment |
| 9444 | m_errorMonitor->SetDesiredFailureMsg( |
| 9445 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9446 | "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL."); |
| 9447 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9448 | m_errorMonitor->VerifyFound(); |
| 9449 | // error w/ non-color opt or GENERAL layout for color attachment |
| 9450 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 9451 | m_errorMonitor->SetDesiredFailureMsg( |
| 9452 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9453 | "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL."); |
| 9454 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9455 | m_errorMonitor->VerifyFound(); |
| 9456 | subpass.colorAttachmentCount = 0; |
| 9457 | subpass.pDepthStencilAttachment = &attach; |
| 9458 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 9459 | // perf warning for GENERAL layout on DS attachment |
| 9460 | m_errorMonitor->SetDesiredFailureMsg( |
| 9461 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 9462 | "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL."); |
| 9463 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9464 | m_errorMonitor->VerifyFound(); |
| 9465 | // error w/ non-ds opt or GENERAL layout for color attachment |
| 9466 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 9467 | m_errorMonitor->SetDesiredFailureMsg( |
| 9468 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9469 | "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL."); |
| 9470 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9471 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 1efce02 | 2016-05-11 10:40:34 -0600 | [diff] [blame] | 9472 | // For this error we need a valid renderpass so create default one |
| 9473 | attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 9474 | attach.attachment = 0; |
| 9475 | attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 9476 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
| 9477 | attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE; |
| 9478 | attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 9479 | attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 9480 | // Can't do a CLEAR load on READ_ONLY initialLayout |
| 9481 | attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 9482 | attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 9483 | attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 9484 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9485 | " with invalid first layout " |
| 9486 | "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_" |
| 9487 | "ONLY_OPTIMAL"); |
| 9488 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 9489 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 9490 | |
| 9491 | vkDestroyImage(m_device->device(), src_image, NULL); |
| 9492 | vkDestroyImage(m_device->device(), dst_image, NULL); |
| 9493 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9494 | #endif // DRAW_STATE_TESTS |
| 9495 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 9496 | #if THREADING_TESTS |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9497 | #if GTEST_IS_THREADSAFE |
| 9498 | struct thread_data_struct { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9499 | VkCommandBuffer commandBuffer; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9500 | VkEvent event; |
| 9501 | bool bailout; |
| 9502 | }; |
| 9503 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9504 | extern "C" void *AddToCommandBuffer(void *arg) { |
| 9505 | struct thread_data_struct *data = (struct thread_data_struct *)arg; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9506 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9507 | for (int i = 0; i < 10000; i++) { |
| 9508 | vkCmdSetEvent(data->commandBuffer, data->event, |
| 9509 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9510 | if (data->bailout) { |
| 9511 | break; |
| 9512 | } |
| 9513 | } |
| 9514 | return NULL; |
| 9515 | } |
| 9516 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9517 | TEST_F(VkLayerTest, ThreadCommandBufferCollision) { |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 9518 | test_platform_thread thread; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9519 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9520 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9521 | "THREADING ERROR"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9522 | |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9523 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9524 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 9525 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9526 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9527 | // Calls AllocateCommandBuffers |
| 9528 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
Mark Lobodzinski | 5495d13 | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 9529 | |
| 9530 | // Avoid creating RenderPass |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9531 | commandBuffer.BeginCommandBuffer(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9532 | |
| 9533 | VkEventCreateInfo event_info; |
| 9534 | VkEvent event; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9535 | VkResult err; |
| 9536 | |
| 9537 | memset(&event_info, 0, sizeof(event_info)); |
| 9538 | event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 9539 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9540 | err = vkCreateEvent(device(), &event_info, NULL, &event); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9541 | ASSERT_VK_SUCCESS(err); |
| 9542 | |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9543 | err = vkResetEvent(device(), event); |
| 9544 | ASSERT_VK_SUCCESS(err); |
| 9545 | |
| 9546 | struct thread_data_struct data; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9547 | data.commandBuffer = commandBuffer.GetBufferHandle(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9548 | data.event = event; |
| 9549 | data.bailout = false; |
| 9550 | m_errorMonitor->SetBailout(&data.bailout); |
| 9551 | // Add many entries to command buffer from another thread. |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 9552 | test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9553 | // Add many entries to command buffer from this thread at the same time. |
| 9554 | AddToCommandBuffer(&data); |
Mark Lobodzinski | 5495d13 | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 9555 | |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 9556 | test_platform_thread_join(thread, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9557 | commandBuffer.EndCommandBuffer(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9558 | |
Mike Stroyan | 10b8cb7 | 2016-01-22 15:22:03 -0700 | [diff] [blame] | 9559 | m_errorMonitor->SetBailout(NULL); |
| 9560 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9561 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9562 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9563 | vkDestroyEvent(device(), event, NULL); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 9564 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 9565 | #endif // GTEST_IS_THREADSAFE |
| 9566 | #endif // THREADING_TESTS |
| 9567 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9568 | #if SHADER_CHECKER_TESTS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9569 | TEST_F(VkLayerTest, InvalidSPIRVCodeSize) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9570 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9571 | "Invalid SPIR-V header"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9572 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9573 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9574 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9575 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9576 | VkShaderModule module; |
| 9577 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 9578 | struct icd_spv_header spv; |
| 9579 | |
| 9580 | spv.magic = ICD_SPV_MAGIC; |
| 9581 | spv.version = ICD_SPV_VERSION; |
| 9582 | spv.gen_magic = 0; |
| 9583 | |
| 9584 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 9585 | moduleCreateInfo.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9586 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9587 | moduleCreateInfo.codeSize = 4; |
| 9588 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9589 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9590 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9591 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9592 | } |
| 9593 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9594 | TEST_F(VkLayerTest, InvalidSPIRVMagic) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9595 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9596 | "Invalid SPIR-V magic number"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9597 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9598 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9599 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9600 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9601 | VkShaderModule module; |
| 9602 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 9603 | struct icd_spv_header spv; |
| 9604 | |
| 9605 | spv.magic = ~ICD_SPV_MAGIC; |
| 9606 | spv.version = ICD_SPV_VERSION; |
| 9607 | spv.gen_magic = 0; |
| 9608 | |
| 9609 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 9610 | moduleCreateInfo.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9611 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9612 | moduleCreateInfo.codeSize = sizeof(spv) + 10; |
| 9613 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9614 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9615 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9616 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9617 | } |
| 9618 | |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9619 | #if 0 |
| 9620 | // Not currently covered by SPIRV-Tools validator |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9621 | TEST_F(VkLayerTest, InvalidSPIRVVersion) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9622 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9623 | "Invalid SPIR-V header"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9624 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9625 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9626 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9627 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9628 | VkShaderModule module; |
| 9629 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 9630 | struct icd_spv_header spv; |
| 9631 | |
| 9632 | spv.magic = ICD_SPV_MAGIC; |
| 9633 | spv.version = ~ICD_SPV_VERSION; |
| 9634 | spv.gen_magic = 0; |
| 9635 | |
| 9636 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 9637 | moduleCreateInfo.pNext = NULL; |
| 9638 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9639 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9640 | moduleCreateInfo.codeSize = sizeof(spv) + 10; |
| 9641 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 9642 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9643 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9644 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9645 | } |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 9646 | #endif |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 9647 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9648 | TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 9649 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9650 | "not consumed by fragment shader"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9651 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9652 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 9653 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9654 | |
| 9655 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9656 | "#version 450\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9657 | "\n" |
| 9658 | "layout(location=0) out float x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 9659 | "out gl_PerVertex {\n" |
| 9660 | " vec4 gl_Position;\n" |
| 9661 | "};\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9662 | "void main(){\n" |
| 9663 | " gl_Position = vec4(1);\n" |
| 9664 | " x = 0;\n" |
| 9665 | "}\n"; |
| 9666 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9667 | "#version 450\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9668 | "\n" |
| 9669 | "layout(location=0) out vec4 color;\n" |
| 9670 | "void main(){\n" |
| 9671 | " color = vec4(1);\n" |
| 9672 | "}\n"; |
| 9673 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 9674 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9675 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9676 | |
| 9677 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 9678 | pipe.AddColorAttachment(); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9679 | pipe.AddShader(&vs); |
| 9680 | pipe.AddShader(&fs); |
| 9681 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9682 | VkDescriptorSetObj descriptorSet(m_device); |
| 9683 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9684 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9685 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 9686 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9687 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9688 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9689 | } |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 9690 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9691 | TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9692 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9693 | "not written by vertex shader"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9694 | |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9695 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 9696 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9697 | |
| 9698 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9699 | "#version 450\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9700 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 9701 | "out gl_PerVertex {\n" |
| 9702 | " vec4 gl_Position;\n" |
| 9703 | "};\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9704 | "void main(){\n" |
| 9705 | " gl_Position = vec4(1);\n" |
| 9706 | "}\n"; |
| 9707 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9708 | "#version 450\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9709 | "\n" |
| 9710 | "layout(location=0) in float x;\n" |
| 9711 | "layout(location=0) out vec4 color;\n" |
| 9712 | "void main(){\n" |
| 9713 | " color = vec4(x);\n" |
| 9714 | "}\n"; |
| 9715 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 9716 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9717 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9718 | |
| 9719 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 9720 | pipe.AddColorAttachment(); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9721 | pipe.AddShader(&vs); |
| 9722 | pipe.AddShader(&fs); |
| 9723 | |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9724 | VkDescriptorSetObj descriptorSet(m_device); |
| 9725 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9726 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9727 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 9728 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9729 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9730 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 9731 | } |
| 9732 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9733 | TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) { |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9734 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9735 | "not written by vertex shader"); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9736 | |
| 9737 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9738 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9739 | |
| 9740 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9741 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9742 | "\n" |
| 9743 | "out gl_PerVertex {\n" |
| 9744 | " vec4 gl_Position;\n" |
| 9745 | "};\n" |
| 9746 | "void main(){\n" |
| 9747 | " gl_Position = vec4(1);\n" |
| 9748 | "}\n"; |
| 9749 | char const *fsSource = |
| 9750 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9751 | "\n" |
| 9752 | "in block { layout(location=0) float x; } ins;\n" |
| 9753 | "layout(location=0) out vec4 color;\n" |
| 9754 | "void main(){\n" |
| 9755 | " color = vec4(ins.x);\n" |
| 9756 | "}\n"; |
| 9757 | |
| 9758 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9759 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 9760 | |
| 9761 | VkPipelineObj pipe(m_device); |
| 9762 | pipe.AddColorAttachment(); |
| 9763 | pipe.AddShader(&vs); |
| 9764 | pipe.AddShader(&fs); |
| 9765 | |
| 9766 | VkDescriptorSetObj descriptorSet(m_device); |
| 9767 | descriptorSet.AppendDummy(); |
| 9768 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 9769 | |
| 9770 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 9771 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9772 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9773 | } |
| 9774 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9775 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) { |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 9776 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 9777 | "Type mismatch on location 0.0: 'ptr to " |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9778 | "output arr[2] of float32' vs 'ptr to " |
| 9779 | "input arr[3] of float32'"); |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 9780 | |
| 9781 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9782 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9783 | |
| 9784 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9785 | "#version 450\n" |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 9786 | "\n" |
| 9787 | "layout(location=0) out float x[2];\n" |
| 9788 | "out gl_PerVertex {\n" |
| 9789 | " vec4 gl_Position;\n" |
| 9790 | "};\n" |
| 9791 | "void main(){\n" |
| 9792 | " x[0] = 0; x[1] = 0;\n" |
| 9793 | " gl_Position = vec4(1);\n" |
| 9794 | "}\n"; |
| 9795 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9796 | "#version 450\n" |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 9797 | "\n" |
| 9798 | "layout(location=0) in float x[3];\n" |
| 9799 | "layout(location=0) out vec4 color;\n" |
| 9800 | "void main(){\n" |
| 9801 | " color = vec4(x[0] + x[1] + x[2]);\n" |
| 9802 | "}\n"; |
| 9803 | |
| 9804 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9805 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 9806 | |
| 9807 | VkPipelineObj pipe(m_device); |
| 9808 | pipe.AddColorAttachment(); |
| 9809 | pipe.AddShader(&vs); |
| 9810 | pipe.AddShader(&fs); |
| 9811 | |
| 9812 | VkDescriptorSetObj descriptorSet(m_device); |
| 9813 | descriptorSet.AppendDummy(); |
| 9814 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 9815 | |
| 9816 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 9817 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9818 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 9819 | } |
| 9820 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9821 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9822 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9823 | "Type mismatch on location 0"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9824 | |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9825 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 9826 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9827 | |
| 9828 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9829 | "#version 450\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9830 | "\n" |
| 9831 | "layout(location=0) out int x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 9832 | "out gl_PerVertex {\n" |
| 9833 | " vec4 gl_Position;\n" |
| 9834 | "};\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9835 | "void main(){\n" |
| 9836 | " x = 0;\n" |
| 9837 | " gl_Position = vec4(1);\n" |
| 9838 | "}\n"; |
| 9839 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9840 | "#version 450\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9841 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9842 | "layout(location=0) in float x;\n" /* VS writes int */ |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9843 | "layout(location=0) out vec4 color;\n" |
| 9844 | "void main(){\n" |
| 9845 | " color = vec4(x);\n" |
| 9846 | "}\n"; |
| 9847 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 9848 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9849 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9850 | |
| 9851 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 9852 | pipe.AddColorAttachment(); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9853 | pipe.AddShader(&vs); |
| 9854 | pipe.AddShader(&fs); |
| 9855 | |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9856 | VkDescriptorSetObj descriptorSet(m_device); |
| 9857 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9858 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9859 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 9860 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9861 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9862 | m_errorMonitor->VerifyFound(); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 9863 | } |
| 9864 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9865 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) { |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9866 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9867 | "Type mismatch on location 0"); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9868 | |
| 9869 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9870 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9871 | |
| 9872 | char const *vsSource = |
| 9873 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9874 | "\n" |
| 9875 | "out block { layout(location=0) int x; } outs;\n" |
| 9876 | "out gl_PerVertex {\n" |
| 9877 | " vec4 gl_Position;\n" |
| 9878 | "};\n" |
| 9879 | "void main(){\n" |
| 9880 | " outs.x = 0;\n" |
| 9881 | " gl_Position = vec4(1);\n" |
| 9882 | "}\n"; |
| 9883 | char const *fsSource = |
| 9884 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9885 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9886 | "in block { layout(location=0) float x; } ins;\n" /* VS writes int */ |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9887 | "layout(location=0) out vec4 color;\n" |
| 9888 | "void main(){\n" |
| 9889 | " color = vec4(ins.x);\n" |
| 9890 | "}\n"; |
| 9891 | |
| 9892 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9893 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 9894 | |
| 9895 | VkPipelineObj pipe(m_device); |
| 9896 | pipe.AddColorAttachment(); |
| 9897 | pipe.AddShader(&vs); |
| 9898 | pipe.AddShader(&fs); |
| 9899 | |
| 9900 | VkDescriptorSetObj descriptorSet(m_device); |
| 9901 | descriptorSet.AppendDummy(); |
| 9902 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 9903 | |
| 9904 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 9905 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9906 | m_errorMonitor->VerifyFound(); |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 9907 | } |
| 9908 | |
| 9909 | TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) { |
| 9910 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9911 | "location 0.0 which is not written by vertex shader"); |
| 9912 | |
| 9913 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9914 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9915 | |
| 9916 | char const *vsSource = |
| 9917 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 9918 | "\n" |
| 9919 | "out block { layout(location=1) float x; } outs;\n" |
| 9920 | "out gl_PerVertex {\n" |
| 9921 | " vec4 gl_Position;\n" |
| 9922 | "};\n" |
| 9923 | "void main(){\n" |
| 9924 | " outs.x = 0;\n" |
| 9925 | " gl_Position = vec4(1);\n" |
| 9926 | "}\n"; |
| 9927 | char const *fsSource = |
| 9928 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 9929 | "\n" |
| 9930 | "in block { layout(location=0) float x; } ins;\n" |
| 9931 | "layout(location=0) out vec4 color;\n" |
| 9932 | "void main(){\n" |
| 9933 | " color = vec4(ins.x);\n" |
| 9934 | "}\n"; |
| 9935 | |
| 9936 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9937 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 9938 | |
| 9939 | VkPipelineObj pipe(m_device); |
| 9940 | pipe.AddColorAttachment(); |
| 9941 | pipe.AddShader(&vs); |
| 9942 | pipe.AddShader(&fs); |
| 9943 | |
| 9944 | VkDescriptorSetObj descriptorSet(m_device); |
| 9945 | descriptorSet.AppendDummy(); |
| 9946 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 9947 | |
| 9948 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 9949 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9950 | m_errorMonitor->VerifyFound(); |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 9951 | } |
| 9952 | |
| 9953 | TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) { |
| 9954 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9955 | "location 0.1 which is not written by vertex shader"); |
| 9956 | |
| 9957 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9958 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9959 | |
| 9960 | char const *vsSource = |
| 9961 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 9962 | "\n" |
| 9963 | "out block { layout(location=0, component=0) float x; } outs;\n" |
| 9964 | "out gl_PerVertex {\n" |
| 9965 | " vec4 gl_Position;\n" |
| 9966 | "};\n" |
| 9967 | "void main(){\n" |
| 9968 | " outs.x = 0;\n" |
| 9969 | " gl_Position = vec4(1);\n" |
| 9970 | "}\n"; |
| 9971 | char const *fsSource = |
| 9972 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 9973 | "\n" |
| 9974 | "in block { layout(location=0, component=1) float x; } ins;\n" |
| 9975 | "layout(location=0) out vec4 color;\n" |
| 9976 | "void main(){\n" |
| 9977 | " color = vec4(ins.x);\n" |
| 9978 | "}\n"; |
| 9979 | |
| 9980 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9981 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 9982 | |
| 9983 | VkPipelineObj pipe(m_device); |
| 9984 | pipe.AddColorAttachment(); |
| 9985 | pipe.AddShader(&vs); |
| 9986 | pipe.AddShader(&fs); |
| 9987 | |
| 9988 | VkDescriptorSetObj descriptorSet(m_device); |
| 9989 | descriptorSet.AppendDummy(); |
| 9990 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 9991 | |
| 9992 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 9993 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9994 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9995 | } |
| 9996 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9997 | TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 9998 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9999 | "location 0 not consumed by VS"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10000 | |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10001 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10002 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10003 | |
| 10004 | VkVertexInputBindingDescription input_binding; |
| 10005 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10006 | |
| 10007 | VkVertexInputAttributeDescription input_attrib; |
| 10008 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10009 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10010 | |
| 10011 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10012 | "#version 450\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10013 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10014 | "out gl_PerVertex {\n" |
| 10015 | " vec4 gl_Position;\n" |
| 10016 | "};\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10017 | "void main(){\n" |
| 10018 | " gl_Position = vec4(1);\n" |
| 10019 | "}\n"; |
| 10020 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10021 | "#version 450\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10022 | "\n" |
| 10023 | "layout(location=0) out vec4 color;\n" |
| 10024 | "void main(){\n" |
| 10025 | " color = vec4(1);\n" |
| 10026 | "}\n"; |
| 10027 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10028 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10029 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10030 | |
| 10031 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10032 | pipe.AddColorAttachment(); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10033 | pipe.AddShader(&vs); |
| 10034 | pipe.AddShader(&fs); |
| 10035 | |
| 10036 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10037 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10038 | |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10039 | VkDescriptorSetObj descriptorSet(m_device); |
| 10040 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10041 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10042 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10043 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10044 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10045 | m_errorMonitor->VerifyFound(); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 10046 | } |
| 10047 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10048 | TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 10049 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10050 | "location 0 not consumed by VS"); |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10051 | |
| 10052 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10053 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10054 | |
| 10055 | VkVertexInputBindingDescription input_binding; |
| 10056 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10057 | |
| 10058 | VkVertexInputAttributeDescription input_attrib; |
| 10059 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10060 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10061 | |
| 10062 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10063 | "#version 450\n" |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10064 | "\n" |
| 10065 | "layout(location=1) in float x;\n" |
| 10066 | "out gl_PerVertex {\n" |
| 10067 | " vec4 gl_Position;\n" |
| 10068 | "};\n" |
| 10069 | "void main(){\n" |
| 10070 | " gl_Position = vec4(x);\n" |
| 10071 | "}\n"; |
| 10072 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10073 | "#version 450\n" |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10074 | "\n" |
| 10075 | "layout(location=0) out vec4 color;\n" |
| 10076 | "void main(){\n" |
| 10077 | " color = vec4(1);\n" |
| 10078 | "}\n"; |
| 10079 | |
| 10080 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10081 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10082 | |
| 10083 | VkPipelineObj pipe(m_device); |
| 10084 | pipe.AddColorAttachment(); |
| 10085 | pipe.AddShader(&vs); |
| 10086 | pipe.AddShader(&fs); |
| 10087 | |
| 10088 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10089 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10090 | |
| 10091 | VkDescriptorSetObj descriptorSet(m_device); |
| 10092 | descriptorSet.AppendDummy(); |
| 10093 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10094 | |
| 10095 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10096 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10097 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 10098 | } |
| 10099 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10100 | TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) { |
| 10101 | m_errorMonitor->SetDesiredFailureMsg( |
| 10102 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10103 | "VS consumes input at location 0 but not provided"); |
| 10104 | |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10105 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10106 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10107 | |
| 10108 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10109 | "#version 450\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10110 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10111 | "layout(location=0) in vec4 x;\n" /* not provided */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10112 | "out gl_PerVertex {\n" |
| 10113 | " vec4 gl_Position;\n" |
| 10114 | "};\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10115 | "void main(){\n" |
| 10116 | " gl_Position = x;\n" |
| 10117 | "}\n"; |
| 10118 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10119 | "#version 450\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10120 | "\n" |
| 10121 | "layout(location=0) out vec4 color;\n" |
| 10122 | "void main(){\n" |
| 10123 | " color = vec4(1);\n" |
| 10124 | "}\n"; |
| 10125 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10126 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10127 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10128 | |
| 10129 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10130 | pipe.AddColorAttachment(); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10131 | pipe.AddShader(&vs); |
| 10132 | pipe.AddShader(&fs); |
| 10133 | |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10134 | VkDescriptorSetObj descriptorSet(m_device); |
| 10135 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10136 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10137 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10138 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10139 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10140 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 10141 | } |
| 10142 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10143 | TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) { |
| 10144 | m_errorMonitor->SetDesiredFailureMsg( |
| 10145 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10146 | "location 0 does not match VS input type"); |
| 10147 | |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10148 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10149 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10150 | |
| 10151 | VkVertexInputBindingDescription input_binding; |
| 10152 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10153 | |
| 10154 | VkVertexInputAttributeDescription input_attrib; |
| 10155 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10156 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10157 | |
| 10158 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10159 | "#version 450\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10160 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10161 | "layout(location=0) in int x;\n" /* attrib provided float */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10162 | "out gl_PerVertex {\n" |
| 10163 | " vec4 gl_Position;\n" |
| 10164 | "};\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10165 | "void main(){\n" |
| 10166 | " gl_Position = vec4(x);\n" |
| 10167 | "}\n"; |
| 10168 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10169 | "#version 450\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10170 | "\n" |
| 10171 | "layout(location=0) out vec4 color;\n" |
| 10172 | "void main(){\n" |
| 10173 | " color = vec4(1);\n" |
| 10174 | "}\n"; |
| 10175 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10176 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10177 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10178 | |
| 10179 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10180 | pipe.AddColorAttachment(); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10181 | pipe.AddShader(&vs); |
| 10182 | pipe.AddShader(&fs); |
| 10183 | |
| 10184 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10185 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10186 | |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10187 | VkDescriptorSetObj descriptorSet(m_device); |
| 10188 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10189 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10190 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10191 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10192 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10193 | m_errorMonitor->VerifyFound(); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 10194 | } |
| 10195 | |
Chris Forbes | c68b43c | 2016-04-06 11:18:47 +1200 | [diff] [blame] | 10196 | TEST_F(VkLayerTest, CreatePipelineDuplicateStage) { |
| 10197 | m_errorMonitor->SetDesiredFailureMsg( |
| 10198 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10199 | "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT"); |
| 10200 | |
| 10201 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10202 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10203 | |
| 10204 | char const *vsSource = |
| 10205 | "#version 450\n" |
| 10206 | "\n" |
| 10207 | "out gl_PerVertex {\n" |
| 10208 | " vec4 gl_Position;\n" |
| 10209 | "};\n" |
| 10210 | "void main(){\n" |
| 10211 | " gl_Position = vec4(1);\n" |
| 10212 | "}\n"; |
| 10213 | char const *fsSource = |
| 10214 | "#version 450\n" |
| 10215 | "\n" |
| 10216 | "layout(location=0) out vec4 color;\n" |
| 10217 | "void main(){\n" |
| 10218 | " color = vec4(1);\n" |
| 10219 | "}\n"; |
| 10220 | |
| 10221 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10222 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10223 | |
| 10224 | VkPipelineObj pipe(m_device); |
| 10225 | pipe.AddColorAttachment(); |
| 10226 | pipe.AddShader(&vs); |
| 10227 | pipe.AddShader(&vs); |
| 10228 | pipe.AddShader(&fs); |
| 10229 | |
| 10230 | VkDescriptorSetObj descriptorSet(m_device); |
| 10231 | descriptorSet.AppendDummy(); |
| 10232 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10233 | |
| 10234 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10235 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10236 | m_errorMonitor->VerifyFound(); |
Chris Forbes | c68b43c | 2016-04-06 11:18:47 +1200 | [diff] [blame] | 10237 | } |
| 10238 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10239 | TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10240 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10241 | |
| 10242 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10243 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10244 | |
| 10245 | VkVertexInputBindingDescription input_binding; |
| 10246 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10247 | |
| 10248 | VkVertexInputAttributeDescription input_attribs[2]; |
| 10249 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 10250 | |
| 10251 | for (int i = 0; i < 2; i++) { |
| 10252 | input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 10253 | input_attribs[i].location = i; |
| 10254 | } |
| 10255 | |
| 10256 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10257 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10258 | "\n" |
| 10259 | "layout(location=0) in mat2x4 x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10260 | "out gl_PerVertex {\n" |
| 10261 | " vec4 gl_Position;\n" |
| 10262 | "};\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10263 | "void main(){\n" |
| 10264 | " gl_Position = x[0] + x[1];\n" |
| 10265 | "}\n"; |
| 10266 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10267 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10268 | "\n" |
| 10269 | "layout(location=0) out vec4 color;\n" |
| 10270 | "void main(){\n" |
| 10271 | " color = vec4(1);\n" |
| 10272 | "}\n"; |
| 10273 | |
| 10274 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10275 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10276 | |
| 10277 | VkPipelineObj pipe(m_device); |
| 10278 | pipe.AddColorAttachment(); |
| 10279 | pipe.AddShader(&vs); |
| 10280 | pipe.AddShader(&fs); |
| 10281 | |
| 10282 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10283 | pipe.AddVertexInputAttribs(input_attribs, 2); |
| 10284 | |
| 10285 | VkDescriptorSetObj descriptorSet(m_device); |
| 10286 | descriptorSet.AppendDummy(); |
| 10287 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10288 | |
| 10289 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10290 | |
| 10291 | /* expect success */ |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10292 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10293 | } |
| 10294 | |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10295 | TEST_F(VkLayerTest, CreatePipelineAttribArrayType) |
| 10296 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10297 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10298 | |
| 10299 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10300 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10301 | |
| 10302 | VkVertexInputBindingDescription input_binding; |
| 10303 | memset(&input_binding, 0, sizeof(input_binding)); |
| 10304 | |
| 10305 | VkVertexInputAttributeDescription input_attribs[2]; |
| 10306 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 10307 | |
| 10308 | for (int i = 0; i < 2; i++) { |
| 10309 | input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 10310 | input_attribs[i].location = i; |
| 10311 | } |
| 10312 | |
| 10313 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10314 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10315 | "\n" |
| 10316 | "layout(location=0) in vec4 x[2];\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10317 | "out gl_PerVertex {\n" |
| 10318 | " vec4 gl_Position;\n" |
| 10319 | "};\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10320 | "void main(){\n" |
| 10321 | " gl_Position = x[0] + x[1];\n" |
| 10322 | "}\n"; |
| 10323 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10324 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10325 | "\n" |
| 10326 | "layout(location=0) out vec4 color;\n" |
| 10327 | "void main(){\n" |
| 10328 | " color = vec4(1);\n" |
| 10329 | "}\n"; |
| 10330 | |
| 10331 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10332 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10333 | |
| 10334 | VkPipelineObj pipe(m_device); |
| 10335 | pipe.AddColorAttachment(); |
| 10336 | pipe.AddShader(&vs); |
| 10337 | pipe.AddShader(&fs); |
| 10338 | |
| 10339 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 10340 | pipe.AddVertexInputAttribs(input_attribs, 2); |
| 10341 | |
| 10342 | VkDescriptorSetObj descriptorSet(m_device); |
| 10343 | descriptorSet.AppendDummy(); |
| 10344 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10345 | |
| 10346 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10347 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10348 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10349 | } |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 10350 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10351 | TEST_F(VkLayerTest, CreatePipelineSimplePositive) |
| 10352 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10353 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10354 | |
| 10355 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10356 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10357 | |
| 10358 | char const *vsSource = |
| 10359 | "#version 450\n" |
| 10360 | "out gl_PerVertex {\n" |
| 10361 | " vec4 gl_Position;\n" |
| 10362 | "};\n" |
| 10363 | "void main(){\n" |
| 10364 | " gl_Position = vec4(0);\n" |
| 10365 | "}\n"; |
| 10366 | char const *fsSource = |
| 10367 | "#version 450\n" |
| 10368 | "\n" |
| 10369 | "layout(location=0) out vec4 color;\n" |
| 10370 | "void main(){\n" |
| 10371 | " color = vec4(1);\n" |
| 10372 | "}\n"; |
| 10373 | |
| 10374 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10375 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10376 | |
| 10377 | VkPipelineObj pipe(m_device); |
| 10378 | pipe.AddColorAttachment(); |
| 10379 | pipe.AddShader(&vs); |
| 10380 | pipe.AddShader(&fs); |
| 10381 | |
| 10382 | VkDescriptorSetObj descriptorSet(m_device); |
| 10383 | descriptorSet.AppendDummy(); |
| 10384 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10385 | |
| 10386 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10387 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10388 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10389 | } |
| 10390 | |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 10391 | TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch) |
| 10392 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10393 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 10394 | |
| 10395 | // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block |
| 10396 | |
| 10397 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10398 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10399 | |
| 10400 | char const *vsSource = |
| 10401 | "#version 450\n" |
| 10402 | "out gl_PerVertex {\n" |
| 10403 | " vec4 gl_Position;\n" |
| 10404 | "};\n" |
| 10405 | "layout(location=0) out vec3 x;\n" |
| 10406 | "layout(location=1) out ivec3 y;\n" |
| 10407 | "layout(location=2) out vec3 z;\n" |
| 10408 | "void main(){\n" |
| 10409 | " gl_Position = vec4(0);\n" |
| 10410 | " x = vec3(0); y = ivec3(0); z = vec3(0);\n" |
| 10411 | "}\n"; |
| 10412 | char const *fsSource = |
| 10413 | "#version 450\n" |
| 10414 | "\n" |
| 10415 | "layout(location=0) out vec4 color;\n" |
| 10416 | "layout(location=0) in float x;\n" |
| 10417 | "layout(location=1) flat in int y;\n" |
| 10418 | "layout(location=2) in vec2 z;\n" |
| 10419 | "void main(){\n" |
| 10420 | " color = vec4(1 + x + y + z.x);\n" |
| 10421 | "}\n"; |
| 10422 | |
| 10423 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10424 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10425 | |
| 10426 | VkPipelineObj pipe(m_device); |
| 10427 | pipe.AddColorAttachment(); |
| 10428 | pipe.AddShader(&vs); |
| 10429 | pipe.AddShader(&fs); |
| 10430 | |
| 10431 | VkDescriptorSetObj descriptorSet(m_device); |
| 10432 | descriptorSet.AppendDummy(); |
| 10433 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10434 | |
| 10435 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10436 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10437 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 10438 | } |
| 10439 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10440 | TEST_F(VkLayerTest, CreatePipelineTessPerVertex) |
| 10441 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10442 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10443 | |
| 10444 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10445 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10446 | |
Chris Forbes | c1e852d | 2016-04-04 19:26:42 +1200 | [diff] [blame] | 10447 | if (!m_device->phy().features().tessellationShader) { |
| 10448 | printf("Device does not support tessellation shaders; skipped.\n"); |
| 10449 | return; |
| 10450 | } |
| 10451 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10452 | char const *vsSource = |
| 10453 | "#version 450\n" |
| 10454 | "void main(){}\n"; |
| 10455 | char const *tcsSource = |
| 10456 | "#version 450\n" |
| 10457 | "layout(location=0) out int x[];\n" |
| 10458 | "layout(vertices=3) out;\n" |
| 10459 | "void main(){\n" |
| 10460 | " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n" |
| 10461 | " gl_TessLevelInner[0] = 1;\n" |
| 10462 | " x[gl_InvocationID] = gl_InvocationID;\n" |
| 10463 | "}\n"; |
| 10464 | char const *tesSource = |
| 10465 | "#version 450\n" |
| 10466 | "layout(triangles, equal_spacing, cw) in;\n" |
| 10467 | "layout(location=0) in int x[];\n" |
| 10468 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 10469 | "void main(){\n" |
| 10470 | " gl_Position.xyz = gl_TessCoord;\n" |
| 10471 | " gl_Position.w = x[0] + x[1] + x[2];\n" |
| 10472 | "}\n"; |
| 10473 | char const *fsSource = |
| 10474 | "#version 450\n" |
| 10475 | "layout(location=0) out vec4 color;\n" |
| 10476 | "void main(){\n" |
| 10477 | " color = vec4(1);\n" |
| 10478 | "}\n"; |
| 10479 | |
| 10480 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10481 | VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this); |
| 10482 | VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this); |
| 10483 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10484 | |
| 10485 | VkPipelineInputAssemblyStateCreateInfo iasci{ |
| 10486 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, |
| 10487 | nullptr, |
| 10488 | 0, |
| 10489 | VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, |
| 10490 | VK_FALSE}; |
| 10491 | |
Chris Forbes | b4cacb6 | 2016-04-04 19:15:00 +1200 | [diff] [blame] | 10492 | VkPipelineTessellationStateCreateInfo tsci{ |
| 10493 | VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, |
| 10494 | nullptr, |
| 10495 | 0, |
| 10496 | 3}; |
| 10497 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10498 | VkPipelineObj pipe(m_device); |
| 10499 | pipe.SetInputAssembly(&iasci); |
Chris Forbes | b4cacb6 | 2016-04-04 19:15:00 +1200 | [diff] [blame] | 10500 | pipe.SetTessellation(&tsci); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10501 | pipe.AddColorAttachment(); |
| 10502 | pipe.AddShader(&vs); |
| 10503 | pipe.AddShader(&tcs); |
| 10504 | pipe.AddShader(&tes); |
| 10505 | pipe.AddShader(&fs); |
| 10506 | |
| 10507 | VkDescriptorSetObj descriptorSet(m_device); |
| 10508 | descriptorSet.AppendDummy(); |
| 10509 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10510 | |
| 10511 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10512 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10513 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 10514 | } |
| 10515 | |
Chris Forbes | a0ab815 | 2016-04-20 13:34:27 +1200 | [diff] [blame] | 10516 | TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive) |
| 10517 | { |
| 10518 | m_errorMonitor->ExpectSuccess(); |
| 10519 | |
| 10520 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10521 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10522 | |
| 10523 | if (!m_device->phy().features().geometryShader) { |
| 10524 | printf("Device does not support geometry shaders; skipped.\n"); |
| 10525 | return; |
| 10526 | } |
| 10527 | |
| 10528 | char const *vsSource = |
| 10529 | "#version 450\n" |
| 10530 | "layout(location=0) out VertexData { vec4 x; } vs_out;\n" |
| 10531 | "void main(){\n" |
| 10532 | " vs_out.x = vec4(1);\n" |
| 10533 | "}\n"; |
| 10534 | char const *gsSource = |
| 10535 | "#version 450\n" |
| 10536 | "layout(triangles) in;\n" |
| 10537 | "layout(triangle_strip, max_vertices=3) out;\n" |
| 10538 | "layout(location=0) in VertexData { vec4 x; } gs_in[];\n" |
| 10539 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 10540 | "void main() {\n" |
| 10541 | " gl_Position = gs_in[0].x;\n" |
| 10542 | " EmitVertex();\n" |
| 10543 | "}\n"; |
| 10544 | char const *fsSource = |
| 10545 | "#version 450\n" |
| 10546 | "layout(location=0) out vec4 color;\n" |
| 10547 | "void main(){\n" |
| 10548 | " color = vec4(1);\n" |
| 10549 | "}\n"; |
| 10550 | |
| 10551 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10552 | VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this); |
| 10553 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10554 | |
| 10555 | VkPipelineObj pipe(m_device); |
| 10556 | pipe.AddColorAttachment(); |
| 10557 | pipe.AddShader(&vs); |
| 10558 | pipe.AddShader(&gs); |
| 10559 | pipe.AddShader(&fs); |
| 10560 | |
| 10561 | VkDescriptorSetObj descriptorSet(m_device); |
| 10562 | descriptorSet.AppendDummy(); |
| 10563 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10564 | |
| 10565 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10566 | |
| 10567 | m_errorMonitor->VerifyNotFound(); |
| 10568 | } |
| 10569 | |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 10570 | TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) |
| 10571 | { |
| 10572 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10573 | "is per-vertex in tessellation control shader stage " |
| 10574 | "but per-patch in tessellation evaluation shader stage"); |
| 10575 | |
| 10576 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10577 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10578 | |
Chris Forbes | c1e852d | 2016-04-04 19:26:42 +1200 | [diff] [blame] | 10579 | if (!m_device->phy().features().tessellationShader) { |
| 10580 | printf("Device does not support tessellation shaders; skipped.\n"); |
| 10581 | return; |
| 10582 | } |
| 10583 | |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 10584 | char const *vsSource = |
| 10585 | "#version 450\n" |
| 10586 | "void main(){}\n"; |
| 10587 | char const *tcsSource = |
| 10588 | "#version 450\n" |
| 10589 | "layout(location=0) out int x[];\n" |
| 10590 | "layout(vertices=3) out;\n" |
| 10591 | "void main(){\n" |
| 10592 | " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n" |
| 10593 | " gl_TessLevelInner[0] = 1;\n" |
| 10594 | " x[gl_InvocationID] = gl_InvocationID;\n" |
| 10595 | "}\n"; |
| 10596 | char const *tesSource = |
| 10597 | "#version 450\n" |
| 10598 | "layout(triangles, equal_spacing, cw) in;\n" |
| 10599 | "layout(location=0) patch in int x;\n" |
| 10600 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 10601 | "void main(){\n" |
| 10602 | " gl_Position.xyz = gl_TessCoord;\n" |
| 10603 | " gl_Position.w = x;\n" |
| 10604 | "}\n"; |
| 10605 | char const *fsSource = |
| 10606 | "#version 450\n" |
| 10607 | "layout(location=0) out vec4 color;\n" |
| 10608 | "void main(){\n" |
| 10609 | " color = vec4(1);\n" |
| 10610 | "}\n"; |
| 10611 | |
| 10612 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10613 | VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this); |
| 10614 | VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this); |
| 10615 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10616 | |
| 10617 | VkPipelineInputAssemblyStateCreateInfo iasci{ |
| 10618 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, |
| 10619 | nullptr, |
| 10620 | 0, |
| 10621 | VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, |
| 10622 | VK_FALSE}; |
| 10623 | |
| 10624 | VkPipelineTessellationStateCreateInfo tsci{ |
| 10625 | VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, |
| 10626 | nullptr, |
| 10627 | 0, |
| 10628 | 3}; |
| 10629 | |
| 10630 | VkPipelineObj pipe(m_device); |
| 10631 | pipe.SetInputAssembly(&iasci); |
| 10632 | pipe.SetTessellation(&tsci); |
| 10633 | pipe.AddColorAttachment(); |
| 10634 | pipe.AddShader(&vs); |
| 10635 | pipe.AddShader(&tcs); |
| 10636 | pipe.AddShader(&tes); |
| 10637 | pipe.AddShader(&fs); |
| 10638 | |
| 10639 | VkDescriptorSetObj descriptorSet(m_device); |
| 10640 | descriptorSet.AppendDummy(); |
| 10641 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10642 | |
| 10643 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10644 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10645 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 10646 | } |
| 10647 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10648 | TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) { |
| 10649 | m_errorMonitor->SetDesiredFailureMsg( |
| 10650 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10651 | "Duplicate vertex input binding descriptions for binding 0"); |
| 10652 | |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10653 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 10654 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10655 | |
| 10656 | /* Two binding descriptions for binding 0 */ |
| 10657 | VkVertexInputBindingDescription input_bindings[2]; |
| 10658 | memset(input_bindings, 0, sizeof(input_bindings)); |
| 10659 | |
| 10660 | VkVertexInputAttributeDescription input_attrib; |
| 10661 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 10662 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 10663 | |
| 10664 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10665 | "#version 450\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10666 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10667 | "layout(location=0) in float x;\n" /* attrib provided float */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10668 | "out gl_PerVertex {\n" |
| 10669 | " vec4 gl_Position;\n" |
| 10670 | "};\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10671 | "void main(){\n" |
| 10672 | " gl_Position = vec4(x);\n" |
| 10673 | "}\n"; |
| 10674 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10675 | "#version 450\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10676 | "\n" |
| 10677 | "layout(location=0) out vec4 color;\n" |
| 10678 | "void main(){\n" |
| 10679 | " color = vec4(1);\n" |
| 10680 | "}\n"; |
| 10681 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10682 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10683 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10684 | |
| 10685 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10686 | pipe.AddColorAttachment(); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10687 | pipe.AddShader(&vs); |
| 10688 | pipe.AddShader(&fs); |
| 10689 | |
| 10690 | pipe.AddVertexInputBindings(input_bindings, 2); |
| 10691 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 10692 | |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10693 | VkDescriptorSetObj descriptorSet(m_device); |
| 10694 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10695 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10696 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10697 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10698 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10699 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 10700 | } |
Chris Forbes | 8f68b56 | 2015-05-25 11:13:32 +1200 | [diff] [blame] | 10701 | |
Chris Forbes | 35efec7 | 2016-04-21 14:32:08 +1200 | [diff] [blame] | 10702 | TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) { |
| 10703 | m_errorMonitor->ExpectSuccess(); |
| 10704 | |
| 10705 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10706 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10707 | |
| 10708 | if (!m_device->phy().features().tessellationShader) { |
| 10709 | printf("Device does not support 64bit vertex attributes; skipped.\n"); |
| 10710 | return; |
| 10711 | } |
| 10712 | |
| 10713 | VkVertexInputBindingDescription input_bindings[1]; |
| 10714 | memset(input_bindings, 0, sizeof(input_bindings)); |
| 10715 | |
| 10716 | VkVertexInputAttributeDescription input_attribs[4]; |
| 10717 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 10718 | input_attribs[0].location = 0; |
| 10719 | input_attribs[0].offset = 0; |
| 10720 | input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 10721 | input_attribs[1].location = 2; |
| 10722 | input_attribs[1].offset = 32; |
| 10723 | input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 10724 | input_attribs[2].location = 4; |
| 10725 | input_attribs[2].offset = 64; |
| 10726 | input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 10727 | input_attribs[3].location = 6; |
| 10728 | input_attribs[3].offset = 96; |
| 10729 | input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 10730 | |
| 10731 | char const *vsSource = |
| 10732 | "#version 450\n" |
| 10733 | "\n" |
| 10734 | "layout(location=0) in dmat4 x;\n" |
| 10735 | "out gl_PerVertex {\n" |
| 10736 | " vec4 gl_Position;\n" |
| 10737 | "};\n" |
| 10738 | "void main(){\n" |
| 10739 | " gl_Position = vec4(x[0][0]);\n" |
| 10740 | "}\n"; |
| 10741 | char const *fsSource = |
| 10742 | "#version 450\n" |
| 10743 | "\n" |
| 10744 | "layout(location=0) out vec4 color;\n" |
| 10745 | "void main(){\n" |
| 10746 | " color = vec4(1);\n" |
| 10747 | "}\n"; |
| 10748 | |
| 10749 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10750 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10751 | |
| 10752 | VkPipelineObj pipe(m_device); |
| 10753 | pipe.AddColorAttachment(); |
| 10754 | pipe.AddShader(&vs); |
| 10755 | pipe.AddShader(&fs); |
| 10756 | |
| 10757 | pipe.AddVertexInputBindings(input_bindings, 1); |
| 10758 | pipe.AddVertexInputAttribs(input_attribs, 4); |
| 10759 | |
| 10760 | VkDescriptorSetObj descriptorSet(m_device); |
| 10761 | descriptorSet.AppendDummy(); |
| 10762 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10763 | |
| 10764 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10765 | |
| 10766 | m_errorMonitor->VerifyNotFound(); |
| 10767 | } |
| 10768 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10769 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10770 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10771 | "Attachment 0 not written by FS"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10772 | |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10773 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10774 | |
| 10775 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10776 | "#version 450\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10777 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10778 | "out gl_PerVertex {\n" |
| 10779 | " vec4 gl_Position;\n" |
| 10780 | "};\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10781 | "void main(){\n" |
| 10782 | " gl_Position = vec4(1);\n" |
| 10783 | "}\n"; |
| 10784 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10785 | "#version 450\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10786 | "\n" |
| 10787 | "void main(){\n" |
| 10788 | "}\n"; |
| 10789 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10790 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10791 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10792 | |
| 10793 | VkPipelineObj pipe(m_device); |
| 10794 | pipe.AddShader(&vs); |
| 10795 | pipe.AddShader(&fs); |
| 10796 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10797 | /* set up CB 0, not written */ |
| 10798 | pipe.AddColorAttachment(); |
| 10799 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10800 | |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10801 | VkDescriptorSetObj descriptorSet(m_device); |
| 10802 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10803 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10804 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10805 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10806 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10807 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 10808 | } |
| 10809 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10810 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10811 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 10812 | VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10813 | "FS writes to output location 1 with no matching attachment"); |
| 10814 | |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10815 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10816 | |
| 10817 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10818 | "#version 450\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10819 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10820 | "out gl_PerVertex {\n" |
| 10821 | " vec4 gl_Position;\n" |
| 10822 | "};\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10823 | "void main(){\n" |
| 10824 | " gl_Position = vec4(1);\n" |
| 10825 | "}\n"; |
| 10826 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10827 | "#version 450\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10828 | "\n" |
| 10829 | "layout(location=0) out vec4 x;\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10830 | "layout(location=1) out vec4 y;\n" /* no matching attachment for this */ |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10831 | "void main(){\n" |
| 10832 | " x = vec4(1);\n" |
| 10833 | " y = vec4(1);\n" |
| 10834 | "}\n"; |
| 10835 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10836 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10837 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10838 | |
| 10839 | VkPipelineObj pipe(m_device); |
| 10840 | pipe.AddShader(&vs); |
| 10841 | pipe.AddShader(&fs); |
| 10842 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10843 | /* set up CB 0, not written */ |
| 10844 | pipe.AddColorAttachment(); |
| 10845 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10846 | /* FS writes CB 1, but we don't configure it */ |
| 10847 | |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10848 | VkDescriptorSetObj descriptorSet(m_device); |
| 10849 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10850 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10851 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10852 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10853 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10854 | m_errorMonitor->VerifyFound(); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 10855 | } |
| 10856 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10857 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10858 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10859 | "does not match FS output type"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10860 | |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10861 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10862 | |
| 10863 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10864 | "#version 450\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10865 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10866 | "out gl_PerVertex {\n" |
| 10867 | " vec4 gl_Position;\n" |
| 10868 | "};\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10869 | "void main(){\n" |
| 10870 | " gl_Position = vec4(1);\n" |
| 10871 | "}\n"; |
| 10872 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10873 | "#version 450\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10874 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10875 | "layout(location=0) out ivec4 x;\n" /* not UNORM */ |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10876 | "void main(){\n" |
| 10877 | " x = ivec4(1);\n" |
| 10878 | "}\n"; |
| 10879 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10880 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10881 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10882 | |
| 10883 | VkPipelineObj pipe(m_device); |
| 10884 | pipe.AddShader(&vs); |
| 10885 | pipe.AddShader(&fs); |
| 10886 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 10887 | /* set up CB 0; type is UNORM by default */ |
| 10888 | pipe.AddColorAttachment(); |
| 10889 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10890 | |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10891 | VkDescriptorSetObj descriptorSet(m_device); |
| 10892 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10893 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10894 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 10895 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10896 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10897 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10898 | } |
Chris Forbes | 7b1b893 | 2015-06-05 14:43:36 +1200 | [diff] [blame] | 10899 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10900 | TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10901 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10902 | "not declared in pipeline layout"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10903 | |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 10904 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 10905 | |
| 10906 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10907 | "#version 450\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 10908 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 10909 | "out gl_PerVertex {\n" |
| 10910 | " vec4 gl_Position;\n" |
| 10911 | "};\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 10912 | "void main(){\n" |
| 10913 | " gl_Position = vec4(1);\n" |
| 10914 | "}\n"; |
| 10915 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 10916 | "#version 450\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 10917 | "\n" |
| 10918 | "layout(location=0) out vec4 x;\n" |
| 10919 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 10920 | "void main(){\n" |
| 10921 | " x = vec4(bar.y);\n" |
| 10922 | "}\n"; |
| 10923 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 10924 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10925 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 10926 | |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 10927 | VkPipelineObj pipe(m_device); |
| 10928 | pipe.AddShader(&vs); |
| 10929 | pipe.AddShader(&fs); |
| 10930 | |
| 10931 | /* set up CB 0; type is UNORM by default */ |
| 10932 | pipe.AddColorAttachment(); |
| 10933 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10934 | |
| 10935 | VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10936 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 10937 | |
| 10938 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10939 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10940 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 10941 | } |
| 10942 | |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 10943 | TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) { |
| 10944 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10945 | "not declared in layout"); |
| 10946 | |
| 10947 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10948 | |
| 10949 | char const *vsSource = |
| 10950 | "#version 450\n" |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 10951 | "\n" |
| 10952 | "layout(push_constant, std430) uniform foo { float x; } consts;\n" |
| 10953 | "out gl_PerVertex {\n" |
| 10954 | " vec4 gl_Position;\n" |
| 10955 | "};\n" |
| 10956 | "void main(){\n" |
| 10957 | " gl_Position = vec4(consts.x);\n" |
| 10958 | "}\n"; |
| 10959 | char const *fsSource = |
| 10960 | "#version 450\n" |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 10961 | "\n" |
| 10962 | "layout(location=0) out vec4 x;\n" |
| 10963 | "void main(){\n" |
| 10964 | " x = vec4(1);\n" |
| 10965 | "}\n"; |
| 10966 | |
| 10967 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10968 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10969 | |
| 10970 | VkPipelineObj pipe(m_device); |
| 10971 | pipe.AddShader(&vs); |
| 10972 | pipe.AddShader(&fs); |
| 10973 | |
| 10974 | /* set up CB 0; type is UNORM by default */ |
| 10975 | pipe.AddColorAttachment(); |
| 10976 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10977 | |
| 10978 | VkDescriptorSetObj descriptorSet(m_device); |
| 10979 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10980 | |
| 10981 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10982 | |
| 10983 | /* should have generated an error -- no push constant ranges provided! */ |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10984 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 10985 | } |
| 10986 | |
Chris Forbes | 10eb9ae | 2016-05-31 16:09:42 +1200 | [diff] [blame] | 10987 | TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) { |
| 10988 | m_errorMonitor->SetDesiredFailureMsg( |
| 10989 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10990 | "Shader uses descriptor slot 0.0"); |
| 10991 | |
| 10992 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10993 | |
| 10994 | char const *csSource = |
| 10995 | "#version 450\n" |
| 10996 | "\n" |
| 10997 | "layout(local_size_x=1) in;\n" |
| 10998 | "layout(set=0, binding=0) buffer block { vec4 x; };\n" |
| 10999 | "void main(){\n" |
| 11000 | " x = vec4(1);\n" |
| 11001 | "}\n"; |
| 11002 | |
| 11003 | VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this); |
| 11004 | |
| 11005 | VkDescriptorSetObj descriptorSet(m_device); |
| 11006 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11007 | |
| 11008 | VkComputePipelineCreateInfo cpci = { |
| 11009 | VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, |
| 11010 | nullptr, 0, { |
| 11011 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 11012 | nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, |
| 11013 | cs.handle(), "main", nullptr |
| 11014 | }, |
| 11015 | descriptorSet.GetPipelineLayout(), |
| 11016 | VK_NULL_HANDLE, -1 |
| 11017 | }; |
| 11018 | |
| 11019 | VkPipeline pipe; |
| 11020 | VkResult err = vkCreateComputePipelines( |
| 11021 | m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe); |
| 11022 | |
| 11023 | m_errorMonitor->VerifyFound(); |
| 11024 | |
| 11025 | if (err == VK_SUCCESS) { |
| 11026 | vkDestroyPipeline(m_device->device(), pipe, nullptr); |
| 11027 | } |
| 11028 | } |
| 11029 | |
| 11030 | TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) { |
| 11031 | m_errorMonitor->ExpectSuccess(); |
| 11032 | |
| 11033 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11034 | |
| 11035 | char const *csSource = |
| 11036 | "#version 450\n" |
| 11037 | "\n" |
| 11038 | "layout(local_size_x=1) in;\n" |
| 11039 | "layout(set=0, binding=0) buffer block { vec4 x; };\n" |
| 11040 | "void main(){\n" |
| 11041 | " // x is not used.\n" |
| 11042 | "}\n"; |
| 11043 | |
| 11044 | VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this); |
| 11045 | |
| 11046 | VkDescriptorSetObj descriptorSet(m_device); |
| 11047 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 11048 | |
| 11049 | VkComputePipelineCreateInfo cpci = { |
| 11050 | VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, |
| 11051 | nullptr, 0, { |
| 11052 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 11053 | nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, |
| 11054 | cs.handle(), "main", nullptr |
| 11055 | }, |
| 11056 | descriptorSet.GetPipelineLayout(), |
| 11057 | VK_NULL_HANDLE, -1 |
| 11058 | }; |
| 11059 | |
| 11060 | VkPipeline pipe; |
| 11061 | VkResult err = vkCreateComputePipelines( |
| 11062 | m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe); |
| 11063 | |
| 11064 | m_errorMonitor->VerifyNotFound(); |
| 11065 | |
| 11066 | if (err == VK_SUCCESS) { |
| 11067 | vkDestroyPipeline(m_device->device(), pipe, nullptr); |
| 11068 | } |
| 11069 | } |
| 11070 | |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 11071 | #endif // SHADER_CHECKER_TESTS |
| 11072 | |
| 11073 | #if DEVICE_LIMITS_TESTS |
Mark Young | c48c4c1 | 2016-04-11 14:26:49 -0600 | [diff] [blame] | 11074 | TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11075 | m_errorMonitor->SetDesiredFailureMsg( |
| 11076 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11077 | "CreateImage extents exceed allowable limits for format"); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11078 | |
| 11079 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11080 | |
| 11081 | // Create an image |
| 11082 | VkImage image; |
| 11083 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11084 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11085 | const int32_t tex_width = 32; |
| 11086 | const int32_t tex_height = 32; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11087 | |
| 11088 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11089 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11090 | image_create_info.pNext = NULL; |
| 11091 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11092 | image_create_info.format = tex_format; |
| 11093 | image_create_info.extent.width = tex_width; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11094 | image_create_info.extent.height = tex_height; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11095 | image_create_info.extent.depth = 1; |
| 11096 | image_create_info.mipLevels = 1; |
| 11097 | image_create_info.arrayLayers = 1; |
| 11098 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11099 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11100 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 11101 | image_create_info.flags = 0; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11102 | |
| 11103 | // Introduce error by sending down a bogus width extent |
| 11104 | image_create_info.extent.width = 65536; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11105 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11106 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11107 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 11108 | } |
| 11109 | |
Mark Young | c48c4c1 | 2016-04-11 14:26:49 -0600 | [diff] [blame] | 11110 | TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) { |
| 11111 | m_errorMonitor->SetDesiredFailureMsg( |
| 11112 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11113 | "CreateImage extents is 0 for at least one required dimension"); |
| 11114 | |
| 11115 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11116 | |
| 11117 | // Create an image |
| 11118 | VkImage image; |
| 11119 | |
| 11120 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11121 | const int32_t tex_width = 32; |
| 11122 | const int32_t tex_height = 32; |
| 11123 | |
| 11124 | VkImageCreateInfo image_create_info = {}; |
| 11125 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11126 | image_create_info.pNext = NULL; |
| 11127 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11128 | image_create_info.format = tex_format; |
| 11129 | image_create_info.extent.width = tex_width; |
| 11130 | image_create_info.extent.height = tex_height; |
| 11131 | image_create_info.extent.depth = 1; |
| 11132 | image_create_info.mipLevels = 1; |
| 11133 | image_create_info.arrayLayers = 1; |
| 11134 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11135 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11136 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 11137 | image_create_info.flags = 0; |
| 11138 | |
| 11139 | // Introduce error by sending down a bogus width extent |
| 11140 | image_create_info.extent.width = 0; |
| 11141 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 11142 | |
| 11143 | m_errorMonitor->VerifyFound(); |
| 11144 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 11145 | #endif // DEVICE_LIMITS_TESTS |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 11146 | |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11147 | #if IMAGE_TESTS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11148 | TEST_F(VkLayerTest, InvalidImageView) { |
| 11149 | VkResult err; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11150 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11151 | m_errorMonitor->SetDesiredFailureMsg( |
| 11152 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11153 | "vkCreateImageView called with baseMipLevel 10 "); |
| 11154 | |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11155 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11156 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11157 | // Create an image and try to create a view with bad baseMipLevel |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11158 | VkImage image; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11159 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11160 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11161 | const int32_t tex_width = 32; |
| 11162 | const int32_t tex_height = 32; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11163 | |
| 11164 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11165 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11166 | image_create_info.pNext = NULL; |
| 11167 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11168 | image_create_info.format = tex_format; |
| 11169 | image_create_info.extent.width = tex_width; |
| 11170 | image_create_info.extent.height = tex_height; |
| 11171 | image_create_info.extent.depth = 1; |
| 11172 | image_create_info.mipLevels = 1; |
| 11173 | image_create_info.arrayLayers = 1; |
| 11174 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11175 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11176 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 11177 | image_create_info.flags = 0; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11178 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11179 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11180 | ASSERT_VK_SUCCESS(err); |
| 11181 | |
| 11182 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11183 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11184 | image_view_create_info.image = image; |
| 11185 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 11186 | image_view_create_info.format = tex_format; |
| 11187 | image_view_create_info.subresourceRange.layerCount = 1; |
| 11188 | image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error |
| 11189 | image_view_create_info.subresourceRange.levelCount = 1; |
| 11190 | image_view_create_info.subresourceRange.aspectMask = |
| 11191 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11192 | |
| 11193 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11194 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 11195 | &view); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11196 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11197 | m_errorMonitor->VerifyFound(); |
Tony Barbour | df4c004 | 2016-06-01 15:55:43 -0600 | [diff] [blame] | 11198 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11199 | } |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11200 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11201 | TEST_F(VkLayerTest, InvalidImageViewAspect) { |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11202 | TEST_DESCRIPTION( |
| 11203 | "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] | 11204 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11205 | "vkCreateImageView: Color image " |
| 11206 | "formats must have ONLY the " |
| 11207 | "VK_IMAGE_ASPECT_COLOR_BIT set"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11208 | |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11209 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11210 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11211 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11212 | VkImageObj image(m_device); |
| 11213 | image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, |
| 11214 | VK_IMAGE_TILING_LINEAR, 0); |
| 11215 | ASSERT_TRUE(image.initialized()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11216 | |
| 11217 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11218 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11219 | image_view_create_info.image = image.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11220 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 11221 | image_view_create_info.format = tex_format; |
| 11222 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 11223 | image_view_create_info.subresourceRange.levelCount = 1; |
| 11224 | // Cause an error by setting an invalid image aspect |
| 11225 | image_view_create_info.subresourceRange.aspectMask = |
| 11226 | VK_IMAGE_ASPECT_METADATA_BIT; |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11227 | |
| 11228 | VkImageView view; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 11229 | vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11230 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11231 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 11232 | } |
| 11233 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11234 | TEST_F(VkLayerTest, CopyImageLayerCountMismatch) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11235 | VkResult err; |
| 11236 | bool pass; |
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 | m_errorMonitor->SetDesiredFailureMsg( |
| 11239 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11240 | "vkCmdCopyImage: number of layers in source and destination subresources for pRegions"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11241 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11242 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11243 | |
| 11244 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11245 | VkImage srcImage; |
| 11246 | VkImage dstImage; |
| 11247 | VkDeviceMemory srcMem; |
| 11248 | VkDeviceMemory destMem; |
| 11249 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11250 | |
| 11251 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11252 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11253 | image_create_info.pNext = NULL; |
| 11254 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11255 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11256 | image_create_info.extent.width = 32; |
| 11257 | image_create_info.extent.height = 32; |
| 11258 | image_create_info.extent.depth = 1; |
| 11259 | image_create_info.mipLevels = 1; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11260 | image_create_info.arrayLayers = 4; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11261 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11262 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 11263 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11264 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11265 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11266 | err = |
| 11267 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11268 | ASSERT_VK_SUCCESS(err); |
| 11269 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11270 | err = |
| 11271 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11272 | ASSERT_VK_SUCCESS(err); |
| 11273 | |
| 11274 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11275 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11276 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 11277 | memAlloc.pNext = NULL; |
| 11278 | memAlloc.allocationSize = 0; |
| 11279 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11280 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 11281 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11282 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11283 | pass = |
| 11284 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 11285 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11286 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11287 | ASSERT_VK_SUCCESS(err); |
| 11288 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11289 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11290 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11291 | pass = |
| 11292 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11293 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11294 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11295 | ASSERT_VK_SUCCESS(err); |
| 11296 | |
| 11297 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 11298 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11299 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11300 | ASSERT_VK_SUCCESS(err); |
| 11301 | |
| 11302 | BeginCommandBuffer(); |
| 11303 | VkImageCopy copyRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11304 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11305 | copyRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 11306 | copyRegion.srcSubresource.baseArrayLayer = 0; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11307 | copyRegion.srcSubresource.layerCount = 1; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11308 | copyRegion.srcOffset.x = 0; |
| 11309 | copyRegion.srcOffset.y = 0; |
| 11310 | copyRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11311 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11312 | copyRegion.dstSubresource.mipLevel = 0; |
| 11313 | copyRegion.dstSubresource.baseArrayLayer = 0; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11314 | // Introduce failure by forcing the dst layerCount to differ from src |
| 11315 | copyRegion.dstSubresource.layerCount = 3; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11316 | copyRegion.dstOffset.x = 0; |
| 11317 | copyRegion.dstOffset.y = 0; |
| 11318 | copyRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11319 | copyRegion.extent.width = 1; |
| 11320 | copyRegion.extent.height = 1; |
| 11321 | copyRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11322 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 11323 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11324 | EndCommandBuffer(); |
| 11325 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11326 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11327 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11328 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11329 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11330 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 11331 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11332 | } |
| 11333 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11334 | TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) { |
| 11335 | |
| 11336 | TEST_DESCRIPTION("Creating images with unsuported formats "); |
| 11337 | |
| 11338 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11339 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11340 | VkImageObj image(m_device); |
| 11341 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 11342 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 11343 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 11344 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 11345 | ASSERT_TRUE(image.initialized()); |
| 11346 | |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11347 | // Create image with unsupported format - Expect FORMAT_UNSUPPORTED |
| 11348 | VkImageCreateInfo image_create_info; |
| 11349 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11350 | image_create_info.pNext = NULL; |
| 11351 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11352 | image_create_info.format = VK_FORMAT_UNDEFINED; |
| 11353 | image_create_info.extent.width = 32; |
| 11354 | image_create_info.extent.height = 32; |
| 11355 | image_create_info.extent.depth = 1; |
| 11356 | image_create_info.mipLevels = 1; |
| 11357 | image_create_info.arrayLayers = 1; |
| 11358 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11359 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 11360 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11361 | image_create_info.flags = 0; |
| 11362 | |
| 11363 | m_errorMonitor->SetDesiredFailureMsg( |
| 11364 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11365 | "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED"); |
| 11366 | |
| 11367 | VkImage localImage; |
| 11368 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage); |
| 11369 | m_errorMonitor->VerifyFound(); |
| 11370 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11371 | VkFormat unsupported = VK_FORMAT_UNDEFINED; |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11372 | // Look for a format that is COMPLETELY unsupported with this hardware |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11373 | for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) { |
| 11374 | VkFormat format = static_cast<VkFormat>(f); |
| 11375 | VkFormatProperties fProps = m_device->format_properties(format); |
| 11376 | if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && |
| 11377 | fProps.optimalTilingFeatures == 0) { |
| 11378 | unsupported = format; |
| 11379 | break; |
| 11380 | } |
| 11381 | } |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11382 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11383 | if (unsupported != VK_FORMAT_UNDEFINED) { |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11384 | image_create_info.format = unsupported; |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11385 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11386 | "is an unsupported format"); |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11387 | |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 11388 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage); |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 11389 | m_errorMonitor->VerifyFound(); |
| 11390 | } |
| 11391 | } |
| 11392 | |
| 11393 | TEST_F(VkLayerTest, ImageLayerViewTests) { |
| 11394 | VkResult ret; |
| 11395 | TEST_DESCRIPTION("Passing bad parameters to CreateImageView"); |
| 11396 | |
| 11397 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11398 | |
| 11399 | VkImageObj image(m_device); |
| 11400 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 11401 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 11402 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 11403 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 11404 | ASSERT_TRUE(image.initialized()); |
| 11405 | |
| 11406 | VkImageView imgView; |
| 11407 | VkImageViewCreateInfo imgViewInfo = {}; |
| 11408 | imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 11409 | imgViewInfo.image = image.handle(); |
| 11410 | imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 11411 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11412 | imgViewInfo.subresourceRange.layerCount = 1; |
| 11413 | imgViewInfo.subresourceRange.baseMipLevel = 0; |
| 11414 | imgViewInfo.subresourceRange.levelCount = 1; |
| 11415 | imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11416 | |
| 11417 | m_errorMonitor->SetDesiredFailureMsg( |
| 11418 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11419 | "vkCreateImageView called with baseMipLevel"); |
| 11420 | // View can't have baseMipLevel >= image's mipLevels - Expect |
| 11421 | // VIEW_CREATE_ERROR |
| 11422 | imgViewInfo.subresourceRange.baseMipLevel = 1; |
| 11423 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11424 | m_errorMonitor->VerifyFound(); |
| 11425 | imgViewInfo.subresourceRange.baseMipLevel = 0; |
| 11426 | |
| 11427 | m_errorMonitor->SetDesiredFailureMsg( |
| 11428 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11429 | "vkCreateImageView called with baseArrayLayer"); |
| 11430 | // View can't have baseArrayLayer >= image's arraySize - Expect |
| 11431 | // VIEW_CREATE_ERROR |
| 11432 | imgViewInfo.subresourceRange.baseArrayLayer = 1; |
| 11433 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11434 | m_errorMonitor->VerifyFound(); |
| 11435 | imgViewInfo.subresourceRange.baseArrayLayer = 0; |
| 11436 | |
| 11437 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11438 | "vkCreateImageView called with 0 in " |
| 11439 | "pCreateInfo->subresourceRange." |
| 11440 | "levelCount"); |
| 11441 | // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR |
| 11442 | imgViewInfo.subresourceRange.levelCount = 0; |
| 11443 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11444 | m_errorMonitor->VerifyFound(); |
| 11445 | imgViewInfo.subresourceRange.levelCount = 1; |
| 11446 | |
| 11447 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11448 | "vkCreateImageView called with 0 in " |
| 11449 | "pCreateInfo->subresourceRange." |
| 11450 | "layerCount"); |
| 11451 | // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR |
| 11452 | imgViewInfo.subresourceRange.layerCount = 0; |
| 11453 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11454 | m_errorMonitor->VerifyFound(); |
| 11455 | imgViewInfo.subresourceRange.layerCount = 1; |
| 11456 | |
| 11457 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11458 | "but both must be color formats"); |
| 11459 | // Can't use depth format for view into color image - Expect INVALID_FORMAT |
| 11460 | imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 11461 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11462 | m_errorMonitor->VerifyFound(); |
| 11463 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11464 | |
| 11465 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11466 | "Formats MUST be IDENTICAL unless " |
| 11467 | "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT " |
| 11468 | "was set on image creation."); |
| 11469 | // Same compatibility class but no MUTABLE_FORMAT bit - Expect |
| 11470 | // VIEW_CREATE_ERROR |
| 11471 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT; |
| 11472 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11473 | m_errorMonitor->VerifyFound(); |
| 11474 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11475 | |
| 11476 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11477 | "can support ImageViews with " |
| 11478 | "differing formats but they must be " |
| 11479 | "in the same compatibility class."); |
| 11480 | // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect |
| 11481 | // VIEW_CREATE_ERROR |
| 11482 | VkImageCreateInfo mutImgInfo = image.create_info(); |
| 11483 | VkImage mutImage; |
| 11484 | mutImgInfo.format = VK_FORMAT_R8_UINT; |
| 11485 | assert( |
| 11486 | m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & |
| 11487 | VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT); |
| 11488 | mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; |
| 11489 | mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 11490 | ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage); |
| 11491 | ASSERT_VK_SUCCESS(ret); |
| 11492 | imgViewInfo.image = mutImage; |
| 11493 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 11494 | m_errorMonitor->VerifyFound(); |
| 11495 | imgViewInfo.image = image.handle(); |
| 11496 | vkDestroyImage(m_device->handle(), mutImage, NULL); |
| 11497 | } |
| 11498 | |
| 11499 | TEST_F(VkLayerTest, MiscImageLayerTests) { |
| 11500 | |
| 11501 | TEST_DESCRIPTION("Image layer tests that don't belong elsewhare"); |
| 11502 | |
| 11503 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11504 | |
| 11505 | VkImageObj image(m_device); |
| 11506 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 11507 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 11508 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 11509 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 11510 | ASSERT_TRUE(image.initialized()); |
| 11511 | |
| 11512 | m_errorMonitor->SetDesiredFailureMsg( |
| 11513 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11514 | "number of layers in image subresource is zero"); |
| 11515 | vk_testing::Buffer buffer; |
| 11516 | VkMemoryPropertyFlags reqs = 0; |
| 11517 | buffer.init_as_src(*m_device, 128 * 128 * 4, reqs); |
| 11518 | VkBufferImageCopy region = {}; |
| 11519 | region.bufferRowLength = 128; |
| 11520 | region.bufferImageHeight = 128; |
| 11521 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11522 | // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT |
| 11523 | region.imageSubresource.layerCount = 0; |
| 11524 | region.imageExtent.height = 4; |
| 11525 | region.imageExtent.width = 4; |
| 11526 | region.imageExtent.depth = 1; |
| 11527 | m_commandBuffer->BeginCommandBuffer(); |
| 11528 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 11529 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 11530 | 1, ®ion); |
| 11531 | m_errorMonitor->VerifyFound(); |
| 11532 | region.imageSubresource.layerCount = 1; |
| 11533 | |
| 11534 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11535 | "aspectMasks for each region must " |
| 11536 | "specify only COLOR or DEPTH or " |
| 11537 | "STENCIL"); |
| 11538 | // Expect MISMATCHED_IMAGE_ASPECT |
| 11539 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT; |
| 11540 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 11541 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 11542 | 1, ®ion); |
| 11543 | m_errorMonitor->VerifyFound(); |
| 11544 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11545 | |
| 11546 | m_errorMonitor->SetDesiredFailureMsg( |
| 11547 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11548 | "If the format of srcImage is a depth, stencil, depth stencil or " |
| 11549 | "integer-based format then filter must be VK_FILTER_NEAREST"); |
| 11550 | // Expect INVALID_FILTER |
| 11551 | VkImageObj intImage1(m_device); |
| 11552 | intImage1.init(128, 128, VK_FORMAT_R8_UINT, |
| 11553 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, |
| 11554 | 0); |
| 11555 | VkImageObj intImage2(m_device); |
| 11556 | intImage2.init(128, 128, VK_FORMAT_R8_UINT, |
| 11557 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, |
| 11558 | 0); |
| 11559 | VkImageBlit blitRegion = {}; |
| 11560 | blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11561 | blitRegion.srcSubresource.baseArrayLayer = 0; |
| 11562 | blitRegion.srcSubresource.layerCount = 1; |
| 11563 | blitRegion.srcSubresource.mipLevel = 0; |
| 11564 | blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11565 | blitRegion.dstSubresource.baseArrayLayer = 0; |
| 11566 | blitRegion.dstSubresource.layerCount = 1; |
| 11567 | blitRegion.dstSubresource.mipLevel = 0; |
| 11568 | |
| 11569 | vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), |
| 11570 | intImage1.layout(), intImage2.handle(), intImage2.layout(), |
| 11571 | 16, &blitRegion, VK_FILTER_LINEAR); |
| 11572 | m_errorMonitor->VerifyFound(); |
| 11573 | |
| 11574 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11575 | "called with 0 in ppMemoryBarriers"); |
| 11576 | VkImageMemoryBarrier img_barrier; |
| 11577 | img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 11578 | img_barrier.pNext = NULL; |
| 11579 | img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 11580 | img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 11581 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 11582 | img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 11583 | img_barrier.image = image.handle(); |
| 11584 | img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 11585 | img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 11586 | img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11587 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 11588 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 11589 | // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE |
| 11590 | img_barrier.subresourceRange.layerCount = 0; |
| 11591 | img_barrier.subresourceRange.levelCount = 1; |
| 11592 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 11593 | VK_PIPELINE_STAGE_HOST_BIT, |
| 11594 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 11595 | nullptr, 1, &img_barrier); |
| 11596 | m_errorMonitor->VerifyFound(); |
| 11597 | img_barrier.subresourceRange.layerCount = 1; |
| 11598 | } |
| 11599 | |
| 11600 | TEST_F(VkLayerTest, ImageFormatLimits) { |
| 11601 | |
| 11602 | TEST_DESCRIPTION("Exceed the limits of image format "); |
| 11603 | |
| 11604 | m_errorMonitor->SetDesiredFailureMsg( |
| 11605 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11606 | "CreateImage extents exceed allowable limits for format"); |
| 11607 | VkImageCreateInfo image_create_info = {}; |
| 11608 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11609 | image_create_info.pNext = NULL; |
| 11610 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11611 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11612 | image_create_info.extent.width = 32; |
| 11613 | image_create_info.extent.height = 32; |
| 11614 | image_create_info.extent.depth = 1; |
| 11615 | image_create_info.mipLevels = 1; |
| 11616 | image_create_info.arrayLayers = 1; |
| 11617 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11618 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11619 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11620 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 11621 | image_create_info.flags = 0; |
| 11622 | |
| 11623 | VkImage nullImg; |
| 11624 | VkImageFormatProperties imgFmtProps; |
| 11625 | vkGetPhysicalDeviceImageFormatProperties( |
| 11626 | gpu(), image_create_info.format, image_create_info.imageType, |
| 11627 | image_create_info.tiling, image_create_info.usage, |
| 11628 | image_create_info.flags, &imgFmtProps); |
| 11629 | image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1; |
| 11630 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 11631 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11632 | m_errorMonitor->VerifyFound(); |
| 11633 | image_create_info.extent.depth = 1; |
| 11634 | |
| 11635 | m_errorMonitor->SetDesiredFailureMsg( |
| 11636 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11637 | "exceeds allowable maximum supported by format of"); |
| 11638 | image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1; |
| 11639 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 11640 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11641 | m_errorMonitor->VerifyFound(); |
| 11642 | image_create_info.mipLevels = 1; |
| 11643 | |
| 11644 | m_errorMonitor->SetDesiredFailureMsg( |
| 11645 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11646 | "exceeds allowable maximum supported by format of"); |
| 11647 | image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1; |
| 11648 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 11649 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11650 | m_errorMonitor->VerifyFound(); |
| 11651 | image_create_info.arrayLayers = 1; |
| 11652 | |
| 11653 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11654 | "is not supported by format"); |
| 11655 | int samples = imgFmtProps.sampleCounts >> 1; |
| 11656 | image_create_info.samples = (VkSampleCountFlagBits)samples; |
| 11657 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 11658 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11659 | m_errorMonitor->VerifyFound(); |
| 11660 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11661 | |
| 11662 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11663 | "pCreateInfo->initialLayout, must be " |
| 11664 | "VK_IMAGE_LAYOUT_UNDEFINED or " |
| 11665 | "VK_IMAGE_LAYOUT_PREINITIALIZED"); |
| 11666 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 11667 | // Expect INVALID_LAYOUT |
| 11668 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 11669 | m_errorMonitor->VerifyFound(); |
| 11670 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 11671 | } |
| 11672 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11673 | TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 11674 | VkResult err; |
| 11675 | bool pass; |
| 11676 | |
| 11677 | // Create color images with different format sizes and try to copy between them |
| 11678 | m_errorMonitor->SetDesiredFailureMsg( |
| 11679 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11680 | "vkCmdCopyImage called with unmatched source and dest image format sizes"); |
| 11681 | |
| 11682 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11683 | |
| 11684 | // Create two images of different types and try to copy between them |
| 11685 | VkImage srcImage; |
| 11686 | VkImage dstImage; |
| 11687 | VkDeviceMemory srcMem; |
| 11688 | VkDeviceMemory destMem; |
| 11689 | VkMemoryRequirements memReqs; |
| 11690 | |
| 11691 | VkImageCreateInfo image_create_info = {}; |
| 11692 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11693 | image_create_info.pNext = NULL; |
| 11694 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11695 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11696 | image_create_info.extent.width = 32; |
| 11697 | image_create_info.extent.height = 32; |
| 11698 | image_create_info.extent.depth = 1; |
| 11699 | image_create_info.mipLevels = 1; |
| 11700 | image_create_info.arrayLayers = 1; |
| 11701 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11702 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11703 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11704 | image_create_info.flags = 0; |
| 11705 | |
| 11706 | err = |
| 11707 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
| 11708 | ASSERT_VK_SUCCESS(err); |
| 11709 | |
| 11710 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 11711 | // Introduce failure by creating second image with a different-sized format. |
| 11712 | image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16; |
| 11713 | |
| 11714 | err = |
| 11715 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
| 11716 | ASSERT_VK_SUCCESS(err); |
| 11717 | |
| 11718 | // Allocate memory |
| 11719 | VkMemoryAllocateInfo memAlloc = {}; |
| 11720 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 11721 | memAlloc.pNext = NULL; |
| 11722 | memAlloc.allocationSize = 0; |
| 11723 | memAlloc.memoryTypeIndex = 0; |
| 11724 | |
| 11725 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
| 11726 | memAlloc.allocationSize = memReqs.size; |
| 11727 | pass = |
| 11728 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
| 11729 | ASSERT_TRUE(pass); |
| 11730 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
| 11731 | ASSERT_VK_SUCCESS(err); |
| 11732 | |
| 11733 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
| 11734 | memAlloc.allocationSize = memReqs.size; |
| 11735 | pass = |
| 11736 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
| 11737 | ASSERT_TRUE(pass); |
| 11738 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
| 11739 | ASSERT_VK_SUCCESS(err); |
| 11740 | |
| 11741 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 11742 | ASSERT_VK_SUCCESS(err); |
| 11743 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
| 11744 | ASSERT_VK_SUCCESS(err); |
| 11745 | |
| 11746 | BeginCommandBuffer(); |
| 11747 | VkImageCopy copyRegion; |
| 11748 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11749 | copyRegion.srcSubresource.mipLevel = 0; |
| 11750 | copyRegion.srcSubresource.baseArrayLayer = 0; |
| 11751 | copyRegion.srcSubresource.layerCount = 0; |
| 11752 | copyRegion.srcOffset.x = 0; |
| 11753 | copyRegion.srcOffset.y = 0; |
| 11754 | copyRegion.srcOffset.z = 0; |
| 11755 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 11756 | copyRegion.dstSubresource.mipLevel = 0; |
| 11757 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 11758 | copyRegion.dstSubresource.layerCount = 0; |
| 11759 | copyRegion.dstOffset.x = 0; |
| 11760 | copyRegion.dstOffset.y = 0; |
| 11761 | copyRegion.dstOffset.z = 0; |
| 11762 | copyRegion.extent.width = 1; |
| 11763 | copyRegion.extent.height = 1; |
| 11764 | copyRegion.extent.depth = 1; |
| 11765 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 11766 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 11767 | EndCommandBuffer(); |
| 11768 | |
| 11769 | m_errorMonitor->VerifyFound(); |
| 11770 | |
| 11771 | vkDestroyImage(m_device->device(), srcImage, NULL); |
| 11772 | vkDestroyImage(m_device->device(), dstImage, NULL); |
| 11773 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 11774 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11775 | } |
| 11776 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11777 | TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) { |
| 11778 | VkResult err; |
| 11779 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11780 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11781 | // 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] | 11782 | m_errorMonitor->SetDesiredFailureMsg( |
| 11783 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11784 | "vkCmdCopyImage called with unmatched source and dest image depth"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11785 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11786 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11787 | |
| 11788 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11789 | VkImage srcImage; |
| 11790 | VkImage dstImage; |
| 11791 | VkDeviceMemory srcMem; |
| 11792 | VkDeviceMemory destMem; |
| 11793 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11794 | |
| 11795 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11796 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11797 | image_create_info.pNext = NULL; |
| 11798 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11799 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11800 | image_create_info.extent.width = 32; |
| 11801 | image_create_info.extent.height = 32; |
| 11802 | image_create_info.extent.depth = 1; |
| 11803 | image_create_info.mipLevels = 1; |
| 11804 | image_create_info.arrayLayers = 1; |
| 11805 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11806 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11807 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11808 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11809 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11810 | err = |
| 11811 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11812 | ASSERT_VK_SUCCESS(err); |
| 11813 | |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 11814 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 11815 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11816 | // Introduce failure by creating second image with a depth/stencil format |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11817 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 11818 | image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 11819 | image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11820 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11821 | err = |
| 11822 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11823 | ASSERT_VK_SUCCESS(err); |
| 11824 | |
| 11825 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11826 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11827 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 11828 | memAlloc.pNext = NULL; |
| 11829 | memAlloc.allocationSize = 0; |
| 11830 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11831 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 11832 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11833 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11834 | pass = |
| 11835 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 11836 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11837 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11838 | ASSERT_VK_SUCCESS(err); |
| 11839 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11840 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11841 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11842 | pass = |
| 11843 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 11844 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11845 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11846 | ASSERT_VK_SUCCESS(err); |
| 11847 | |
| 11848 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 11849 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11850 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11851 | ASSERT_VK_SUCCESS(err); |
| 11852 | |
| 11853 | BeginCommandBuffer(); |
| 11854 | VkImageCopy copyRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11855 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11856 | copyRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 11857 | copyRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11858 | copyRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11859 | copyRegion.srcOffset.x = 0; |
| 11860 | copyRegion.srcOffset.y = 0; |
| 11861 | copyRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11862 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11863 | copyRegion.dstSubresource.mipLevel = 0; |
| 11864 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 11865 | copyRegion.dstSubresource.layerCount = 0; |
| 11866 | copyRegion.dstOffset.x = 0; |
| 11867 | copyRegion.dstOffset.y = 0; |
| 11868 | copyRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11869 | copyRegion.extent.width = 1; |
| 11870 | copyRegion.extent.height = 1; |
| 11871 | copyRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11872 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 11873 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11874 | EndCommandBuffer(); |
| 11875 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11876 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11877 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11878 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11879 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11880 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 11881 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11882 | } |
| 11883 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11884 | TEST_F(VkLayerTest, ResolveImageLowSampleCount) { |
| 11885 | VkResult err; |
| 11886 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11887 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11888 | m_errorMonitor->SetDesiredFailureMsg( |
| 11889 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11890 | "vkCmdResolveImage called with source sample count less than 2."); |
| 11891 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11892 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11893 | |
| 11894 | // 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] | 11895 | VkImage srcImage; |
| 11896 | VkImage dstImage; |
| 11897 | VkDeviceMemory srcMem; |
| 11898 | VkDeviceMemory destMem; |
| 11899 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11900 | |
| 11901 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11902 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11903 | image_create_info.pNext = NULL; |
| 11904 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11905 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11906 | image_create_info.extent.width = 32; |
| 11907 | image_create_info.extent.height = 1; |
| 11908 | image_create_info.extent.depth = 1; |
| 11909 | image_create_info.mipLevels = 1; |
| 11910 | image_create_info.arrayLayers = 1; |
| 11911 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11912 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 11913 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11914 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11915 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11916 | err = |
| 11917 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11918 | ASSERT_VK_SUCCESS(err); |
| 11919 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11920 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11921 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11922 | err = |
| 11923 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11924 | ASSERT_VK_SUCCESS(err); |
| 11925 | |
| 11926 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11927 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11928 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 11929 | memAlloc.pNext = NULL; |
| 11930 | memAlloc.allocationSize = 0; |
| 11931 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11932 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 11933 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11934 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11935 | pass = |
| 11936 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 11937 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11938 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11939 | ASSERT_VK_SUCCESS(err); |
| 11940 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11941 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11942 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11943 | pass = |
| 11944 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 11945 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11946 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11947 | ASSERT_VK_SUCCESS(err); |
| 11948 | |
| 11949 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 11950 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11951 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11952 | ASSERT_VK_SUCCESS(err); |
| 11953 | |
| 11954 | BeginCommandBuffer(); |
| 11955 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11956 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 11957 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11958 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11959 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11960 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 11961 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11962 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11963 | resolveRegion.srcOffset.x = 0; |
| 11964 | resolveRegion.srcOffset.y = 0; |
| 11965 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11966 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11967 | resolveRegion.dstSubresource.mipLevel = 0; |
| 11968 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 11969 | resolveRegion.dstSubresource.layerCount = 0; |
| 11970 | resolveRegion.dstOffset.x = 0; |
| 11971 | resolveRegion.dstOffset.y = 0; |
| 11972 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11973 | resolveRegion.extent.width = 1; |
| 11974 | resolveRegion.extent.height = 1; |
| 11975 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11976 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 11977 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11978 | EndCommandBuffer(); |
| 11979 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11980 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11981 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11982 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11983 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11984 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 11985 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11986 | } |
| 11987 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11988 | TEST_F(VkLayerTest, ResolveImageHighSampleCount) { |
| 11989 | VkResult err; |
| 11990 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11991 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11992 | m_errorMonitor->SetDesiredFailureMsg( |
| 11993 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11994 | "vkCmdResolveImage called with dest sample count greater than 1."); |
| 11995 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11996 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11997 | |
Chris Forbes | a753069 | 2016-05-08 12:35:39 +1200 | [diff] [blame] | 11998 | // 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] | 11999 | VkImage srcImage; |
| 12000 | VkImage dstImage; |
| 12001 | VkDeviceMemory srcMem; |
| 12002 | VkDeviceMemory destMem; |
| 12003 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12004 | |
| 12005 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12006 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12007 | image_create_info.pNext = NULL; |
| 12008 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12009 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12010 | image_create_info.extent.width = 32; |
| 12011 | image_create_info.extent.height = 1; |
| 12012 | image_create_info.extent.depth = 1; |
| 12013 | image_create_info.mipLevels = 1; |
| 12014 | image_create_info.arrayLayers = 1; |
Chris Forbes | a753069 | 2016-05-08 12:35:39 +1200 | [diff] [blame] | 12015 | image_create_info.samples = VK_SAMPLE_COUNT_4_BIT; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12016 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12017 | // Note: Some implementations expect color attachment usage for any |
| 12018 | // multisample surface |
| 12019 | image_create_info.usage = |
| 12020 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12021 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12022 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12023 | err = |
| 12024 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12025 | ASSERT_VK_SUCCESS(err); |
| 12026 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12027 | // Note: Some implementations expect color attachment usage for any |
| 12028 | // multisample surface |
| 12029 | image_create_info.usage = |
| 12030 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12031 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12032 | err = |
| 12033 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12034 | ASSERT_VK_SUCCESS(err); |
| 12035 | |
| 12036 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12037 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12038 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12039 | memAlloc.pNext = NULL; |
| 12040 | memAlloc.allocationSize = 0; |
| 12041 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12042 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12043 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12044 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12045 | pass = |
| 12046 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12047 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12048 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12049 | ASSERT_VK_SUCCESS(err); |
| 12050 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12051 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12052 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12053 | pass = |
| 12054 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12055 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12056 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12057 | ASSERT_VK_SUCCESS(err); |
| 12058 | |
| 12059 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12060 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12061 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12062 | ASSERT_VK_SUCCESS(err); |
| 12063 | |
| 12064 | BeginCommandBuffer(); |
| 12065 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12066 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12067 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12068 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12069 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12070 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12071 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12072 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12073 | resolveRegion.srcOffset.x = 0; |
| 12074 | resolveRegion.srcOffset.y = 0; |
| 12075 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12076 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12077 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12078 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12079 | resolveRegion.dstSubresource.layerCount = 0; |
| 12080 | resolveRegion.dstOffset.x = 0; |
| 12081 | resolveRegion.dstOffset.y = 0; |
| 12082 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12083 | resolveRegion.extent.width = 1; |
| 12084 | resolveRegion.extent.height = 1; |
| 12085 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12086 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12087 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12088 | EndCommandBuffer(); |
| 12089 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12090 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12091 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12092 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12093 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12094 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12095 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12096 | } |
| 12097 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12098 | TEST_F(VkLayerTest, ResolveImageFormatMismatch) { |
| 12099 | VkResult err; |
| 12100 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12101 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12102 | m_errorMonitor->SetDesiredFailureMsg( |
| 12103 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12104 | "vkCmdResolveImage called with unmatched source and dest formats."); |
| 12105 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12106 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12107 | |
| 12108 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12109 | VkImage srcImage; |
| 12110 | VkImage dstImage; |
| 12111 | VkDeviceMemory srcMem; |
| 12112 | VkDeviceMemory destMem; |
| 12113 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12114 | |
| 12115 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12116 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12117 | image_create_info.pNext = NULL; |
| 12118 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12119 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12120 | image_create_info.extent.width = 32; |
| 12121 | image_create_info.extent.height = 1; |
| 12122 | image_create_info.extent.depth = 1; |
| 12123 | image_create_info.mipLevels = 1; |
| 12124 | image_create_info.arrayLayers = 1; |
| 12125 | image_create_info.samples = VK_SAMPLE_COUNT_2_BIT; |
| 12126 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12127 | // Note: Some implementations expect color attachment usage for any |
| 12128 | // multisample surface |
| 12129 | image_create_info.usage = |
| 12130 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12131 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12132 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12133 | err = |
| 12134 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12135 | ASSERT_VK_SUCCESS(err); |
| 12136 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12137 | // Set format to something other than source image |
| 12138 | image_create_info.format = VK_FORMAT_R32_SFLOAT; |
| 12139 | // Note: Some implementations expect color attachment usage for any |
| 12140 | // multisample surface |
| 12141 | image_create_info.usage = |
| 12142 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12143 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12144 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12145 | err = |
| 12146 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12147 | ASSERT_VK_SUCCESS(err); |
| 12148 | |
| 12149 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12150 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12151 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12152 | memAlloc.pNext = NULL; |
| 12153 | memAlloc.allocationSize = 0; |
| 12154 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12155 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12156 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12157 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12158 | pass = |
| 12159 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12160 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12161 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12162 | ASSERT_VK_SUCCESS(err); |
| 12163 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12164 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12165 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12166 | pass = |
| 12167 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12168 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12169 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12170 | ASSERT_VK_SUCCESS(err); |
| 12171 | |
| 12172 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12173 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12174 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12175 | ASSERT_VK_SUCCESS(err); |
| 12176 | |
| 12177 | BeginCommandBuffer(); |
| 12178 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12179 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12180 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12181 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12182 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12183 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12184 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12185 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12186 | resolveRegion.srcOffset.x = 0; |
| 12187 | resolveRegion.srcOffset.y = 0; |
| 12188 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12189 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12190 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12191 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12192 | resolveRegion.dstSubresource.layerCount = 0; |
| 12193 | resolveRegion.dstOffset.x = 0; |
| 12194 | resolveRegion.dstOffset.y = 0; |
| 12195 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12196 | resolveRegion.extent.width = 1; |
| 12197 | resolveRegion.extent.height = 1; |
| 12198 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12199 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12200 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12201 | EndCommandBuffer(); |
| 12202 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12203 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12204 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12205 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12206 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12207 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12208 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12209 | } |
| 12210 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12211 | TEST_F(VkLayerTest, ResolveImageTypeMismatch) { |
| 12212 | VkResult err; |
| 12213 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12214 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12215 | m_errorMonitor->SetDesiredFailureMsg( |
| 12216 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12217 | "vkCmdResolveImage called with unmatched source and dest image types."); |
| 12218 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12219 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12220 | |
| 12221 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12222 | VkImage srcImage; |
| 12223 | VkImage dstImage; |
| 12224 | VkDeviceMemory srcMem; |
| 12225 | VkDeviceMemory destMem; |
| 12226 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12227 | |
| 12228 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12229 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12230 | image_create_info.pNext = NULL; |
| 12231 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12232 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12233 | image_create_info.extent.width = 32; |
| 12234 | image_create_info.extent.height = 1; |
| 12235 | image_create_info.extent.depth = 1; |
| 12236 | image_create_info.mipLevels = 1; |
| 12237 | image_create_info.arrayLayers = 1; |
| 12238 | image_create_info.samples = VK_SAMPLE_COUNT_2_BIT; |
| 12239 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12240 | // Note: Some implementations expect color attachment usage for any |
| 12241 | // multisample surface |
| 12242 | image_create_info.usage = |
| 12243 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12244 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12245 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12246 | err = |
| 12247 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12248 | ASSERT_VK_SUCCESS(err); |
| 12249 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12250 | image_create_info.imageType = VK_IMAGE_TYPE_1D; |
| 12251 | // Note: Some implementations expect color attachment usage for any |
| 12252 | // multisample surface |
| 12253 | image_create_info.usage = |
| 12254 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12255 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12256 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12257 | err = |
| 12258 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12259 | ASSERT_VK_SUCCESS(err); |
| 12260 | |
| 12261 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12262 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12263 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 12264 | memAlloc.pNext = NULL; |
| 12265 | memAlloc.allocationSize = 0; |
| 12266 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12267 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 12268 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12269 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12270 | pass = |
| 12271 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12272 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12273 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12274 | ASSERT_VK_SUCCESS(err); |
| 12275 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12276 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12277 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12278 | pass = |
| 12279 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 12280 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12281 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12282 | ASSERT_VK_SUCCESS(err); |
| 12283 | |
| 12284 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 12285 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12286 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12287 | ASSERT_VK_SUCCESS(err); |
| 12288 | |
| 12289 | BeginCommandBuffer(); |
| 12290 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12291 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 12292 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12293 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12294 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12295 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 12296 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12297 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12298 | resolveRegion.srcOffset.x = 0; |
| 12299 | resolveRegion.srcOffset.y = 0; |
| 12300 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 12301 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12302 | resolveRegion.dstSubresource.mipLevel = 0; |
| 12303 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 12304 | resolveRegion.dstSubresource.layerCount = 0; |
| 12305 | resolveRegion.dstOffset.x = 0; |
| 12306 | resolveRegion.dstOffset.y = 0; |
| 12307 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12308 | resolveRegion.extent.width = 1; |
| 12309 | resolveRegion.extent.height = 1; |
| 12310 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12311 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 12312 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12313 | EndCommandBuffer(); |
| 12314 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12315 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12316 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12317 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12318 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12319 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 12320 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 12321 | } |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12322 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12323 | TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) { |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12324 | // 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] | 12325 | // to using a DS format, then cause it to hit error due to COLOR_BIT not |
| 12326 | // set in aspect |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12327 | // The image format check comes 2nd in validation so we trigger it first, |
| 12328 | // 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] | 12329 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12330 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12331 | m_errorMonitor->SetDesiredFailureMsg( |
| 12332 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12333 | "Combination depth/stencil image formats can have only the "); |
| 12334 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12335 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12336 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 12337 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12338 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 12339 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12340 | |
| 12341 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12342 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 12343 | ds_pool_ci.pNext = NULL; |
| 12344 | ds_pool_ci.maxSets = 1; |
| 12345 | ds_pool_ci.poolSizeCount = 1; |
| 12346 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12347 | |
| 12348 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12349 | err = |
| 12350 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12351 | ASSERT_VK_SUCCESS(err); |
| 12352 | |
| 12353 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12354 | dsl_binding.binding = 0; |
| 12355 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 12356 | dsl_binding.descriptorCount = 1; |
| 12357 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 12358 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12359 | |
| 12360 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12361 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 12362 | ds_layout_ci.pNext = NULL; |
| 12363 | ds_layout_ci.bindingCount = 1; |
| 12364 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12365 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12366 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 12367 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12368 | ASSERT_VK_SUCCESS(err); |
| 12369 | |
| 12370 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 12371 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 12372 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 12373 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12374 | alloc_info.descriptorPool = ds_pool; |
| 12375 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12376 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 12377 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12378 | ASSERT_VK_SUCCESS(err); |
| 12379 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12380 | VkImage image_bad; |
| 12381 | VkImage image_good; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12382 | // One bad format and one good format for Color attachment |
Tobin Ehlis | 269f032 | 2016-05-25 16:24:21 -0600 | [diff] [blame] | 12383 | const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12384 | const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12385 | const int32_t tex_width = 32; |
| 12386 | const int32_t tex_height = 32; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12387 | |
| 12388 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12389 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12390 | image_create_info.pNext = NULL; |
| 12391 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12392 | image_create_info.format = tex_format_bad; |
| 12393 | image_create_info.extent.width = tex_width; |
| 12394 | image_create_info.extent.height = tex_height; |
| 12395 | image_create_info.extent.depth = 1; |
| 12396 | image_create_info.mipLevels = 1; |
| 12397 | image_create_info.arrayLayers = 1; |
| 12398 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12399 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12400 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | |
| 12401 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 12402 | image_create_info.flags = 0; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12403 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12404 | err = |
| 12405 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12406 | ASSERT_VK_SUCCESS(err); |
| 12407 | image_create_info.format = tex_format_good; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12408 | image_create_info.usage = |
| 12409 | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 12410 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, |
| 12411 | &image_good); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12412 | ASSERT_VK_SUCCESS(err); |
| 12413 | |
| 12414 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12415 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12416 | image_view_create_info.image = image_bad; |
| 12417 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 12418 | image_view_create_info.format = tex_format_bad; |
| 12419 | image_view_create_info.subresourceRange.baseArrayLayer = 0; |
| 12420 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 12421 | image_view_create_info.subresourceRange.layerCount = 1; |
| 12422 | image_view_create_info.subresourceRange.levelCount = 1; |
| 12423 | image_view_create_info.subresourceRange.aspectMask = |
| 12424 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12425 | |
| 12426 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 12427 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 12428 | &view); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 12429 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 12430 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12431 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12432 | vkDestroyImage(m_device->device(), image_bad, NULL); |
| 12433 | vkDestroyImage(m_device->device(), image_good, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 12434 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 12435 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 12436 | } |
Tobin Ehlis | 6e23d77 | 2016-05-19 11:08:34 -0600 | [diff] [blame] | 12437 | |
| 12438 | TEST_F(VkLayerTest, ClearImageErrors) { |
| 12439 | TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and " |
| 12440 | "ClearDepthStencilImage with a color image."); |
| 12441 | |
| 12442 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 12443 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 12444 | |
| 12445 | // Renderpass is started here so end it as Clear cmds can't be in renderpass |
| 12446 | BeginCommandBuffer(); |
| 12447 | m_commandBuffer->EndRenderPass(); |
| 12448 | |
| 12449 | // Color image |
| 12450 | VkClearColorValue clear_color; |
| 12451 | memset(clear_color.uint32, 0, sizeof(uint32_t) * 4); |
| 12452 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 12453 | const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 12454 | const int32_t img_width = 32; |
| 12455 | const int32_t img_height = 32; |
| 12456 | VkImageCreateInfo image_create_info = {}; |
| 12457 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 12458 | image_create_info.pNext = NULL; |
| 12459 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12460 | image_create_info.format = color_format; |
| 12461 | image_create_info.extent.width = img_width; |
| 12462 | image_create_info.extent.height = img_height; |
| 12463 | image_create_info.extent.depth = 1; |
| 12464 | image_create_info.mipLevels = 1; |
| 12465 | image_create_info.arrayLayers = 1; |
| 12466 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 12467 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 12468 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 12469 | |
| 12470 | vk_testing::Image color_image; |
| 12471 | color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 12472 | reqs); |
| 12473 | |
| 12474 | const VkImageSubresourceRange color_range = |
| 12475 | vk_testing::Image::subresource_range(image_create_info, |
| 12476 | VK_IMAGE_ASPECT_COLOR_BIT); |
| 12477 | |
| 12478 | // Depth/Stencil image |
| 12479 | VkClearDepthStencilValue clear_value = {0}; |
| 12480 | reqs = 0; // don't need HOST_VISIBLE DS image |
| 12481 | VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info(); |
| 12482 | ds_image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 12483 | ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 12484 | ds_image_create_info.extent.width = 64; |
| 12485 | ds_image_create_info.extent.height = 64; |
| 12486 | ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 12487 | ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 12488 | |
| 12489 | vk_testing::Image ds_image; |
| 12490 | ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, |
| 12491 | reqs); |
| 12492 | |
| 12493 | const VkImageSubresourceRange ds_range = |
| 12494 | vk_testing::Image::subresource_range(ds_image_create_info, |
| 12495 | VK_IMAGE_ASPECT_DEPTH_BIT); |
| 12496 | |
| 12497 | m_errorMonitor->SetDesiredFailureMsg( |
| 12498 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12499 | "vkCmdClearColorImage called with depth/stencil image."); |
| 12500 | |
| 12501 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), |
| 12502 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, |
| 12503 | &color_range); |
| 12504 | |
| 12505 | m_errorMonitor->VerifyFound(); |
| 12506 | |
Tony Barbour | 26434b9 | 2016-06-02 09:43:50 -0600 | [diff] [blame] | 12507 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12508 | "vkCmdClearColorImage called with " |
| 12509 | "image created without " |
| 12510 | "VK_IMAGE_USAGE_TRANSFER_DST_BIT"); |
| 12511 | |
| 12512 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), |
| 12513 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, |
| 12514 | &color_range); |
| 12515 | |
| 12516 | m_errorMonitor->VerifyFound(); |
| 12517 | |
Tobin Ehlis | 6e23d77 | 2016-05-19 11:08:34 -0600 | [diff] [blame] | 12518 | // Call CmdClearDepthStencilImage with color image |
| 12519 | m_errorMonitor->SetDesiredFailureMsg( |
| 12520 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 12521 | "vkCmdClearDepthStencilImage called without a depth/stencil image."); |
| 12522 | |
| 12523 | vkCmdClearDepthStencilImage( |
| 12524 | m_commandBuffer->GetBufferHandle(), color_image.handle(), |
| 12525 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, |
| 12526 | &ds_range); |
| 12527 | |
| 12528 | m_errorMonitor->VerifyFound(); |
| 12529 | } |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 12530 | #endif // IMAGE_TESTS |
| 12531 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 12532 | int main(int argc, char **argv) { |
| 12533 | int result; |
| 12534 | |
Cody Northrop | 8e54a40 | 2016-03-08 22:25:52 -0700 | [diff] [blame] | 12535 | #ifdef ANDROID |
| 12536 | int vulkanSupport = InitVulkan(); |
| 12537 | if (vulkanSupport == 0) |
| 12538 | return 1; |
| 12539 | #endif |
| 12540 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 12541 | ::testing::InitGoogleTest(&argc, argv); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 12542 | VkTestFramework::InitArgs(&argc, argv); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 12543 | |
| 12544 | ::testing::AddGlobalTestEnvironment(new TestEnvironment); |
| 12545 | |
| 12546 | result = RUN_ALL_TESTS(); |
| 12547 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 12548 | VkTestFramework::Finish(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 12549 | return result; |
| 12550 | } |