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 Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 66 | } BsoFailSelect; |
| 67 | |
| 68 | struct vktriangle_vs_uniform { |
| 69 | // Must start with MVP |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 70 | float mvp[4][4]; |
| 71 | float position[3][4]; |
| 72 | float color[3][4]; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 73 | }; |
| 74 | |
Mark Lobodzinski | 75a97e6 | 2015-06-02 09:41:30 -0500 | [diff] [blame] | 75 | static const char bindStateVertShaderText[] = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 76 | "#version 450\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 77 | "vec2 vertices[3];\n" |
| 78 | "out gl_PerVertex {\n" |
| 79 | " vec4 gl_Position;\n" |
| 80 | "};\n" |
| 81 | "void main() {\n" |
| 82 | " vertices[0] = vec2(-1.0, -1.0);\n" |
| 83 | " vertices[1] = vec2( 1.0, -1.0);\n" |
| 84 | " vertices[2] = vec2( 0.0, 1.0);\n" |
| 85 | " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n" |
| 86 | "}\n"; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 87 | |
Mark Lobodzinski | 75a97e6 | 2015-06-02 09:41:30 -0500 | [diff] [blame] | 88 | static const char bindStateFragShaderText[] = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 89 | "#version 450\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 90 | "\n" |
| 91 | "layout(location = 0) out vec4 uFragColor;\n" |
| 92 | "void main(){\n" |
| 93 | " uFragColor = vec4(0,1,0,1);\n" |
| 94 | "}\n"; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 95 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 96 | static VKAPI_ATTR VkBool32 VKAPI_CALL |
| 97 | myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, |
| 98 | uint64_t srcObject, size_t location, int32_t msgCode, |
| 99 | const char *pLayerPrefix, const char *pMsg, void *pUserData); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 100 | |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 101 | // ******************************************************** |
| 102 | // ErrorMonitor Usage: |
| 103 | // |
| 104 | // Call SetDesiredFailureMsg with a string to be compared against all |
| 105 | // encountered log messages. Passing NULL will match all log messages. |
| 106 | // logMsg will return true for skipCall only if msg is matched or NULL. |
| 107 | // |
| 108 | // Call DesiredMsgFound to determine if the desired failure message |
| 109 | // was encountered. |
| 110 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 111 | class ErrorMonitor { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 112 | public: |
| 113 | ErrorMonitor() { |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 114 | test_platform_thread_create_mutex(&m_mutex); |
| 115 | test_platform_thread_lock_mutex(&m_mutex); |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 116 | m_msgFlags = VK_DEBUG_REPORT_INFORMATION_BIT_EXT; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 117 | m_bailout = NULL; |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 118 | test_platform_thread_unlock_mutex(&m_mutex); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 119 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 120 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 121 | ~ErrorMonitor() { test_platform_thread_delete_mutex(&m_mutex); } |
| 122 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 123 | void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 124 | // also discard all collected messages to this point |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 125 | test_platform_thread_lock_mutex(&m_mutex); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 126 | m_failureMsg.clear(); |
| 127 | m_otherMsgs.clear(); |
| 128 | m_desiredMsg = msgString; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 129 | m_msgFound = VK_FALSE; |
| 130 | m_msgFlags = msgFlags; |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 131 | test_platform_thread_unlock_mutex(&m_mutex); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 132 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 133 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 134 | VkBool32 CheckForDesiredMsg(VkFlags msgFlags, const char *msgString) { |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 135 | VkBool32 result = VK_FALSE; |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 136 | test_platform_thread_lock_mutex(&m_mutex); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 137 | if (m_bailout != NULL) { |
| 138 | *m_bailout = true; |
| 139 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 140 | string errorString(msgString); |
| 141 | if (msgFlags & m_msgFlags) { |
| 142 | if (errorString.find(m_desiredMsg) != string::npos) { |
Chris Forbes | c7b8ad7 | 2016-04-04 18:50:38 +1200 | [diff] [blame] | 143 | if (m_msgFound) { /* if multiple matches, don't lose all but the last! */ |
| 144 | m_otherMsgs.push_back(m_failureMsg); |
| 145 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 146 | m_failureMsg = errorString; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 147 | m_msgFound = VK_TRUE; |
| 148 | result = VK_TRUE; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 149 | } else { |
| 150 | m_otherMsgs.push_back(errorString); |
| 151 | } |
| 152 | } |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 153 | test_platform_thread_unlock_mutex(&m_mutex); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 154 | return result; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 155 | } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 156 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 157 | vector<string> GetOtherFailureMsgs(void) { return m_otherMsgs; } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 158 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 159 | string GetFailureMsg(void) { return m_failureMsg; } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 160 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 161 | VkBool32 DesiredMsgFound(void) { return m_msgFound; } |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 162 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 163 | void SetBailout(bool *bailout) { m_bailout = bailout; } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 164 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 165 | void DumpFailureMsgs(void) { |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 166 | vector<string> otherMsgs = GetOtherFailureMsgs(); |
| 167 | cout << "Other error messages logged for this test were:" << endl; |
| 168 | for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) { |
| 169 | cout << " " << *iter << endl; |
| 170 | } |
| 171 | } |
| 172 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 173 | /* helpers */ |
| 174 | |
| 175 | void ExpectSuccess() { |
| 176 | // match anything |
| 177 | SetDesiredFailureMsg(~0u, ""); |
| 178 | } |
| 179 | |
| 180 | void VerifyFound() { |
| 181 | // Not seeing the desired message is a failure. /Before/ throwing, dump |
| 182 | // any other messages. |
| 183 | if (!DesiredMsgFound()) { |
| 184 | DumpFailureMsgs(); |
| 185 | FAIL() << "Did not receive expected error '" << m_desiredMsg << "'"; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | void VerifyNotFound() { |
| 190 | // ExpectSuccess() configured us to match anything. Any error is a |
| 191 | // failure. |
| 192 | if (DesiredMsgFound()) { |
| 193 | DumpFailureMsgs(); |
| 194 | FAIL() << "Expected to succeed but got error: " << GetFailureMsg(); |
| 195 | } |
| 196 | } |
| 197 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 198 | private: |
| 199 | VkFlags m_msgFlags; |
| 200 | string m_desiredMsg; |
| 201 | string m_failureMsg; |
| 202 | vector<string> m_otherMsgs; |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 203 | test_platform_thread_mutex m_mutex; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 204 | bool *m_bailout; |
| 205 | VkBool32 m_msgFound; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 206 | }; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 207 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 208 | static VKAPI_ATTR VkBool32 VKAPI_CALL |
| 209 | myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, |
| 210 | uint64_t srcObject, size_t location, int32_t msgCode, |
| 211 | const char *pLayerPrefix, const char *pMsg, void *pUserData) { |
| 212 | if (msgFlags & |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 213 | (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] | 214 | VK_DEBUG_REPORT_ERROR_BIT_EXT)) { |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 215 | ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 216 | return errMonitor->CheckForDesiredMsg(msgFlags, pMsg); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 217 | } |
Courtney Goeltzenleuchter | 0664083 | 2015-09-04 13:52:24 -0600 | [diff] [blame] | 218 | return false; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 219 | } |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 220 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 221 | class VkLayerTest : public VkRenderFramework { |
| 222 | public: |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 223 | VkResult BeginCommandBuffer(VkCommandBufferObj &commandBuffer); |
| 224 | VkResult EndCommandBuffer(VkCommandBufferObj &commandBuffer); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 225 | void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, |
| 226 | BsoFailSelect failMask); |
| 227 | void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, |
| 228 | VkPipelineObj &pipelineobj, |
| 229 | VkDescriptorSetObj &descriptorSet, |
| 230 | BsoFailSelect failMask); |
| 231 | void GenericDrawPreparation(VkPipelineObj &pipelineobj, |
| 232 | VkDescriptorSetObj &descriptorSet, |
| 233 | BsoFailSelect failMask) { |
| 234 | GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, |
| 235 | failMask); |
| 236 | } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 237 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 238 | /* Convenience functions that use built-in command buffer */ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 239 | VkResult BeginCommandBuffer() { |
| 240 | return BeginCommandBuffer(*m_commandBuffer); |
| 241 | } |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 242 | VkResult EndCommandBuffer() { return EndCommandBuffer(*m_commandBuffer); } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 243 | void Draw(uint32_t vertexCount, uint32_t instanceCount, |
| 244 | uint32_t firstVertex, uint32_t firstInstance) { |
| 245 | m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, |
| 246 | firstInstance); |
| 247 | } |
| 248 | void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, |
| 249 | uint32_t firstIndex, int32_t vertexOffset, |
| 250 | uint32_t firstInstance) { |
| 251 | m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, |
| 252 | vertexOffset, firstInstance); |
| 253 | } |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 254 | void QueueCommandBuffer() { m_commandBuffer->QueueCommandBuffer(); } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 255 | void QueueCommandBuffer(const VkFence &fence) { |
| 256 | m_commandBuffer->QueueCommandBuffer(fence); |
| 257 | } |
| 258 | void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, |
| 259 | VkDeviceSize offset, uint32_t binding) { |
| 260 | m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding); |
| 261 | } |
| 262 | void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) { |
| 263 | m_commandBuffer->BindIndexBuffer(indexBuffer, offset); |
| 264 | } |
| 265 | |
| 266 | protected: |
| 267 | ErrorMonitor *m_errorMonitor; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 268 | bool m_enableWSI; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 269 | |
| 270 | virtual void SetUp() { |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 271 | std::vector<const char *> instance_layer_names; |
| 272 | std::vector<const char *> device_layer_names; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 273 | std::vector<const char *> instance_extension_names; |
| 274 | std::vector<const char *> device_extension_names; |
Tony Barbour | 3fdff9e | 2015-04-23 12:55:36 -0600 | [diff] [blame] | 275 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 276 | instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); |
Courtney Goeltzenleuchter | c2b06fe | 2015-06-16 15:59:11 -0600 | [diff] [blame] | 277 | /* |
| 278 | * Since CreateDbgMsgCallback is an instance level extension call |
| 279 | * any extension / layer that utilizes that feature also needs |
| 280 | * to be enabled at create instance time. |
| 281 | */ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 282 | // Use Threading layer first to protect others from |
| 283 | // ThreadCommandBufferCollision test |
Courtney Goeltzenleuchter | 7688532 | 2016-02-06 17:11:22 -0700 | [diff] [blame] | 284 | instance_layer_names.push_back("VK_LAYER_GOOGLE_threading"); |
Tobin Ehlis | 24aab04 | 2016-03-24 10:54:18 -0600 | [diff] [blame] | 285 | instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation"); |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 286 | instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker"); |
Tobin Ehlis | c96f806 | 2016-03-09 16:12:48 -0700 | [diff] [blame] | 287 | instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation"); |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 288 | instance_layer_names.push_back("VK_LAYER_LUNARG_device_limits"); |
| 289 | instance_layer_names.push_back("VK_LAYER_LUNARG_image"); |
Ian Elliott | e48a138 | 2016-04-28 14:22:58 -0600 | [diff] [blame] | 290 | instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain"); |
Dustin Graves | eaa78cd | 2016-01-26 16:30:22 -0700 | [diff] [blame] | 291 | instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects"); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 292 | |
Courtney Goeltzenleuchter | 7688532 | 2016-02-06 17:11:22 -0700 | [diff] [blame] | 293 | device_layer_names.push_back("VK_LAYER_GOOGLE_threading"); |
Tobin Ehlis | 24aab04 | 2016-03-24 10:54:18 -0600 | [diff] [blame] | 294 | device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation"); |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 295 | device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker"); |
Tobin Ehlis | c96f806 | 2016-03-09 16:12:48 -0700 | [diff] [blame] | 296 | device_layer_names.push_back("VK_LAYER_LUNARG_core_validation"); |
Michael Lentine | 03107b4 | 2015-12-11 10:49:51 -0800 | [diff] [blame] | 297 | device_layer_names.push_back("VK_LAYER_LUNARG_device_limits"); |
| 298 | device_layer_names.push_back("VK_LAYER_LUNARG_image"); |
Ian Elliott | e48a138 | 2016-04-28 14:22:58 -0600 | [diff] [blame] | 299 | device_layer_names.push_back("VK_LAYER_LUNARG_swapchain"); |
Dustin Graves | eaa78cd | 2016-01-26 16:30:22 -0700 | [diff] [blame] | 300 | device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects"); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 301 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 302 | if (m_enableWSI) { |
| 303 | instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME); |
| 304 | device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME); |
| 305 | #ifdef NEED_TO_TEST_THIS_ON_PLATFORM |
| 306 | #if defined(VK_USE_PLATFORM_ANDROID_KHR) |
| 307 | instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME); |
| 308 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 309 | #if defined(VK_USE_PLATFORM_MIR_KHR) |
| 310 | instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME); |
| 311 | #endif // VK_USE_PLATFORM_MIR_KHR |
| 312 | #if defined(VK_USE_PLATFORM_WAYLAND_KHR) |
| 313 | instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME); |
| 314 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
| 315 | #if defined(VK_USE_PLATFORM_WIN32_KHR) |
| 316 | instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); |
| 317 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 318 | #endif // NEED_TO_TEST_THIS_ON_PLATFORM |
| 319 | #if defined(VK_USE_PLATFORM_XCB_KHR) |
| 320 | instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME); |
| 321 | #elif defined(VK_USE_PLATFORM_XLIB_KHR) |
| 322 | instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME); |
| 323 | #endif // VK_USE_PLATFORM_XLIB_KHR |
| 324 | } |
| 325 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 326 | this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 327 | this->app_info.pNext = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 328 | this->app_info.pApplicationName = "layer_tests"; |
| 329 | this->app_info.applicationVersion = 1; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 330 | this->app_info.pEngineName = "unittest"; |
| 331 | this->app_info.engineVersion = 1; |
Jon Ashburn | c5012ff | 2016-03-22 13:57:46 -0600 | [diff] [blame] | 332 | this->app_info.apiVersion = VK_API_VERSION_1_0; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 333 | |
Tony Barbour | 15524c3 | 2015-04-29 17:34:29 -0600 | [diff] [blame] | 334 | m_errorMonitor = new ErrorMonitor; |
Courtney Goeltzenleuchter | cd69eee | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 335 | InitFramework(instance_layer_names, device_layer_names, |
| 336 | instance_extension_names, device_extension_names, |
| 337 | myDbgFunc, m_errorMonitor); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | virtual void TearDown() { |
| 341 | // Clean up resources before we reset |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 342 | ShutdownFramework(); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 343 | delete m_errorMonitor; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 344 | } |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 345 | |
| 346 | VkLayerTest() { |
| 347 | m_enableWSI = false; |
| 348 | } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 349 | }; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 350 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 351 | VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &commandBuffer) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 352 | VkResult result; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 353 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 354 | result = commandBuffer.BeginCommandBuffer(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 355 | |
| 356 | /* |
| 357 | * For render test all drawing happens in a single render pass |
| 358 | * on a single command buffer. |
| 359 | */ |
Chris Forbes | 76a5eeb | 2015-06-16 14:05:59 +1200 | [diff] [blame] | 360 | if (VK_SUCCESS == result && renderPass()) { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 361 | commandBuffer.BeginRenderPass(renderPassBeginInfo()); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | return result; |
| 365 | } |
| 366 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 367 | VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &commandBuffer) { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 368 | VkResult result; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 369 | |
Chris Forbes | 76a5eeb | 2015-06-16 14:05:59 +1200 | [diff] [blame] | 370 | if (renderPass()) { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 371 | commandBuffer.EndRenderPass(); |
Chris Forbes | 76a5eeb | 2015-06-16 14:05:59 +1200 | [diff] [blame] | 372 | } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 373 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 374 | result = commandBuffer.EndCommandBuffer(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 375 | |
| 376 | return result; |
| 377 | } |
| 378 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 379 | void VkLayerTest::VKTriangleTest(const char *vertShaderText, |
| 380 | const char *fragShaderText, |
| 381 | BsoFailSelect failMask) { |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 382 | // Create identity matrix |
| 383 | int i; |
| 384 | struct vktriangle_vs_uniform data; |
| 385 | |
| 386 | glm::mat4 Projection = glm::mat4(1.0f); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 387 | glm::mat4 View = glm::mat4(1.0f); |
| 388 | glm::mat4 Model = glm::mat4(1.0f); |
| 389 | glm::mat4 MVP = Projection * View * Model; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 390 | const int matrixSize = sizeof(MVP); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 391 | const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 392 | |
| 393 | memcpy(&data.mvp, &MVP[0][0], matrixSize); |
| 394 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 395 | static const Vertex tri_data[] = { |
| 396 | {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, |
| 397 | {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, |
| 398 | {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)}, |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 399 | }; |
| 400 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 401 | for (i = 0; i < 3; i++) { |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 402 | data.position[i][0] = tri_data[i].posX; |
| 403 | data.position[i][1] = tri_data[i].posY; |
| 404 | data.position[i][2] = tri_data[i].posZ; |
| 405 | data.position[i][3] = tri_data[i].posW; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 406 | data.color[i][0] = tri_data[i].r; |
| 407 | data.color[i][1] = tri_data[i].g; |
| 408 | data.color[i][2] = tri_data[i].b; |
| 409 | data.color[i][3] = tri_data[i].a; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 413 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 414 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 415 | VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), |
| 416 | (const void *)&data); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 417 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 418 | VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 419 | VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, |
| 420 | this); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 421 | |
| 422 | VkPipelineObj pipelineobj(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 423 | pipelineobj.AddColorAttachment(); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 424 | pipelineobj.AddShader(&vs); |
| 425 | pipelineobj.AddShader(&ps); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 426 | if (failMask & BsoFailLineWidth) { |
| 427 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH); |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 428 | VkPipelineInputAssemblyStateCreateInfo ia_state = {}; |
| 429 | ia_state.sType = |
| 430 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 431 | ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST; |
| 432 | pipelineobj.SetInputAssembly(&ia_state); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 433 | } |
| 434 | if (failMask & BsoFailDepthBias) { |
| 435 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS); |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 436 | VkPipelineRasterizationStateCreateInfo rs_state = {}; |
| 437 | rs_state.sType = |
| 438 | VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 439 | rs_state.depthBiasEnable = VK_TRUE; |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 440 | rs_state.lineWidth = 1.0f; |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 441 | pipelineobj.SetRasterization(&rs_state); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 442 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 443 | // Viewport and scissors must stay in synch or other errors will occur than |
| 444 | // the ones we want |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 445 | if (failMask & BsoFailViewport) { |
| 446 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 447 | m_viewports.clear(); |
| 448 | m_scissors.clear(); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 449 | } |
| 450 | if (failMask & BsoFailScissor) { |
| 451 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 452 | m_scissors.clear(); |
| 453 | m_viewports.clear(); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 454 | } |
| 455 | if (failMask & BsoFailBlend) { |
| 456 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS); |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 457 | VkPipelineColorBlendAttachmentState att_state = {}; |
| 458 | att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR; |
| 459 | att_state.blendEnable = VK_TRUE; |
| 460 | pipelineobj.AddColorAttachment(0, &att_state); |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 461 | } |
| 462 | if (failMask & BsoFailDepthBounds) { |
| 463 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS); |
| 464 | } |
| 465 | if (failMask & BsoFailStencilReadMask) { |
| 466 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK); |
| 467 | } |
| 468 | if (failMask & BsoFailStencilWriteMask) { |
| 469 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK); |
| 470 | } |
| 471 | if (failMask & BsoFailStencilReference) { |
| 472 | pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE); |
| 473 | } |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 474 | |
| 475 | VkDescriptorSetObj descriptorSet(m_device); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 476 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, |
| 477 | constantBuffer); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 478 | |
| 479 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 480 | ASSERT_VK_SUCCESS(BeginCommandBuffer()); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 481 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 482 | GenericDrawPreparation(pipelineobj, descriptorSet, failMask); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 483 | |
| 484 | // render triangle |
Courtney Goeltzenleuchter | 08c2637 | 2015-09-23 12:31:50 -0600 | [diff] [blame] | 485 | Draw(3, 1, 0, 0); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 486 | |
| 487 | // finalize recording of the command buffer |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 488 | EndCommandBuffer(); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 489 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 490 | QueueCommandBuffer(); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 491 | } |
| 492 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 493 | void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, |
| 494 | VkPipelineObj &pipelineobj, |
| 495 | VkDescriptorSetObj &descriptorSet, |
| 496 | BsoFailSelect failMask) { |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 497 | if (m_depthStencil->Initialized()) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 498 | commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 499 | m_stencil_clear_color, m_depthStencil); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 500 | } else { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 501 | commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 502 | m_stencil_clear_color, NULL); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 503 | } |
| 504 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 505 | commandBuffer->PrepareAttachments(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 506 | // Make sure depthWriteEnable is set so that Depth fail test will work |
| 507 | // correctly |
| 508 | // Make sure stencilTestEnable is set so that Stencil fail test will work |
| 509 | // correctly |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 510 | VkStencilOpState stencil = {}; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 511 | stencil.failOp = VK_STENCIL_OP_KEEP; |
| 512 | stencil.passOp = VK_STENCIL_OP_KEEP; |
| 513 | stencil.depthFailOp = VK_STENCIL_OP_KEEP; |
| 514 | stencil.compareOp = VK_COMPARE_OP_NEVER; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 515 | |
| 516 | VkPipelineDepthStencilStateCreateInfo ds_ci = {}; |
| 517 | ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 518 | ds_ci.pNext = NULL; |
| 519 | ds_ci.depthTestEnable = VK_FALSE; |
| 520 | ds_ci.depthWriteEnable = VK_TRUE; |
| 521 | ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER; |
| 522 | ds_ci.depthBoundsTestEnable = VK_FALSE; |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 523 | if (failMask & BsoFailDepthBounds) { |
| 524 | ds_ci.depthBoundsTestEnable = VK_TRUE; |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 525 | ds_ci.maxDepthBounds = 0.0f; |
| 526 | ds_ci.minDepthBounds = 0.0f; |
Tobin Ehlis | 7a1d235 | 2016-03-28 11:18:19 -0600 | [diff] [blame] | 527 | } |
Courtney Goeltzenleuchter | 507ba97 | 2015-09-30 16:16:57 -0600 | [diff] [blame] | 528 | ds_ci.stencilTestEnable = VK_TRUE; |
| 529 | ds_ci.front = stencil; |
| 530 | ds_ci.back = stencil; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 531 | |
Tobin Ehlis | 4bf96d1 | 2015-06-25 11:58:41 -0600 | [diff] [blame] | 532 | pipelineobj.SetDepthStencil(&ds_ci); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 533 | pipelineobj.SetViewport(m_viewports); |
| 534 | pipelineobj.SetScissor(m_scissors); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 535 | descriptorSet.CreateVKDescriptorSet(commandBuffer); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 536 | VkResult err = pipelineobj.CreateVKPipeline( |
| 537 | descriptorSet.GetPipelineLayout(), renderPass()); |
Cody Northrop | 29a08f2 | 2015-08-27 10:20:35 -0600 | [diff] [blame] | 538 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 539 | commandBuffer->BindPipeline(pipelineobj); |
| 540 | commandBuffer->BindDescriptorSet(descriptorSet); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 541 | } |
| 542 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 543 | class VkWsiEnabledLayerTest : public VkLayerTest { |
| 544 | public: |
| 545 | protected: |
| 546 | VkWsiEnabledLayerTest() { |
| 547 | m_enableWSI = true; |
| 548 | } |
| 549 | }; |
| 550 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 551 | // ******************************************************************************************************************** |
| 552 | // ******************************************************************************************************************** |
| 553 | // ******************************************************************************************************************** |
| 554 | // ******************************************************************************************************************** |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 555 | #if PARAMETER_VALIDATION_TESTS |
| 556 | TEST_F(VkLayerTest, RequiredParameter) { |
| 557 | TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, " |
| 558 | "pointer, array, and array count parameters"); |
| 559 | |
| 560 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 561 | |
| 562 | m_errorMonitor->SetDesiredFailureMsg( |
| 563 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 564 | "required parameter pFeatures specified as NULL"); |
| 565 | // Specify NULL for a pointer to a handle |
| 566 | // Expected to trigger an error with |
| 567 | // parameter_validation::validate_required_pointer |
| 568 | vkGetPhysicalDeviceFeatures(gpu(), NULL); |
| 569 | m_errorMonitor->VerifyFound(); |
| 570 | |
| 571 | m_errorMonitor->SetDesiredFailureMsg( |
| 572 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Dustin Graves | a4bb8c1 | 2016-05-16 17:22:51 -0600 | [diff] [blame] | 573 | "required parameter pQueueFamilyPropertyCount specified as NULL"); |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 574 | // Specify NULL for pointer to array count |
| 575 | // Expected to trigger an error with parameter_validation::validate_array |
Dustin Graves | a4bb8c1 | 2016-05-16 17:22:51 -0600 | [diff] [blame] | 576 | vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL); |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 577 | m_errorMonitor->VerifyFound(); |
| 578 | |
| 579 | m_errorMonitor->SetDesiredFailureMsg( |
| 580 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 581 | "parameter viewportCount must be greater than 0"); |
| 582 | // Specify 0 for a required array count |
| 583 | // Expected to trigger an error with parameter_validation::validate_array |
| 584 | VkViewport view_port = {}; |
| 585 | m_commandBuffer->SetViewport(0, 0, &view_port); |
| 586 | m_errorMonitor->VerifyFound(); |
| 587 | |
| 588 | m_errorMonitor->SetDesiredFailureMsg( |
| 589 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 590 | "required parameter pViewports specified as NULL"); |
| 591 | // Specify NULL for a required array |
| 592 | // Expected to trigger an error with parameter_validation::validate_array |
| 593 | m_commandBuffer->SetViewport(0, 1, NULL); |
| 594 | m_errorMonitor->VerifyFound(); |
| 595 | |
| 596 | m_errorMonitor->SetDesiredFailureMsg( |
| 597 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 598 | "required parameter memory specified as VK_NULL_HANDLE"); |
| 599 | // Specify VK_NULL_HANDLE for a required handle |
| 600 | // Expected to trigger an error with |
| 601 | // parameter_validation::validate_required_handle |
| 602 | vkUnmapMemory(device(), VK_NULL_HANDLE); |
| 603 | m_errorMonitor->VerifyFound(); |
| 604 | |
| 605 | m_errorMonitor->SetDesiredFailureMsg( |
| 606 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 607 | "required parameter pFences[0] specified as VK_NULL_HANDLE"); |
| 608 | // Specify VK_NULL_HANDLE for a required handle array entry |
| 609 | // Expected to trigger an error with |
| 610 | // parameter_validation::validate_required_handle_array |
| 611 | VkFence fence = VK_NULL_HANDLE; |
| 612 | vkResetFences(device(), 1, &fence); |
| 613 | m_errorMonitor->VerifyFound(); |
| 614 | |
| 615 | m_errorMonitor->SetDesiredFailureMsg( |
| 616 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 617 | "required parameter pAllocateInfo specified as NULL"); |
| 618 | // Specify NULL for a required struct pointer |
| 619 | // Expected to trigger an error with |
| 620 | // parameter_validation::validate_struct_type |
| 621 | VkDeviceMemory memory = VK_NULL_HANDLE; |
| 622 | vkAllocateMemory(device(), NULL, NULL, &memory); |
| 623 | m_errorMonitor->VerifyFound(); |
| 624 | |
| 625 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 626 | "value of faceMask must not be 0"); |
| 627 | // Specify 0 for a required VkFlags parameter |
| 628 | // Expected to trigger an error with parameter_validation::validate_flags |
| 629 | m_commandBuffer->SetStencilReference(0, 0); |
| 630 | m_errorMonitor->VerifyFound(); |
| 631 | |
| 632 | m_errorMonitor->SetDesiredFailureMsg( |
| 633 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 634 | "value of pSubmits[i].pWaitDstStageMask[0] must not be 0"); |
| 635 | // Specify 0 for a required VkFlags array entry |
| 636 | // Expected to trigger an error with |
| 637 | // parameter_validation::validate_flags_array |
| 638 | VkSemaphore semaphore = VK_NULL_HANDLE; |
| 639 | VkPipelineStageFlags stageFlags = 0; |
| 640 | VkSubmitInfo submitInfo = {}; |
| 641 | submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 642 | submitInfo.waitSemaphoreCount = 1; |
| 643 | submitInfo.pWaitSemaphores = &semaphore; |
| 644 | submitInfo.pWaitDstStageMask = &stageFlags; |
| 645 | vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE); |
| 646 | m_errorMonitor->VerifyFound(); |
| 647 | } |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 648 | |
Dustin Graves | fce74c0 | 2016-05-10 11:42:58 -0600 | [diff] [blame] | 649 | TEST_F(VkLayerTest, ReservedParameter) { |
| 650 | TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter"); |
| 651 | |
| 652 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 653 | |
| 654 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 655 | " must be 0"); |
| 656 | // Specify 0 for a reserved VkFlags parameter |
| 657 | // Expected to trigger an error with |
| 658 | // parameter_validation::validate_reserved_flags |
| 659 | VkEvent event_handle = VK_NULL_HANDLE; |
| 660 | VkEventCreateInfo event_info = {}; |
| 661 | event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 662 | event_info.flags = 1; |
| 663 | vkCreateEvent(device(), &event_info, NULL, &event_handle); |
| 664 | m_errorMonitor->VerifyFound(); |
| 665 | } |
| 666 | |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 667 | TEST_F(VkLayerTest, InvalidStructSType) { |
| 668 | TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan " |
| 669 | "structure's sType field"); |
| 670 | |
| 671 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 672 | |
| 673 | m_errorMonitor->SetDesiredFailureMsg( |
| 674 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 675 | "parameter pAllocateInfo->sType must be"); |
| 676 | // Zero struct memory, effectively setting sType to |
| 677 | // VK_STRUCTURE_TYPE_APPLICATION_INFO |
| 678 | // Expected to trigger an error with |
| 679 | // parameter_validation::validate_struct_type |
| 680 | VkMemoryAllocateInfo alloc_info = {}; |
| 681 | VkDeviceMemory memory = VK_NULL_HANDLE; |
| 682 | vkAllocateMemory(device(), &alloc_info, NULL, &memory); |
| 683 | m_errorMonitor->VerifyFound(); |
| 684 | |
| 685 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 686 | "parameter pSubmits[0].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_array |
| 691 | VkSubmitInfo submit_info = {}; |
| 692 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 693 | m_errorMonitor->VerifyFound(); |
| 694 | } |
| 695 | |
| 696 | TEST_F(VkLayerTest, InvalidStructPNext) { |
| 697 | TEST_DESCRIPTION( |
| 698 | "Specify an invalid value for a Vulkan structure's pNext field"); |
| 699 | |
| 700 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 701 | |
| 702 | m_errorMonitor->SetDesiredFailureMsg( |
| 703 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 704 | "value of pAllocateInfo->pNext must be NULL"); |
| 705 | // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be |
| 706 | // NULL |
| 707 | // Expected to trigger an error with |
| 708 | // parameter_validation::validate_struct_pnext |
| 709 | VkDeviceMemory memory = VK_NULL_HANDLE; |
| 710 | // Zero-initialization will provide the correct sType |
| 711 | VkApplicationInfo app_info = {}; |
Dustin Graves | 47b6cba | 2016-05-10 17:34:38 -0600 | [diff] [blame] | 712 | VkMemoryAllocateInfo memory_alloc_info = {}; |
| 713 | memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 714 | memory_alloc_info.pNext = &app_info; |
| 715 | vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory); |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 716 | m_errorMonitor->VerifyFound(); |
| 717 | |
Dustin Graves | 47b6cba | 2016-05-10 17:34:38 -0600 | [diff] [blame] | 718 | m_errorMonitor->SetDesiredFailureMsg( |
| 719 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 720 | " chain includes a structure with unexpected VkStructureType "); |
| 721 | // Set VkGraphicsPipelineCreateInfo::VkPipelineRasterizationStateCreateInfo::pNext to an invalid structure, when pNext is allowed to be a non-NULL value |
| 722 | // Expected to trigger an error with |
| 723 | // parameter_validation::validate_struct_pnext |
| 724 | VkDescriptorPoolSize ds_type_count = {}; |
| 725 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 726 | ds_type_count.descriptorCount = 1; |
| 727 | |
| 728 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 729 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 730 | ds_pool_ci.pNext = NULL; |
| 731 | ds_pool_ci.maxSets = 1; |
| 732 | ds_pool_ci.poolSizeCount = 1; |
| 733 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 734 | |
| 735 | VkDescriptorPool ds_pool; |
| 736 | VkResult err = |
| 737 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 738 | ASSERT_VK_SUCCESS(err); |
| 739 | |
| 740 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 741 | dsl_binding.binding = 0; |
| 742 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 743 | dsl_binding.descriptorCount = 1; |
| 744 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 745 | dsl_binding.pImmutableSamplers = NULL; |
| 746 | |
| 747 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 748 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 749 | ds_layout_ci.pNext = NULL; |
| 750 | ds_layout_ci.bindingCount = 1; |
| 751 | ds_layout_ci.pBindings = &dsl_binding; |
| 752 | |
| 753 | VkDescriptorSetLayout ds_layout; |
| 754 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 755 | &ds_layout); |
| 756 | ASSERT_VK_SUCCESS(err); |
| 757 | |
| 758 | VkDescriptorSet descriptorSet; |
| 759 | VkDescriptorSetAllocateInfo ds_alloc_info = {}; |
| 760 | ds_alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 761 | ds_alloc_info.descriptorSetCount = 1; |
| 762 | ds_alloc_info.descriptorPool = ds_pool; |
| 763 | ds_alloc_info.pSetLayouts = &ds_layout; |
| 764 | err = vkAllocateDescriptorSets(m_device->device(), &ds_alloc_info, |
| 765 | &descriptorSet); |
| 766 | ASSERT_VK_SUCCESS(err); |
| 767 | |
| 768 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 769 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 770 | pipeline_layout_ci.setLayoutCount = 1; |
| 771 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 772 | |
| 773 | VkPipelineLayout pipeline_layout; |
| 774 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 775 | &pipeline_layout); |
| 776 | ASSERT_VK_SUCCESS(err); |
| 777 | |
| 778 | VkViewport vp = {}; // Just need dummy vp to point to |
| 779 | VkRect2D sc = {}; // dummy scissor to point to |
| 780 | |
| 781 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 782 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 783 | vp_state_ci.scissorCount = 1; |
| 784 | vp_state_ci.pScissors = ≻ |
| 785 | vp_state_ci.viewportCount = 1; |
| 786 | vp_state_ci.pViewports = &vp; |
| 787 | |
| 788 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 789 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 790 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 791 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 792 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 793 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 794 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 795 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 796 | |
| 797 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 798 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 799 | gp_ci.pViewportState = &vp_state_ci; |
| 800 | gp_ci.pRasterizationState = &rs_state_ci; |
| 801 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 802 | gp_ci.layout = pipeline_layout; |
| 803 | gp_ci.renderPass = renderPass(); |
| 804 | |
| 805 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 806 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 807 | pc_ci.initialDataSize = 0; |
| 808 | pc_ci.pInitialData = 0; |
| 809 | |
| 810 | VkPipeline pipeline; |
| 811 | VkPipelineCache pipelineCache; |
| 812 | |
| 813 | err = |
| 814 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 815 | ASSERT_VK_SUCCESS(err); |
| 816 | |
| 817 | // Set VkPipelineRasterizationStateCreateInfo::pNext to an invalid value |
| 818 | VkApplicationInfo invalid_pnext_struct = {}; |
| 819 | rs_state_ci.pNext = &invalid_pnext_struct; |
| 820 | |
| 821 | vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 822 | &gp_ci, NULL, &pipeline); |
| 823 | m_errorMonitor->VerifyFound(); |
Dustin Graves | c99cf5a | 2016-05-09 14:40:29 -0600 | [diff] [blame] | 824 | } |
Dustin Graves | 5d33d53 | 2016-05-09 16:21:12 -0600 | [diff] [blame] | 825 | |
| 826 | TEST_F(VkLayerTest, UnrecognizedValue) { |
| 827 | TEST_DESCRIPTION( |
| 828 | "Specify unrecognized Vulkan enumeration, flags, and VkBool32 values"); |
| 829 | |
| 830 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 831 | |
| 832 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 833 | "does not fall within the begin..end " |
| 834 | "range of the core VkFormat " |
| 835 | "enumeration tokens"); |
| 836 | // Specify an invalid VkFormat value |
| 837 | // Expected to trigger an error with |
| 838 | // parameter_validation::validate_ranged_enum |
| 839 | VkFormatProperties format_properties; |
| 840 | vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), |
| 841 | &format_properties); |
| 842 | m_errorMonitor->VerifyFound(); |
| 843 | |
| 844 | m_errorMonitor->SetDesiredFailureMsg( |
| 845 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 846 | "contains flag bits that are not recognized members of"); |
| 847 | // Specify an invalid VkFlags bitmask value |
| 848 | // Expected to trigger an error with parameter_validation::validate_flags |
| 849 | VkImageFormatProperties image_format_properties; |
| 850 | vkGetPhysicalDeviceImageFormatProperties( |
| 851 | gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, |
| 852 | VK_IMAGE_TILING_OPTIMAL, static_cast<VkImageUsageFlags>(1 << 25), 0, |
| 853 | &image_format_properties); |
| 854 | m_errorMonitor->VerifyFound(); |
| 855 | |
| 856 | m_errorMonitor->SetDesiredFailureMsg( |
| 857 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 858 | "contains flag bits that are not recognized members of"); |
| 859 | // Specify an invalid VkFlags array entry |
| 860 | // Expected to trigger an error with |
| 861 | // parameter_validation::validate_flags_array |
| 862 | VkSemaphore semaphore = VK_NULL_HANDLE; |
| 863 | VkPipelineStageFlags stage_flags = |
| 864 | static_cast<VkPipelineStageFlags>(1 << 25); |
| 865 | VkSubmitInfo submit_info = {}; |
| 866 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 867 | submit_info.waitSemaphoreCount = 1; |
| 868 | submit_info.pWaitSemaphores = &semaphore; |
| 869 | submit_info.pWaitDstStageMask = &stage_flags; |
| 870 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 871 | m_errorMonitor->VerifyFound(); |
| 872 | |
| 873 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
| 874 | "is neither VK_TRUE nor VK_FALSE"); |
| 875 | // Specify an invalid VkBool32 value |
| 876 | // Expected to trigger a warning with |
| 877 | // parameter_validation::validate_bool32 |
| 878 | VkSampler sampler = VK_NULL_HANDLE; |
| 879 | VkSamplerCreateInfo sampler_info = {}; |
| 880 | sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 881 | sampler_info.pNext = NULL; |
| 882 | sampler_info.magFilter = VK_FILTER_NEAREST; |
| 883 | sampler_info.minFilter = VK_FILTER_NEAREST; |
| 884 | sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 885 | sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 886 | sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 887 | sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 888 | sampler_info.mipLodBias = 1.0; |
| 889 | sampler_info.maxAnisotropy = 1; |
| 890 | sampler_info.compareEnable = VK_FALSE; |
| 891 | sampler_info.compareOp = VK_COMPARE_OP_NEVER; |
| 892 | sampler_info.minLod = 1.0; |
| 893 | sampler_info.maxLod = 1.0; |
| 894 | sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 895 | sampler_info.unnormalizedCoordinates = VK_FALSE; |
| 896 | // Not VK_TRUE or VK_FALSE |
| 897 | sampler_info.anisotropyEnable = 3; |
| 898 | vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler); |
| 899 | m_errorMonitor->VerifyFound(); |
| 900 | } |
Dustin Graves | fce74c0 | 2016-05-10 11:42:58 -0600 | [diff] [blame] | 901 | |
| 902 | TEST_F(VkLayerTest, FailedReturnValue) { |
| 903 | TEST_DESCRIPTION("Check for a message describing a VkResult failure code"); |
| 904 | |
| 905 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 906 | |
Dustin Graves | 13c1e2b | 2016-05-16 15:31:02 -0600 | [diff] [blame] | 907 | // Find an unsupported image format |
| 908 | VkFormat unsupported = VK_FORMAT_UNDEFINED; |
| 909 | for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) { |
| 910 | VkFormat format = static_cast<VkFormat>(f); |
| 911 | VkFormatProperties fProps = m_device->format_properties(format); |
| 912 | if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && |
| 913 | fProps.optimalTilingFeatures == 0) { |
| 914 | unsupported = format; |
| 915 | break; |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | if (unsupported != VK_FORMAT_UNDEFINED) { |
| 920 | m_errorMonitor->SetDesiredFailureMsg( |
| 921 | VK_DEBUG_REPORT_WARNING_BIT_EXT, |
| 922 | "the requested format is not supported on this device"); |
| 923 | // Specify an unsupported VkFormat value to generate a |
| 924 | // VK_ERROR_FORMAT_NOT_SUPPORTED return code |
| 925 | // Expected to trigger a warning from |
| 926 | // parameter_validation::validate_result |
| 927 | VkImageFormatProperties image_format_properties; |
| 928 | VkResult err = vkGetPhysicalDeviceImageFormatProperties( |
| 929 | gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL, |
| 930 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties); |
| 931 | ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED); |
| 932 | m_errorMonitor->VerifyFound(); |
| 933 | } |
Dustin Graves | fce74c0 | 2016-05-10 11:42:58 -0600 | [diff] [blame] | 934 | } |
Dustin Graves | ffa90fa | 2016-05-06 11:20:38 -0600 | [diff] [blame] | 935 | #endif // PARAMETER_VALIDATION_TESTS |
| 936 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 937 | #if MEM_TRACKER_TESTS |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 938 | #if 0 |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 939 | TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion) |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 940 | { |
| 941 | vk_testing::Fence testFence; |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 942 | VkFenceCreateInfo fenceInfo = {}; |
| 943 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 944 | fenceInfo.pNext = NULL; |
| 945 | fenceInfo.flags = 0; |
| 946 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 947 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting CB"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 948 | |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 949 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tony Barbour | c1eb1a5 | 2015-07-20 13:00:10 -0600 | [diff] [blame] | 950 | |
| 951 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 952 | vk_testing::Buffer buffer; |
| 953 | buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 954 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 955 | BeginCommandBuffer(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 956 | m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 957 | EndCommandBuffer(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 958 | |
| 959 | testFence.init(*m_device, fenceInfo); |
| 960 | |
| 961 | // Bypass framework since it does the waits automatically |
| 962 | VkResult err = VK_SUCCESS; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 963 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 964 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 965 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 966 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 967 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 968 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 969 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 970 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 971 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 972 | submit_info.pSignalSemaphores = NULL; |
Courtney Goeltzenleuchter | 646b907 | 2015-10-20 18:04:07 -0600 | [diff] [blame] | 973 | |
| 974 | err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle()); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 975 | ASSERT_VK_SUCCESS( err ); |
| 976 | |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 977 | // Introduce failure by calling begin again before checking fence |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 978 | vkResetCommandBuffer(m_commandBuffer->handle(), 0); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 979 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 980 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 981 | } |
| 982 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 983 | TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion) |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 984 | { |
| 985 | vk_testing::Fence testFence; |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 986 | VkFenceCreateInfo fenceInfo = {}; |
| 987 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 988 | fenceInfo.pNext = NULL; |
| 989 | fenceInfo.flags = 0; |
| 990 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 991 | 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] | 992 | |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 993 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 994 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 995 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 996 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 997 | BeginCommandBuffer(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 998 | 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] | 999 | EndCommandBuffer(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1000 | |
| 1001 | testFence.init(*m_device, fenceInfo); |
| 1002 | |
| 1003 | // Bypass framework since it does the waits automatically |
| 1004 | VkResult err = VK_SUCCESS; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1005 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 1006 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 1007 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1008 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1009 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 1010 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1011 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1012 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1013 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 1014 | submit_info.pSignalSemaphores = NULL; |
Courtney Goeltzenleuchter | 646b907 | 2015-10-20 18:04:07 -0600 | [diff] [blame] | 1015 | |
| 1016 | err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle()); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1017 | ASSERT_VK_SUCCESS( err ); |
| 1018 | |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 1019 | VkCommandBufferInheritanceInfo hinfo = {}; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1020 | VkCommandBufferBeginInfo info = {}; |
| 1021 | info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
| 1022 | info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 1023 | info.renderPass = VK_NULL_HANDLE; |
| 1024 | info.subpass = 0; |
| 1025 | info.framebuffer = VK_NULL_HANDLE; |
Chia-I Wu | b8d47ae | 2015-11-11 10:18:12 +0800 | [diff] [blame] | 1026 | info.occlusionQueryEnable = VK_FALSE; |
| 1027 | info.queryFlags = 0; |
| 1028 | info.pipelineStatistics = 0; |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 1029 | |
| 1030 | // Introduce failure by calling BCB again before checking fence |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1031 | vkBeginCommandBuffer(m_commandBuffer->handle(), &info); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1032 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 1033 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | ccb2b04 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 1034 | } |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 1035 | #endif |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 1036 | |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1037 | // This is a positive test. No failures are expected. |
| 1038 | TEST_F(VkLayerTest, TestAliasedMemoryTracking) { |
| 1039 | VkResult err; |
| 1040 | bool pass; |
| 1041 | |
| 1042 | TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy " |
| 1043 | "the buffer, create an image, and bind the same memory to " |
| 1044 | "it"); |
| 1045 | |
| 1046 | m_errorMonitor->ExpectSuccess(); |
| 1047 | |
| 1048 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1049 | |
| 1050 | VkBuffer buffer; |
| 1051 | VkImage image; |
| 1052 | VkDeviceMemory mem; |
| 1053 | VkMemoryRequirements mem_reqs; |
| 1054 | |
| 1055 | VkBufferCreateInfo buf_info = {}; |
| 1056 | buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1057 | buf_info.pNext = NULL; |
| 1058 | buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 1059 | buf_info.size = 256; |
| 1060 | buf_info.queueFamilyIndexCount = 0; |
| 1061 | buf_info.pQueueFamilyIndices = NULL; |
| 1062 | buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1063 | buf_info.flags = 0; |
| 1064 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer); |
| 1065 | ASSERT_VK_SUCCESS(err); |
| 1066 | |
| 1067 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs); |
| 1068 | |
| 1069 | VkMemoryAllocateInfo alloc_info = {}; |
| 1070 | alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1071 | alloc_info.pNext = NULL; |
| 1072 | alloc_info.memoryTypeIndex = 0; |
| 1073 | |
| 1074 | // Ensure memory is big enough for both bindings |
| 1075 | alloc_info.allocationSize = 0x10000; |
| 1076 | |
| 1077 | pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, |
| 1078 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 1079 | if (!pass) { |
| 1080 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1081 | return; |
| 1082 | } |
| 1083 | |
| 1084 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem); |
| 1085 | ASSERT_VK_SUCCESS(err); |
| 1086 | |
| 1087 | uint8_t *pData; |
| 1088 | err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, |
| 1089 | (void **)&pData); |
| 1090 | ASSERT_VK_SUCCESS(err); |
| 1091 | |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 1092 | memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size)); |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1093 | |
| 1094 | vkUnmapMemory(m_device->device(), mem); |
| 1095 | |
| 1096 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 1097 | ASSERT_VK_SUCCESS(err); |
| 1098 | |
| 1099 | // NOW, destroy the buffer. Obviously, the resource no longer occupies this |
| 1100 | // memory. In fact, it was never used by the GPU. |
| 1101 | // Just be be sure, wait for idle. |
| 1102 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1103 | vkDeviceWaitIdle(m_device->device()); |
| 1104 | |
| 1105 | VkImageCreateInfo image_create_info = {}; |
| 1106 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 1107 | image_create_info.pNext = NULL; |
| 1108 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 1109 | image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 1110 | image_create_info.extent.width = 64; |
| 1111 | image_create_info.extent.height = 64; |
| 1112 | image_create_info.extent.depth = 1; |
| 1113 | image_create_info.mipLevels = 1; |
| 1114 | image_create_info.arrayLayers = 1; |
| 1115 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 1116 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 1117 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 1118 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 1119 | image_create_info.queueFamilyIndexCount = 0; |
| 1120 | image_create_info.pQueueFamilyIndices = NULL; |
| 1121 | image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1122 | image_create_info.flags = 0; |
| 1123 | |
| 1124 | VkMemoryAllocateInfo mem_alloc = {}; |
| 1125 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1126 | mem_alloc.pNext = NULL; |
| 1127 | mem_alloc.allocationSize = 0; |
| 1128 | mem_alloc.memoryTypeIndex = 0; |
| 1129 | |
| 1130 | /* Create a mappable image. It will be the texture if linear images are ok |
| 1131 | * to be textures or it will be the staging image if they are not. |
| 1132 | */ |
| 1133 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 1134 | ASSERT_VK_SUCCESS(err); |
| 1135 | |
| 1136 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 1137 | |
| 1138 | mem_alloc.allocationSize = mem_reqs.size; |
| 1139 | |
| 1140 | pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, |
| 1141 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 1142 | if (!pass) { |
| 1143 | vkDestroyImage(m_device->device(), image, NULL); |
| 1144 | return; |
| 1145 | } |
| 1146 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1147 | // VALIDATION FAILURE: |
Mark Lobodzinski | 152fe25 | 2016-05-03 16:49:15 -0600 | [diff] [blame] | 1148 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 1149 | ASSERT_VK_SUCCESS(err); |
| 1150 | |
| 1151 | m_errorMonitor->VerifyNotFound(); |
| 1152 | |
| 1153 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1154 | vkDestroyImage(m_device->device(), image, NULL); |
| 1155 | } |
| 1156 | |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1157 | TEST_F(VkLayerTest, InvalidMemoryAliasing) { |
| 1158 | TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the " |
| 1159 | "buffer and image to memory such that they will alias."); |
| 1160 | VkResult err; |
| 1161 | bool pass; |
| 1162 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1163 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1164 | VkBuffer buffer, buffer2; |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1165 | VkImage image; |
| 1166 | VkDeviceMemory mem; // buffer will be bound first |
| 1167 | VkDeviceMemory mem_img; // image bound first |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1168 | VkMemoryRequirements buff_mem_reqs, img_mem_reqs; |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1169 | |
| 1170 | VkBufferCreateInfo buf_info = {}; |
| 1171 | buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1172 | buf_info.pNext = NULL; |
| 1173 | buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 1174 | buf_info.size = 256; |
| 1175 | buf_info.queueFamilyIndexCount = 0; |
| 1176 | buf_info.pQueueFamilyIndices = NULL; |
| 1177 | buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1178 | buf_info.flags = 0; |
| 1179 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer); |
| 1180 | ASSERT_VK_SUCCESS(err); |
| 1181 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1182 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1183 | |
| 1184 | VkImageCreateInfo image_create_info = {}; |
| 1185 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 1186 | image_create_info.pNext = NULL; |
| 1187 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 1188 | image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 1189 | image_create_info.extent.width = 64; |
| 1190 | image_create_info.extent.height = 64; |
| 1191 | image_create_info.extent.depth = 1; |
| 1192 | image_create_info.mipLevels = 1; |
| 1193 | image_create_info.arrayLayers = 1; |
| 1194 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 1195 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 1196 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 1197 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 1198 | image_create_info.queueFamilyIndexCount = 0; |
| 1199 | image_create_info.pQueueFamilyIndices = NULL; |
| 1200 | image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1201 | image_create_info.flags = 0; |
| 1202 | |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1203 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 1204 | ASSERT_VK_SUCCESS(err); |
| 1205 | |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1206 | vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs); |
| 1207 | |
| 1208 | VkMemoryAllocateInfo alloc_info = {}; |
| 1209 | alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1210 | alloc_info.pNext = NULL; |
| 1211 | alloc_info.memoryTypeIndex = 0; |
| 1212 | // Ensure memory is big enough for both bindings |
| 1213 | alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size; |
| 1214 | pass = m_device->phy().set_memory_type( |
| 1215 | buff_mem_reqs.memoryTypeBits | img_mem_reqs.memoryTypeBits, &alloc_info, |
| 1216 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1217 | if (!pass) { |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1218 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1219 | vkDestroyImage(m_device->device(), image, NULL); |
| 1220 | return; |
| 1221 | } |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1222 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem); |
| 1223 | ASSERT_VK_SUCCESS(err); |
| 1224 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 1225 | ASSERT_VK_SUCCESS(err); |
| 1226 | |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1227 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1228 | " is aliased with buffer 0x"); |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1229 | // VALIDATION FAILURE due to image mapping overlapping buffer mapping |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1230 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 1231 | m_errorMonitor->VerifyFound(); |
| 1232 | |
| 1233 | // Now correctly bind image to second mem allocation before incorrectly |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1234 | // aliasing buffer2 |
| 1235 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2); |
| 1236 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1237 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img); |
| 1238 | ASSERT_VK_SUCCESS(err); |
| 1239 | err = vkBindImageMemory(m_device->device(), image, mem_img, 0); |
| 1240 | ASSERT_VK_SUCCESS(err); |
| 1241 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1242 | " is aliased with image 0x"); |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1243 | err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1244 | m_errorMonitor->VerifyFound(); |
| 1245 | |
| 1246 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
Tobin Ehlis | 077ded3 | 2016-05-12 17:39:13 -0600 | [diff] [blame] | 1247 | vkDestroyBuffer(m_device->device(), buffer2, NULL); |
Tobin Ehlis | f11be98 | 2016-05-11 13:52:53 -0600 | [diff] [blame] | 1248 | vkDestroyImage(m_device->device(), image, NULL); |
| 1249 | vkFreeMemory(m_device->device(), mem, NULL); |
| 1250 | vkFreeMemory(m_device->device(), mem_img, NULL); |
| 1251 | } |
| 1252 | |
Tobin Ehlis | 3537252 | 2016-05-12 08:32:31 -0600 | [diff] [blame] | 1253 | TEST_F(VkLayerTest, InvalidMemoryMapping) { |
| 1254 | TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways"); |
| 1255 | VkResult err; |
| 1256 | bool pass; |
| 1257 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1258 | |
| 1259 | VkBuffer buffer; |
| 1260 | VkDeviceMemory mem; |
| 1261 | VkMemoryRequirements mem_reqs; |
| 1262 | |
| 1263 | VkBufferCreateInfo buf_info = {}; |
| 1264 | buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1265 | buf_info.pNext = NULL; |
| 1266 | buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 1267 | buf_info.size = 256; |
| 1268 | buf_info.queueFamilyIndexCount = 0; |
| 1269 | buf_info.pQueueFamilyIndices = NULL; |
| 1270 | buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1271 | buf_info.flags = 0; |
| 1272 | err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer); |
| 1273 | ASSERT_VK_SUCCESS(err); |
| 1274 | |
| 1275 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs); |
| 1276 | VkMemoryAllocateInfo alloc_info = {}; |
| 1277 | alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 1278 | alloc_info.pNext = NULL; |
| 1279 | alloc_info.memoryTypeIndex = 0; |
| 1280 | |
| 1281 | // Ensure memory is big enough for both bindings |
| 1282 | static const VkDeviceSize allocation_size = 0x10000; |
| 1283 | alloc_info.allocationSize = allocation_size; |
| 1284 | pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, |
| 1285 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 1286 | if (!pass) { |
| 1287 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1288 | return; |
| 1289 | } |
| 1290 | err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem); |
| 1291 | ASSERT_VK_SUCCESS(err); |
| 1292 | |
| 1293 | uint8_t *pData; |
| 1294 | // Attempt to map memory size 0 is invalid |
| 1295 | m_errorMonitor->SetDesiredFailureMsg( |
| 1296 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1297 | "VkMapMemory: Attempting to map memory range of size zero"); |
| 1298 | err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData); |
| 1299 | m_errorMonitor->VerifyFound(); |
| 1300 | // Map memory twice |
| 1301 | err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, |
| 1302 | (void **)&pData); |
| 1303 | ASSERT_VK_SUCCESS(err); |
| 1304 | m_errorMonitor->SetDesiredFailureMsg( |
| 1305 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1306 | "VkMapMemory: Attempting to map memory on an already-mapped object "); |
| 1307 | err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, |
| 1308 | (void **)&pData); |
| 1309 | m_errorMonitor->VerifyFound(); |
| 1310 | |
| 1311 | // Unmap the memory to avoid re-map error |
| 1312 | vkUnmapMemory(m_device->device(), mem); |
| 1313 | // overstep allocation with VK_WHOLE_SIZE |
| 1314 | m_errorMonitor->SetDesiredFailureMsg( |
| 1315 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1316 | " with size of VK_WHOLE_SIZE oversteps total array size 0x"); |
| 1317 | err = vkMapMemory(m_device->device(), mem, allocation_size + 1, |
| 1318 | VK_WHOLE_SIZE, 0, (void **)&pData); |
| 1319 | m_errorMonitor->VerifyFound(); |
| 1320 | // overstep allocation w/o VK_WHOLE_SIZE |
| 1321 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1322 | " oversteps total array size 0x"); |
| 1323 | err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, |
| 1324 | (void **)&pData); |
| 1325 | m_errorMonitor->VerifyFound(); |
| 1326 | // Now error due to unmapping memory that's not mapped |
| 1327 | m_errorMonitor->SetDesiredFailureMsg( |
| 1328 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1329 | "Unmapping Memory without memory being mapped: "); |
| 1330 | vkUnmapMemory(m_device->device(), mem); |
| 1331 | m_errorMonitor->VerifyFound(); |
| 1332 | // Now map memory and cause errors due to flushing invalid ranges |
| 1333 | err = vkMapMemory(m_device->device(), mem, 16, VK_WHOLE_SIZE, 0, |
| 1334 | (void **)&pData); |
| 1335 | ASSERT_VK_SUCCESS(err); |
| 1336 | VkMappedMemoryRange mmr = {}; |
| 1337 | mmr.memory = mem; |
| 1338 | mmr.offset = 15; // Error b/c offset less than offset of mapped mem |
| 1339 | m_errorMonitor->SetDesiredFailureMsg( |
| 1340 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1341 | ") is less than Memory Object's offset ("); |
| 1342 | vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr); |
| 1343 | m_errorMonitor->VerifyFound(); |
| 1344 | // Now flush range that oversteps mapped range |
| 1345 | vkUnmapMemory(m_device->device(), mem); |
| 1346 | err = vkMapMemory(m_device->device(), mem, 0, 256, 0, (void **)&pData); |
| 1347 | ASSERT_VK_SUCCESS(err); |
| 1348 | mmr.offset = 16; |
| 1349 | mmr.size = 256; // flushing bounds (272) exceed mapped bounds (256) |
| 1350 | m_errorMonitor->SetDesiredFailureMsg( |
| 1351 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1352 | ") exceeds the Memory Object's upper-bound ("); |
| 1353 | vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr); |
| 1354 | m_errorMonitor->VerifyFound(); |
| 1355 | |
| 1356 | pass = |
| 1357 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, |
| 1358 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, |
| 1359 | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); |
| 1360 | if (!pass) { |
| 1361 | vkFreeMemory(m_device->device(), mem, NULL); |
| 1362 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1363 | return; |
| 1364 | } |
| 1365 | // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of |
| 1366 | // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver() |
| 1367 | |
| 1368 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 1369 | vkFreeMemory(m_device->device(), mem, NULL); |
| 1370 | } |
| 1371 | |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1372 | TEST_F(VkLayerTest, EnableWsiBeforeUse) { |
| 1373 | VkResult err; |
| 1374 | bool pass; |
| 1375 | |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1376 | // FIXME: After we turn on this code for non-Linux platforms, uncomment the |
| 1377 | // following declaration (which is temporarily being moved below): |
| 1378 | // VkSurfaceKHR surface = VK_NULL_HANDLE; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1379 | VkSwapchainKHR swapchain = VK_NULL_HANDLE; |
| 1380 | VkSwapchainCreateInfoKHR swapchain_create_info = {}; |
| 1381 | uint32_t swapchain_image_count = 0; |
| 1382 | // VkImage swapchain_images[1] = {VK_NULL_HANDLE}; |
| 1383 | uint32_t image_index = 0; |
| 1384 | // VkPresentInfoKHR present_info = {}; |
| 1385 | |
| 1386 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1387 | |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1388 | #ifdef NEED_TO_TEST_THIS_ON_PLATFORM |
| 1389 | #if defined(VK_USE_PLATFORM_ANDROID_KHR) |
| 1390 | // Use the functions from the VK_KHR_android_surface extension without |
| 1391 | // enabling that extension: |
| 1392 | |
| 1393 | // Create a surface: |
| 1394 | VkAndroidSurfaceCreateInfoKHR android_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1395 | m_errorMonitor->SetDesiredFailureMsg( |
| 1396 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1397 | "extension was not enabled for this"); |
| 1398 | err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, |
| 1399 | &surface); |
| 1400 | pass = (err != VK_SUCCESS); |
| 1401 | ASSERT_TRUE(pass); |
| 1402 | m_errorMonitor->VerifyFound(); |
| 1403 | #endif // VK_USE_PLATFORM_ANDROID_KHR |
| 1404 | |
| 1405 | |
| 1406 | #if defined(VK_USE_PLATFORM_MIR_KHR) |
| 1407 | // Use the functions from the VK_KHR_mir_surface extension without enabling |
| 1408 | // that extension: |
| 1409 | |
| 1410 | // Create a surface: |
| 1411 | VkMirSurfaceCreateInfoKHR mir_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1412 | m_errorMonitor->SetDesiredFailureMsg( |
| 1413 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1414 | "extension was not enabled for this"); |
| 1415 | err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface); |
| 1416 | pass = (err != VK_SUCCESS); |
| 1417 | ASSERT_TRUE(pass); |
| 1418 | m_errorMonitor->VerifyFound(); |
| 1419 | |
| 1420 | // Tell whether an mir_connection supports presentation: |
| 1421 | MirConnection *mir_connection = NULL; |
| 1422 | m_errorMonitor->SetDesiredFailureMsg( |
| 1423 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1424 | "extension was not enabled for this"); |
| 1425 | vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, |
| 1426 | visual_id); |
| 1427 | m_errorMonitor->VerifyFound(); |
| 1428 | #endif // VK_USE_PLATFORM_MIR_KHR |
| 1429 | |
| 1430 | |
| 1431 | #if defined(VK_USE_PLATFORM_WAYLAND_KHR) |
| 1432 | // Use the functions from the VK_KHR_wayland_surface extension without |
| 1433 | // enabling that extension: |
| 1434 | |
| 1435 | // Create a surface: |
| 1436 | VkWaylandSurfaceCreateInfoKHR wayland_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1437 | m_errorMonitor->SetDesiredFailureMsg( |
| 1438 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1439 | "extension was not enabled for this"); |
| 1440 | err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, |
| 1441 | &surface); |
| 1442 | pass = (err != VK_SUCCESS); |
| 1443 | ASSERT_TRUE(pass); |
| 1444 | m_errorMonitor->VerifyFound(); |
| 1445 | |
| 1446 | // Tell whether an wayland_display supports presentation: |
| 1447 | struct wl_display wayland_display = {}; |
| 1448 | m_errorMonitor->SetDesiredFailureMsg( |
| 1449 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1450 | "extension was not enabled for this"); |
| 1451 | vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, |
| 1452 | &wayland_display); |
| 1453 | m_errorMonitor->VerifyFound(); |
| 1454 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1455 | #endif // NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1456 | |
| 1457 | |
| 1458 | #if defined(VK_USE_PLATFORM_WIN32_KHR) |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1459 | // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED |
| 1460 | // TO NON-LINUX PLATFORMS: |
| 1461 | VkSurfaceKHR surface = VK_NULL_HANDLE; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1462 | // Use the functions from the VK_KHR_win32_surface extension without |
| 1463 | // enabling that extension: |
| 1464 | |
| 1465 | // Create a surface: |
| 1466 | VkWin32SurfaceCreateInfoKHR win32_create_info = {}; |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1467 | m_errorMonitor->SetDesiredFailureMsg( |
| 1468 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1469 | "extension was not enabled for this"); |
| 1470 | err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, |
| 1471 | &surface); |
| 1472 | pass = (err != VK_SUCCESS); |
| 1473 | ASSERT_TRUE(pass); |
| 1474 | m_errorMonitor->VerifyFound(); |
| 1475 | |
| 1476 | // Tell whether win32 supports presentation: |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1477 | m_errorMonitor->SetDesiredFailureMsg( |
| 1478 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1479 | "extension was not enabled for this"); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1480 | vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0); |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1481 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1482 | // Set this (for now, until all platforms are supported and tested): |
| 1483 | #define NEED_TO_TEST_THIS_ON_PLATFORM |
| 1484 | #endif // VK_USE_PLATFORM_WIN32_KHR |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1485 | |
| 1486 | |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1487 | #if defined(VK_USE_PLATFORM_XCB_KHR) |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1488 | // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED |
| 1489 | // TO NON-LINUX PLATFORMS: |
| 1490 | VkSurfaceKHR surface = VK_NULL_HANDLE; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1491 | // Use the functions from the VK_KHR_xcb_surface extension without enabling |
| 1492 | // that extension: |
| 1493 | |
| 1494 | // Create a surface: |
| 1495 | VkXcbSurfaceCreateInfoKHR xcb_create_info = {}; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1496 | m_errorMonitor->SetDesiredFailureMsg( |
| 1497 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1498 | "extension was not enabled for this"); |
| 1499 | err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface); |
| 1500 | pass = (err != VK_SUCCESS); |
| 1501 | ASSERT_TRUE(pass); |
| 1502 | m_errorMonitor->VerifyFound(); |
| 1503 | |
| 1504 | // Tell whether an xcb_visualid_t supports presentation: |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1505 | xcb_connection_t *xcb_connection = NULL; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1506 | xcb_visualid_t visual_id = 0; |
| 1507 | m_errorMonitor->SetDesiredFailureMsg( |
| 1508 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1509 | "extension was not enabled for this"); |
Ian Elliott | 3f06ce5 | 2016-04-29 14:46:21 -0600 | [diff] [blame] | 1510 | vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1511 | visual_id); |
| 1512 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1513 | // Set this (for now, until all platforms are supported and tested): |
| 1514 | #define NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1515 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 1516 | |
| 1517 | |
Ian Elliott | 1263081 | 2016-04-29 14:35:43 -0600 | [diff] [blame] | 1518 | #if defined(VK_USE_PLATFORM_XLIB_KHR) |
| 1519 | // Use the functions from the VK_KHR_xlib_surface extension without enabling |
| 1520 | // that extension: |
| 1521 | |
| 1522 | // Create a surface: |
| 1523 | VkXlibSurfaceCreateInfoKHR xlib_create_info = {}; |
Ian Elliott | 1263081 | 2016-04-29 14:35:43 -0600 | [diff] [blame] | 1524 | m_errorMonitor->SetDesiredFailureMsg( |
| 1525 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1526 | "extension was not enabled for this"); |
| 1527 | err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface); |
| 1528 | pass = (err != VK_SUCCESS); |
| 1529 | ASSERT_TRUE(pass); |
| 1530 | m_errorMonitor->VerifyFound(); |
| 1531 | |
| 1532 | // Tell whether an Xlib VisualID supports presentation: |
| 1533 | Display *dpy = NULL; |
| 1534 | VisualID visual = 0; |
| 1535 | m_errorMonitor->SetDesiredFailureMsg( |
| 1536 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1537 | "extension was not enabled for this"); |
| 1538 | vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual); |
| 1539 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1540 | // Set this (for now, until all platforms are supported and tested): |
| 1541 | #define NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1263081 | 2016-04-29 14:35:43 -0600 | [diff] [blame] | 1542 | #endif // VK_USE_PLATFORM_XLIB_KHR |
| 1543 | |
| 1544 | |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1545 | // Use the functions from the VK_KHR_surface extension without enabling |
| 1546 | // that extension: |
| 1547 | |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1548 | #ifdef NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1549 | // Destroy a surface: |
| 1550 | m_errorMonitor->SetDesiredFailureMsg( |
| 1551 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1552 | "extension was not enabled for this"); |
| 1553 | vkDestroySurfaceKHR(instance(), surface, NULL); |
| 1554 | m_errorMonitor->VerifyFound(); |
| 1555 | |
| 1556 | // Check if surface supports presentation: |
| 1557 | VkBool32 supported = false; |
| 1558 | m_errorMonitor->SetDesiredFailureMsg( |
| 1559 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1560 | "extension was not enabled for this"); |
| 1561 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported); |
| 1562 | pass = (err != VK_SUCCESS); |
| 1563 | ASSERT_TRUE(pass); |
| 1564 | m_errorMonitor->VerifyFound(); |
| 1565 | |
| 1566 | // Check surface capabilities: |
| 1567 | VkSurfaceCapabilitiesKHR capabilities = {}; |
| 1568 | m_errorMonitor->SetDesiredFailureMsg( |
| 1569 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1570 | "extension was not enabled for this"); |
| 1571 | err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, |
| 1572 | &capabilities); |
| 1573 | pass = (err != VK_SUCCESS); |
| 1574 | ASSERT_TRUE(pass); |
| 1575 | m_errorMonitor->VerifyFound(); |
| 1576 | |
| 1577 | // Check surface formats: |
| 1578 | uint32_t format_count = 0; |
| 1579 | VkSurfaceFormatKHR *formats = NULL; |
| 1580 | m_errorMonitor->SetDesiredFailureMsg( |
| 1581 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1582 | "extension was not enabled for this"); |
| 1583 | err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, |
| 1584 | &format_count, formats); |
| 1585 | pass = (err != VK_SUCCESS); |
| 1586 | ASSERT_TRUE(pass); |
| 1587 | m_errorMonitor->VerifyFound(); |
| 1588 | |
| 1589 | // Check surface present modes: |
| 1590 | uint32_t present_mode_count = 0; |
| 1591 | VkSurfaceFormatKHR *present_modes = NULL; |
| 1592 | m_errorMonitor->SetDesiredFailureMsg( |
| 1593 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1594 | "extension was not enabled for this"); |
| 1595 | err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, |
| 1596 | &present_mode_count, present_modes); |
| 1597 | pass = (err != VK_SUCCESS); |
| 1598 | ASSERT_TRUE(pass); |
| 1599 | m_errorMonitor->VerifyFound(); |
Ian Elliott | 489eec0 | 2016-05-05 14:12:44 -0600 | [diff] [blame] | 1600 | #endif // NEED_TO_TEST_THIS_ON_PLATFORM |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1601 | |
| 1602 | |
| 1603 | // Use the functions from the VK_KHR_swapchain extension without enabling |
| 1604 | // that extension: |
| 1605 | |
| 1606 | // Create a swapchain: |
| 1607 | m_errorMonitor->SetDesiredFailureMsg( |
| 1608 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1609 | "extension was not enabled for this"); |
| 1610 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 1611 | swapchain_create_info.pNext = NULL; |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1612 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, |
| 1613 | NULL, &swapchain); |
| 1614 | pass = (err != VK_SUCCESS); |
| 1615 | ASSERT_TRUE(pass); |
| 1616 | m_errorMonitor->VerifyFound(); |
| 1617 | |
| 1618 | // Get the images from the swapchain: |
| 1619 | m_errorMonitor->SetDesiredFailureMsg( |
| 1620 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1621 | "extension was not enabled for this"); |
| 1622 | err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, |
| 1623 | &swapchain_image_count, NULL); |
| 1624 | pass = (err != VK_SUCCESS); |
| 1625 | ASSERT_TRUE(pass); |
| 1626 | m_errorMonitor->VerifyFound(); |
| 1627 | |
| 1628 | // Try to acquire an image: |
| 1629 | m_errorMonitor->SetDesiredFailureMsg( |
| 1630 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1631 | "extension was not enabled for this"); |
| 1632 | err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, |
| 1633 | VK_NULL_HANDLE, VK_NULL_HANDLE, &image_index); |
| 1634 | pass = (err != VK_SUCCESS); |
| 1635 | ASSERT_TRUE(pass); |
| 1636 | m_errorMonitor->VerifyFound(); |
| 1637 | |
| 1638 | // Try to present an image: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1639 | // |
| 1640 | // NOTE: Currently can't test this because a real swapchain is needed (as |
| 1641 | // opposed to the fake one we created) in order for the layer to lookup the |
| 1642 | // VkDevice used to enable the extension: |
Ian Elliott | 1c32c77 | 2016-04-28 14:47:13 -0600 | [diff] [blame] | 1643 | |
| 1644 | // Destroy the swapchain: |
| 1645 | m_errorMonitor->SetDesiredFailureMsg( |
| 1646 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1647 | "extension was not enabled for this"); |
| 1648 | vkDestroySwapchainKHR(m_device->device(), swapchain, NULL); |
| 1649 | m_errorMonitor->VerifyFound(); |
| 1650 | } |
| 1651 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1652 | TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) { |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1653 | |
Dustin Graves | 6c6d898 | 2016-05-17 10:09:21 -0600 | [diff] [blame] | 1654 | #if defined(VK_USE_PLATFORM_XCB_KHR) |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1655 | VkSurfaceKHR surface = VK_NULL_HANDLE; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1656 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1657 | VkResult err; |
| 1658 | bool pass; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1659 | VkSwapchainKHR swapchain = VK_NULL_HANDLE; |
| 1660 | VkSwapchainCreateInfoKHR swapchain_create_info = {}; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1661 | // uint32_t swapchain_image_count = 0; |
| 1662 | // VkImage swapchain_images[1] = {VK_NULL_HANDLE}; |
| 1663 | // uint32_t image_index = 0; |
| 1664 | // VkPresentInfoKHR present_info = {}; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1665 | |
| 1666 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1667 | |
| 1668 | // Use the create function from one of the VK_KHR_*_surface extension in |
| 1669 | // order to create a surface, testing all known errors in the process, |
| 1670 | // before successfully creating a surface: |
| 1671 | // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1672 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1673 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1674 | err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface); |
| 1675 | pass = (err != VK_SUCCESS); |
| 1676 | ASSERT_TRUE(pass); |
| 1677 | m_errorMonitor->VerifyFound(); |
| 1678 | |
| 1679 | // Next, try to create a surface with the wrong |
| 1680 | // VkXcbSurfaceCreateInfoKHR::sType: |
| 1681 | VkXcbSurfaceCreateInfoKHR xcb_create_info = {}; |
| 1682 | xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1683 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1684 | "called with the wrong value for"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1685 | err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface); |
| 1686 | pass = (err != VK_SUCCESS); |
| 1687 | ASSERT_TRUE(pass); |
| 1688 | m_errorMonitor->VerifyFound(); |
| 1689 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1690 | // Create a native window, and then correctly create a surface: |
| 1691 | xcb_connection_t *connection; |
| 1692 | xcb_screen_t *screen; |
| 1693 | xcb_window_t xcb_window; |
| 1694 | xcb_intern_atom_reply_t *atom_wm_delete_window; |
| 1695 | |
| 1696 | const xcb_setup_t *setup; |
| 1697 | xcb_screen_iterator_t iter; |
| 1698 | int scr; |
| 1699 | uint32_t value_mask, value_list[32]; |
| 1700 | int width = 1; |
| 1701 | int height = 1; |
| 1702 | |
| 1703 | connection = xcb_connect(NULL, &scr); |
| 1704 | ASSERT_TRUE(connection != NULL); |
| 1705 | setup = xcb_get_setup(connection); |
| 1706 | iter = xcb_setup_roots_iterator(setup); |
| 1707 | while (scr-- > 0) |
| 1708 | xcb_screen_next(&iter); |
| 1709 | screen = iter.data; |
| 1710 | |
| 1711 | xcb_window = xcb_generate_id(connection); |
| 1712 | |
| 1713 | value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; |
| 1714 | value_list[0] = screen->black_pixel; |
| 1715 | value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | |
| 1716 | XCB_EVENT_MASK_STRUCTURE_NOTIFY; |
| 1717 | |
| 1718 | xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, |
| 1719 | screen->root, 0, 0, width, height, 0, |
| 1720 | XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, |
| 1721 | value_mask, value_list); |
| 1722 | |
| 1723 | /* Magic code that will send notification when window is destroyed */ |
| 1724 | xcb_intern_atom_cookie_t cookie = |
| 1725 | xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS"); |
| 1726 | xcb_intern_atom_reply_t *reply = |
| 1727 | xcb_intern_atom_reply(connection, cookie, 0); |
| 1728 | |
| 1729 | xcb_intern_atom_cookie_t cookie2 = |
| 1730 | xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW"); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1731 | atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1732 | xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, |
| 1733 | (*reply).atom, 4, 32, 1, |
| 1734 | &(*atom_wm_delete_window).atom); |
| 1735 | free(reply); |
| 1736 | |
| 1737 | xcb_map_window(connection, xcb_window); |
| 1738 | |
| 1739 | // Force the x/y coordinates to 100,100 results are identical in consecutive |
| 1740 | // runs |
| 1741 | const uint32_t coords[] = {100, 100}; |
| 1742 | xcb_configure_window(connection, xcb_window, |
| 1743 | XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords); |
| 1744 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1745 | // Finally, try to correctly create a surface: |
| 1746 | xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; |
| 1747 | xcb_create_info.pNext = NULL; |
| 1748 | xcb_create_info.flags = 0; |
| 1749 | xcb_create_info.connection = connection; |
| 1750 | xcb_create_info.window = xcb_window; |
| 1751 | err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface); |
| 1752 | pass = (err == VK_SUCCESS); |
| 1753 | ASSERT_TRUE(pass); |
| 1754 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1755 | // Check if surface supports presentation: |
| 1756 | |
| 1757 | // 1st, do so without having queried the queue families: |
| 1758 | VkBool32 supported = false; |
| 1759 | // TODO: Get the following error to come out: |
| 1760 | m_errorMonitor->SetDesiredFailureMsg( |
| 1761 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1762 | "called before calling the vkGetPhysicalDeviceQueueFamilyProperties " |
| 1763 | "function"); |
| 1764 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported); |
| 1765 | pass = (err != VK_SUCCESS); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1766 | // ASSERT_TRUE(pass); |
| 1767 | // m_errorMonitor->VerifyFound(); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1768 | |
| 1769 | // Next, query a queue family index that's too large: |
| 1770 | m_errorMonitor->SetDesiredFailureMsg( |
| 1771 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1772 | "called with a queueFamilyIndex that is too large"); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1773 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, |
| 1774 | &supported); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1775 | pass = (err != VK_SUCCESS); |
| 1776 | ASSERT_TRUE(pass); |
| 1777 | m_errorMonitor->VerifyFound(); |
| 1778 | |
| 1779 | // Finally, do so correctly: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1780 | // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S |
| 1781 | // SUPPORTED |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1782 | err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported); |
| 1783 | pass = (err == VK_SUCCESS); |
| 1784 | ASSERT_TRUE(pass); |
| 1785 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1786 | // Before proceeding, try to create a swapchain without having called |
| 1787 | // vkGetPhysicalDeviceSurfaceCapabilitiesKHR(): |
| 1788 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 1789 | swapchain_create_info.pNext = NULL; |
| 1790 | swapchain_create_info.flags = 0; |
| 1791 | m_errorMonitor->SetDesiredFailureMsg( |
| 1792 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1793 | "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR()."); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1794 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 1795 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1796 | pass = (err != VK_SUCCESS); |
| 1797 | ASSERT_TRUE(pass); |
| 1798 | m_errorMonitor->VerifyFound(); |
| 1799 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1800 | // Get the surface capabilities: |
| 1801 | VkSurfaceCapabilitiesKHR surface_capabilities; |
| 1802 | |
| 1803 | // Do so correctly (only error logged by this entrypoint is if the |
| 1804 | // extension isn't enabled): |
| 1805 | err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, |
| 1806 | &surface_capabilities); |
| 1807 | pass = (err == VK_SUCCESS); |
| 1808 | ASSERT_TRUE(pass); |
| 1809 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1810 | // Get the surface formats: |
| 1811 | uint32_t surface_format_count; |
| 1812 | |
| 1813 | // First, try without a pointer to surface_format_count: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1814 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1815 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1816 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL); |
| 1817 | pass = (err == VK_SUCCESS); |
| 1818 | ASSERT_TRUE(pass); |
| 1819 | m_errorMonitor->VerifyFound(); |
| 1820 | |
| 1821 | // Next, call with a non-NULL pSurfaceFormats, even though we haven't |
| 1822 | // correctly done a 1st try (to get the count): |
| 1823 | m_errorMonitor->SetDesiredFailureMsg( |
| 1824 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1825 | "but no prior positive value has been seen for"); |
| 1826 | surface_format_count = 0; |
| 1827 | vkGetPhysicalDeviceSurfaceFormatsKHR( |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1828 | gpu(), surface, &surface_format_count, |
| 1829 | (VkSurfaceFormatKHR *)&surface_format_count); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1830 | pass = (err == VK_SUCCESS); |
| 1831 | ASSERT_TRUE(pass); |
| 1832 | m_errorMonitor->VerifyFound(); |
| 1833 | |
| 1834 | // 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] | 1835 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
| 1836 | NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1837 | pass = (err == VK_SUCCESS); |
| 1838 | ASSERT_TRUE(pass); |
| 1839 | |
| 1840 | // Allocate memory for the correct number of VkSurfaceFormatKHR's: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1841 | VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc( |
| 1842 | surface_format_count * sizeof(VkSurfaceFormatKHR)); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1843 | |
| 1844 | // Next, do a 2nd try with surface_format_count being set too high: |
| 1845 | surface_format_count += 5; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1846 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1847 | "that is greater than the value"); |
| 1848 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1849 | surface_formats); |
| 1850 | pass = (err == VK_SUCCESS); |
| 1851 | ASSERT_TRUE(pass); |
| 1852 | m_errorMonitor->VerifyFound(); |
| 1853 | |
| 1854 | // Finally, do a correct 1st and 2nd try: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1855 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
| 1856 | NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1857 | pass = (err == VK_SUCCESS); |
| 1858 | ASSERT_TRUE(pass); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1859 | vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1860 | surface_formats); |
| 1861 | pass = (err == VK_SUCCESS); |
| 1862 | ASSERT_TRUE(pass); |
| 1863 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1864 | // Get the surface present modes: |
| 1865 | uint32_t surface_present_mode_count; |
| 1866 | |
| 1867 | // First, try without a pointer to surface_format_count: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1868 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1869 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1870 | vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL); |
| 1871 | pass = (err == VK_SUCCESS); |
| 1872 | ASSERT_TRUE(pass); |
| 1873 | m_errorMonitor->VerifyFound(); |
| 1874 | |
| 1875 | // Next, call with a non-NULL VkPresentModeKHR, even though we haven't |
| 1876 | // correctly done a 1st try (to get the count): |
| 1877 | m_errorMonitor->SetDesiredFailureMsg( |
| 1878 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1879 | "but no prior positive value has been seen for"); |
| 1880 | surface_present_mode_count = 0; |
| 1881 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1882 | gpu(), surface, &surface_present_mode_count, |
| 1883 | (VkPresentModeKHR *)&surface_present_mode_count); |
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 | |
| 1888 | // 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] | 1889 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 1890 | gpu(), surface, &surface_present_mode_count, NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1891 | pass = (err == VK_SUCCESS); |
| 1892 | ASSERT_TRUE(pass); |
| 1893 | |
| 1894 | // Allocate memory for the correct number of VkSurfaceFormatKHR's: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1895 | VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc( |
| 1896 | surface_present_mode_count * sizeof(VkPresentModeKHR)); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1897 | |
| 1898 | // Next, do a 2nd try with surface_format_count being set too high: |
| 1899 | surface_present_mode_count += 5; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1900 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1901 | "that is greater than the value"); |
| 1902 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 1903 | gpu(), surface, &surface_present_mode_count, surface_present_modes); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1904 | pass = (err == VK_SUCCESS); |
| 1905 | ASSERT_TRUE(pass); |
| 1906 | m_errorMonitor->VerifyFound(); |
| 1907 | |
| 1908 | // Finally, do a correct 1st and 2nd try: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1909 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 1910 | gpu(), surface, &surface_present_mode_count, NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1911 | pass = (err == VK_SUCCESS); |
| 1912 | ASSERT_TRUE(pass); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1913 | vkGetPhysicalDeviceSurfacePresentModesKHR( |
| 1914 | gpu(), surface, &surface_present_mode_count, surface_present_modes); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1915 | pass = (err == VK_SUCCESS); |
| 1916 | ASSERT_TRUE(pass); |
| 1917 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1918 | // Create a swapchain: |
| 1919 | |
| 1920 | // First, try without a pointer to swapchain_create_info: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1921 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1922 | "called with NULL pointer"); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1923 | err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain); |
| 1924 | pass = (err != VK_SUCCESS); |
| 1925 | ASSERT_TRUE(pass); |
| 1926 | m_errorMonitor->VerifyFound(); |
| 1927 | |
| 1928 | // Next, call with a non-NULL swapchain_create_info, that has the wrong |
| 1929 | // sType: |
| 1930 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1931 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1932 | "called with the wrong value for"); |
| 1933 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 1934 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1935 | pass = (err != VK_SUCCESS); |
| 1936 | ASSERT_TRUE(pass); |
| 1937 | m_errorMonitor->VerifyFound(); |
| 1938 | |
| 1939 | // Next, call with a NULL swapchain pointer: |
| 1940 | swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 1941 | swapchain_create_info.pNext = NULL; |
| 1942 | swapchain_create_info.flags = 0; |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1943 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1944 | "called with NULL pointer"); |
| 1945 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 1946 | NULL); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1947 | pass = (err != VK_SUCCESS); |
| 1948 | ASSERT_TRUE(pass); |
| 1949 | m_errorMonitor->VerifyFound(); |
| 1950 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1951 | // TODO: Enhance swapchain layer so that |
| 1952 | // swapchain_create_info.queueFamilyIndexCount is checked against something? |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1953 | |
| 1954 | // Next, call with a queue family index that's too large: |
| 1955 | uint32_t queueFamilyIndex[2] = {100000, 0}; |
| 1956 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT; |
| 1957 | swapchain_create_info.queueFamilyIndexCount = 2; |
| 1958 | swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex; |
| 1959 | m_errorMonitor->SetDesiredFailureMsg( |
| 1960 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1961 | "called with a queueFamilyIndex that is too large"); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1962 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 1963 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1964 | pass = (err != VK_SUCCESS); |
| 1965 | ASSERT_TRUE(pass); |
| 1966 | m_errorMonitor->VerifyFound(); |
| 1967 | |
| 1968 | // Next, call a queueFamilyIndexCount that's too small for CONCURRENT: |
| 1969 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT; |
| 1970 | swapchain_create_info.queueFamilyIndexCount = 1; |
| 1971 | m_errorMonitor->SetDesiredFailureMsg( |
| 1972 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1973 | "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or " |
| 1974 | "pCreateInfo->pQueueFamilyIndices)."); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1975 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 1976 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1977 | pass = (err != VK_SUCCESS); |
| 1978 | ASSERT_TRUE(pass); |
| 1979 | m_errorMonitor->VerifyFound(); |
| 1980 | |
| 1981 | // Next, call with an invalid imageSharingMode: |
| 1982 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM; |
| 1983 | swapchain_create_info.queueFamilyIndexCount = 1; |
| 1984 | m_errorMonitor->SetDesiredFailureMsg( |
| 1985 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 1986 | "called with a non-supported pCreateInfo->imageSharingMode (i.e."); |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1987 | err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, |
| 1988 | &swapchain); |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1989 | pass = (err != VK_SUCCESS); |
| 1990 | ASSERT_TRUE(pass); |
| 1991 | m_errorMonitor->VerifyFound(); |
| 1992 | // Fix for the future: |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1993 | // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S |
| 1994 | // SUPPORTED |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 1995 | swapchain_create_info.queueFamilyIndexCount = 0; |
| 1996 | queueFamilyIndex[0] = 0; |
| 1997 | swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 1998 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 1999 | // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ... |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2000 | // Get the images from a swapchain: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2001 | // Acquire an image from a swapchain: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2002 | // Present an image to a swapchain: |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2003 | // Destroy the swapchain: |
| 2004 | |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2005 | // TODOs: |
| 2006 | // |
| 2007 | // - Try destroying the device without first destroying the swapchain |
| 2008 | // |
| 2009 | // - Try destroying the device without first destroying the surface |
| 2010 | // |
| 2011 | // - Try destroying the surface without first destroying the swapchain |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2012 | |
| 2013 | // Destroy the surface: |
| 2014 | vkDestroySurfaceKHR(instance(), surface, NULL); |
| 2015 | |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2016 | // Tear down the window: |
| 2017 | xcb_destroy_window(connection, xcb_window); |
| 2018 | xcb_disconnect(connection); |
| 2019 | |
| 2020 | #else // VK_USE_PLATFORM_XCB_KHR |
Mark Lobodzinski | 085d27a | 2016-05-17 09:34:26 -0600 | [diff] [blame] | 2021 | return; |
Ian Elliott | 2c1daf5 | 2016-05-12 09:41:46 -0600 | [diff] [blame] | 2022 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 2023 | } |
| 2024 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2025 | TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) { |
| 2026 | VkResult err; |
| 2027 | bool pass; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2028 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2029 | m_errorMonitor->SetDesiredFailureMsg( |
| 2030 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2031 | "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT"); |
| 2032 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2033 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2034 | |
| 2035 | // 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] | 2036 | VkImage image; |
| 2037 | VkDeviceMemory mem; |
| 2038 | VkMemoryRequirements mem_reqs; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2039 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2040 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2041 | const int32_t tex_width = 32; |
| 2042 | const int32_t tex_height = 32; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2043 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2044 | VkImageCreateInfo image_create_info = {}; |
| 2045 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2046 | image_create_info.pNext = NULL; |
| 2047 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2048 | image_create_info.format = tex_format; |
| 2049 | image_create_info.extent.width = tex_width; |
| 2050 | image_create_info.extent.height = tex_height; |
| 2051 | image_create_info.extent.depth = 1; |
| 2052 | image_create_info.mipLevels = 1; |
| 2053 | image_create_info.arrayLayers = 1; |
| 2054 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2055 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2056 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2057 | image_create_info.flags = 0; |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 2058 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2059 | VkMemoryAllocateInfo mem_alloc = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 2060 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2061 | mem_alloc.pNext = NULL; |
| 2062 | mem_alloc.allocationSize = 0; |
| 2063 | // Introduce failure, do NOT set memProps to |
| 2064 | // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
| 2065 | mem_alloc.memoryTypeIndex = 1; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2066 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2067 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2068 | ASSERT_VK_SUCCESS(err); |
| 2069 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2070 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2071 | |
Mark Lobodzinski | 2306535 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 2072 | mem_alloc.allocationSize = mem_reqs.size; |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2073 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2074 | pass = |
| 2075 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, |
| 2076 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); |
| 2077 | if (!pass) { // If we can't find any unmappable memory this test doesn't |
| 2078 | // make sense |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2079 | vkDestroyImage(m_device->device(), image, NULL); |
Tony Barbour | 02fdc7d | 2015-08-04 16:13:01 -0600 | [diff] [blame] | 2080 | return; |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2081 | } |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 2082 | |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2083 | // allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2084 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2085 | ASSERT_VK_SUCCESS(err); |
| 2086 | |
| 2087 | // Try to bind free memory that has been freed |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 2088 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2089 | ASSERT_VK_SUCCESS(err); |
| 2090 | |
| 2091 | // Map memory as if to initialize the image |
| 2092 | void *mappedAddress = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2093 | err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, |
| 2094 | &mappedAddress); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2095 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2096 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2097 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2098 | vkDestroyImage(m_device->device(), image, NULL); |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2099 | } |
| 2100 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2101 | TEST_F(VkLayerTest, RebindMemory) { |
| 2102 | VkResult err; |
| 2103 | bool pass; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2104 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2105 | m_errorMonitor->SetDesiredFailureMsg( |
| 2106 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2107 | "which has already been bound to mem object"); |
| 2108 | |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2109 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2110 | |
| 2111 | // 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] | 2112 | VkImage image; |
| 2113 | VkDeviceMemory mem1; |
| 2114 | VkDeviceMemory mem2; |
| 2115 | VkMemoryRequirements mem_reqs; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2116 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2117 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2118 | const int32_t tex_width = 32; |
| 2119 | const int32_t tex_height = 32; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2120 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2121 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2122 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2123 | image_create_info.pNext = NULL; |
| 2124 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2125 | image_create_info.format = tex_format; |
| 2126 | image_create_info.extent.width = tex_width; |
| 2127 | image_create_info.extent.height = tex_height; |
| 2128 | image_create_info.extent.depth = 1; |
| 2129 | image_create_info.mipLevels = 1; |
| 2130 | image_create_info.arrayLayers = 1; |
| 2131 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2132 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2133 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2134 | image_create_info.flags = 0; |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2135 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2136 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2137 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2138 | mem_alloc.pNext = NULL; |
| 2139 | mem_alloc.allocationSize = 0; |
| 2140 | mem_alloc.memoryTypeIndex = 0; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2141 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2142 | // Introduce failure, do NOT set memProps to |
| 2143 | // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2144 | mem_alloc.memoryTypeIndex = 1; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2145 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2146 | ASSERT_VK_SUCCESS(err); |
| 2147 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2148 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2149 | |
| 2150 | mem_alloc.allocationSize = mem_reqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2151 | pass = |
| 2152 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 2153 | ASSERT_TRUE(pass); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2154 | |
| 2155 | // allocate 2 memory objects |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2156 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2157 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2158 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2159 | ASSERT_VK_SUCCESS(err); |
| 2160 | |
| 2161 | // Bind first memory object to Image object |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 2162 | err = vkBindImageMemory(m_device->device(), image, mem1, 0); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2163 | ASSERT_VK_SUCCESS(err); |
| 2164 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2165 | // Introduce validation failure, try to bind a different memory object to |
| 2166 | // the same image object |
Tony Barbour | 67e9915 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 2167 | err = vkBindImageMemory(m_device->device(), image, mem2, 0); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2168 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2169 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2170 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2171 | vkDestroyImage(m_device->device(), image, NULL); |
| 2172 | vkFreeMemory(m_device->device(), mem1, NULL); |
| 2173 | vkFreeMemory(m_device->device(), mem2, NULL); |
Mark Lobodzinski | 944aab1 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 2174 | } |
Mark Lobodzinski | 3780e14 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2175 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2176 | TEST_F(VkLayerTest, SubmitSignaledFence) { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2177 | vk_testing::Fence testFence; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2178 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2179 | m_errorMonitor->SetDesiredFailureMsg( |
| 2180 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences " |
| 2181 | "must be reset before being submitted"); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 2182 | |
| 2183 | VkFenceCreateInfo fenceInfo = {}; |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2184 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 2185 | fenceInfo.pNext = NULL; |
| 2186 | fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2187 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2188 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2189 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 2190 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 2191 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2192 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2193 | m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 2194 | m_stencil_clear_color, NULL); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2195 | EndCommandBuffer(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2196 | |
| 2197 | testFence.init(*m_device, fenceInfo); |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 2198 | |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 2199 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 2200 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 2201 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 2202 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 2203 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 2204 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 2205 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2206 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 2207 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 2208 | submit_info.pSignalSemaphores = NULL; |
Courtney Goeltzenleuchter | 646b907 | 2015-10-20 18:04:07 -0600 | [diff] [blame] | 2209 | |
| 2210 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2211 | vkQueueWaitIdle(m_device->m_queue); |
Mark Lobodzinski | 5fcc421 | 2015-09-14 17:43:42 -0600 | [diff] [blame] | 2212 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2213 | m_errorMonitor->VerifyFound(); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2214 | } |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2215 | // This is a positive test. We used to expect error in this case but spec now |
| 2216 | // allows it |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2217 | TEST_F(VkLayerTest, ResetUnsignaledFence) { |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2218 | m_errorMonitor->ExpectSuccess(); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2219 | vk_testing::Fence testFence; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 2220 | VkFenceCreateInfo fenceInfo = {}; |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2221 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 2222 | fenceInfo.pNext = NULL; |
| 2223 | |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 2224 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2225 | testFence.init(*m_device, fenceInfo); |
Chia-I Wu | d9e8e82 | 2015-07-03 11:45:55 +0800 | [diff] [blame] | 2226 | VkFence fences[1] = {testFence.handle()}; |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2227 | VkResult result = vkResetFences(m_device->device(), 1, fences); |
| 2228 | ASSERT_VK_SUCCESS(result); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2229 | |
Tobin Ehlis | aff7ae9 | 2016-04-18 15:45:20 -0600 | [diff] [blame] | 2230 | m_errorMonitor->VerifyNotFound(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2231 | } |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2232 | |
| 2233 | TEST_F(VkLayerTest, InvalidUsageBits) |
| 2234 | { |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2235 | TEST_DESCRIPTION( |
Karl Schultz | b5bc11e | 2016-05-04 08:36:08 -0600 | [diff] [blame] | 2236 | "Specify wrong usage for image then create conflicting view of image " |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2237 | "Initialize buffer with wrong usage then perform copy expecting errors " |
| 2238 | "from both the image and the buffer (2 calls)"); |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2239 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2240 | "Invalid usage flag for image "); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2241 | |
| 2242 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2243 | VkImageObj image(m_device); |
| 2244 | // Initialize image with USAGE_INPUT_ATTACHMENT |
Tobin Ehlis | 8b313c0 | 2016-05-25 15:01:52 -0600 | [diff] [blame] | 2245 | image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, |
Karl Schultz | b5bc11e | 2016-05-04 08:36:08 -0600 | [diff] [blame] | 2246 | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 2247 | ASSERT_TRUE(image.initialized()); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2248 | |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2249 | VkImageView dsv; |
| 2250 | VkImageViewCreateInfo dsvci = {}; |
| 2251 | dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 2252 | dsvci.image = image.handle(); |
| 2253 | dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 2254 | dsvci.format = VK_FORMAT_D32_SFLOAT_S8_UINT; |
| 2255 | dsvci.subresourceRange.layerCount = 1; |
| 2256 | dsvci.subresourceRange.baseMipLevel = 0; |
| 2257 | dsvci.subresourceRange.levelCount = 1; |
| 2258 | dsvci.subresourceRange.aspectMask = |
| 2259 | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2260 | |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2261 | // Create a view with depth / stencil aspect for image with different usage |
| 2262 | vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2263 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2264 | m_errorMonitor->VerifyFound(); |
Tony Barbour | f92621a | 2016-05-02 14:28:12 -0600 | [diff] [blame] | 2265 | |
| 2266 | // Initialize buffer with TRANSFER_DST usage |
| 2267 | vk_testing::Buffer buffer; |
| 2268 | VkMemoryPropertyFlags reqs = 0; |
| 2269 | buffer.init_as_dst(*m_device, 128 * 128, reqs); |
| 2270 | VkBufferImageCopy region = {}; |
| 2271 | region.bufferRowLength = 128; |
| 2272 | region.bufferImageHeight = 128; |
| 2273 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 2274 | region.imageSubresource.layerCount = 1; |
| 2275 | region.imageExtent.height = 16; |
| 2276 | region.imageExtent.width = 16; |
| 2277 | region.imageExtent.depth = 1; |
| 2278 | |
| 2279 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2280 | "Invalid usage flag for buffer "); |
| 2281 | // Buffer usage not set to TRANSFER_SRC and image usage not set to |
| 2282 | // TRANSFER_DST |
| 2283 | BeginCommandBuffer(); |
| 2284 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 2285 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 2286 | 1, ®ion); |
| 2287 | m_errorMonitor->VerifyFound(); |
| 2288 | |
| 2289 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2290 | "Invalid usage flag for image "); |
| 2291 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 2292 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 2293 | 1, ®ion); |
| 2294 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 41376e1 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 2295 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 2296 | #endif // MEM_TRACKER_TESTS |
| 2297 | |
Tobin Ehlis | 4bf96d1 | 2015-06-25 11:58:41 -0600 | [diff] [blame] | 2298 | #if OBJ_TRACKER_TESTS |
Mark Lobodzinski | fc5cc66 | 2016-05-02 17:17:41 -0600 | [diff] [blame] | 2299 | |
| 2300 | TEST_F(VkLayerTest, LeakAnObject) { |
| 2301 | VkResult err; |
| 2302 | |
| 2303 | TEST_DESCRIPTION( |
| 2304 | "Create a fence and destroy its device without first destroying the fence."); |
| 2305 | |
| 2306 | // Note that we have to create a new device since destroying the |
| 2307 | // framework's device causes Teardown() to fail and just calling Teardown |
| 2308 | // will destroy the errorMonitor. |
| 2309 | |
| 2310 | m_errorMonitor->SetDesiredFailureMsg( |
| 2311 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2312 | "OBJ ERROR : VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT object"); |
| 2313 | |
| 2314 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2315 | |
| 2316 | const std::vector<VkQueueFamilyProperties> queue_props = |
| 2317 | m_device->queue_props; |
| 2318 | std::vector<VkDeviceQueueCreateInfo> queue_info; |
| 2319 | queue_info.reserve(queue_props.size()); |
| 2320 | std::vector<std::vector<float>> queue_priorities; |
| 2321 | for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) { |
| 2322 | VkDeviceQueueCreateInfo qi = {}; |
| 2323 | qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; |
| 2324 | qi.pNext = NULL; |
| 2325 | qi.queueFamilyIndex = i; |
| 2326 | qi.queueCount = queue_props[i].queueCount; |
| 2327 | queue_priorities.emplace_back(qi.queueCount, 0.0f); |
| 2328 | qi.pQueuePriorities = queue_priorities[i].data(); |
| 2329 | queue_info.push_back(qi); |
| 2330 | } |
| 2331 | |
| 2332 | std::vector<const char *> device_layer_names; |
| 2333 | std::vector<const char *> device_extension_names; |
| 2334 | device_layer_names.push_back("VK_LAYER_GOOGLE_threading"); |
| 2335 | device_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation"); |
| 2336 | device_layer_names.push_back("VK_LAYER_LUNARG_object_tracker"); |
| 2337 | device_layer_names.push_back("VK_LAYER_LUNARG_core_validation"); |
| 2338 | device_layer_names.push_back("VK_LAYER_LUNARG_device_limits"); |
| 2339 | device_layer_names.push_back("VK_LAYER_LUNARG_image"); |
| 2340 | device_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects"); |
| 2341 | |
| 2342 | // The sacrificial device object |
| 2343 | VkDevice testDevice; |
| 2344 | VkDeviceCreateInfo device_create_info = {}; |
| 2345 | auto features = m_device->phy().features(); |
| 2346 | device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; |
| 2347 | device_create_info.pNext = NULL; |
| 2348 | device_create_info.queueCreateInfoCount = queue_info.size(); |
| 2349 | device_create_info.pQueueCreateInfos = queue_info.data(); |
| 2350 | device_create_info.enabledLayerCount = device_layer_names.size(); |
| 2351 | device_create_info.ppEnabledLayerNames = device_layer_names.data(); |
| 2352 | device_create_info.pEnabledFeatures = &features; |
| 2353 | err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice); |
| 2354 | ASSERT_VK_SUCCESS(err); |
| 2355 | |
| 2356 | VkFence fence; |
| 2357 | VkFenceCreateInfo fence_create_info = {}; |
| 2358 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 2359 | fence_create_info.pNext = NULL; |
| 2360 | fence_create_info.flags = 0; |
| 2361 | err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence); |
| 2362 | ASSERT_VK_SUCCESS(err); |
| 2363 | |
| 2364 | // Induce failure by not calling vkDestroyFence |
| 2365 | vkDestroyDevice(testDevice, NULL); |
| 2366 | m_errorMonitor->VerifyFound(); |
| 2367 | } |
| 2368 | |
| 2369 | TEST_F(VkLayerTest, InvalidCommandPoolConsistency) { |
| 2370 | |
| 2371 | TEST_DESCRIPTION("Allocate command buffers from one command pool and " |
| 2372 | "attempt to delete them from another."); |
| 2373 | |
| 2374 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2375 | "FreeCommandBuffers is attempting to free Command Buffer"); |
| 2376 | |
| 2377 | VkCommandPool command_pool_one; |
| 2378 | VkCommandPool command_pool_two; |
| 2379 | |
| 2380 | VkCommandPoolCreateInfo pool_create_info{}; |
| 2381 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 2382 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 2383 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 2384 | |
| 2385 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 2386 | &command_pool_one); |
| 2387 | |
| 2388 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 2389 | &command_pool_two); |
| 2390 | |
| 2391 | VkCommandBuffer command_buffer[9]; |
| 2392 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 2393 | command_buffer_allocate_info.sType = |
| 2394 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 2395 | command_buffer_allocate_info.commandPool = command_pool_one; |
| 2396 | command_buffer_allocate_info.commandBufferCount = 9; |
| 2397 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 2398 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 2399 | command_buffer); |
| 2400 | |
| 2401 | vkFreeCommandBuffers(m_device->device(), command_pool_two, 4, |
| 2402 | &command_buffer[3]); |
| 2403 | |
| 2404 | m_errorMonitor->VerifyFound(); |
| 2405 | |
| 2406 | vkDestroyCommandPool(m_device->device(), command_pool_one, NULL); |
| 2407 | vkDestroyCommandPool(m_device->device(), command_pool_two, NULL); |
| 2408 | } |
| 2409 | |
| 2410 | TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) { |
| 2411 | VkResult err; |
| 2412 | |
| 2413 | TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and " |
| 2414 | "attempt to delete them from another."); |
| 2415 | |
| 2416 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2417 | "FreeDescriptorSets is attempting to free descriptorSet"); |
| 2418 | |
| 2419 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2420 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 2421 | |
| 2422 | VkDescriptorPoolSize ds_type_count = {}; |
| 2423 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 2424 | ds_type_count.descriptorCount = 1; |
| 2425 | |
| 2426 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 2427 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 2428 | ds_pool_ci.pNext = NULL; |
| 2429 | ds_pool_ci.flags = 0; |
| 2430 | ds_pool_ci.maxSets = 1; |
| 2431 | ds_pool_ci.poolSizeCount = 1; |
| 2432 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 2433 | |
| 2434 | VkDescriptorPool ds_pool_one; |
| 2435 | err = |
| 2436 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one); |
| 2437 | ASSERT_VK_SUCCESS(err); |
| 2438 | |
| 2439 | // Create a second descriptor pool |
| 2440 | VkDescriptorPool ds_pool_two; |
| 2441 | err = |
| 2442 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two); |
| 2443 | ASSERT_VK_SUCCESS(err); |
| 2444 | |
| 2445 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 2446 | dsl_binding.binding = 0; |
| 2447 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 2448 | dsl_binding.descriptorCount = 1; |
| 2449 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 2450 | dsl_binding.pImmutableSamplers = NULL; |
| 2451 | |
| 2452 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 2453 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 2454 | ds_layout_ci.pNext = NULL; |
| 2455 | ds_layout_ci.bindingCount = 1; |
| 2456 | ds_layout_ci.pBindings = &dsl_binding; |
| 2457 | |
| 2458 | VkDescriptorSetLayout ds_layout; |
| 2459 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 2460 | &ds_layout); |
| 2461 | ASSERT_VK_SUCCESS(err); |
| 2462 | |
| 2463 | VkDescriptorSet descriptorSet; |
| 2464 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 2465 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 2466 | alloc_info.descriptorSetCount = 1; |
| 2467 | alloc_info.descriptorPool = ds_pool_one; |
| 2468 | alloc_info.pSetLayouts = &ds_layout; |
| 2469 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 2470 | &descriptorSet); |
| 2471 | ASSERT_VK_SUCCESS(err); |
| 2472 | |
| 2473 | err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet); |
| 2474 | |
| 2475 | m_errorMonitor->VerifyFound(); |
| 2476 | |
| 2477 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 2478 | vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL); |
| 2479 | vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL); |
| 2480 | } |
| 2481 | |
| 2482 | TEST_F(VkLayerTest, CreateUnknownObject) { |
| 2483 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2484 | "Invalid VkImage Object "); |
| 2485 | |
| 2486 | TEST_DESCRIPTION( |
| 2487 | "Pass an invalid image object handle into a Vulkan API call."); |
| 2488 | |
| 2489 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2490 | |
| 2491 | // Pass bogus handle into GetImageMemoryRequirements |
| 2492 | VkMemoryRequirements mem_reqs; |
| 2493 | uint64_t fakeImageHandle = 0xCADECADE; |
| 2494 | VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle); |
| 2495 | |
| 2496 | vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs); |
| 2497 | |
| 2498 | m_errorMonitor->VerifyFound(); |
| 2499 | } |
| 2500 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2501 | TEST_F(VkLayerTest, PipelineNotBound) { |
| 2502 | VkResult err; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2503 | |
Mark Lobodzinski | fc5cc66 | 2016-05-02 17:17:41 -0600 | [diff] [blame] | 2504 | TEST_DESCRIPTION( |
| 2505 | "Pass in an invalid pipeline object handle into a Vulkan API call."); |
| 2506 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2507 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2508 | "Invalid VkPipeline Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2509 | |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2510 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2511 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2512 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 2513 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2514 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 2515 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2516 | |
| 2517 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2518 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 2519 | ds_pool_ci.pNext = NULL; |
| 2520 | ds_pool_ci.maxSets = 1; |
| 2521 | ds_pool_ci.poolSizeCount = 1; |
| 2522 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2523 | |
| 2524 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2525 | err = |
| 2526 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2527 | ASSERT_VK_SUCCESS(err); |
| 2528 | |
| 2529 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2530 | dsl_binding.binding = 0; |
| 2531 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 2532 | dsl_binding.descriptorCount = 1; |
| 2533 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 2534 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2535 | |
| 2536 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2537 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 2538 | ds_layout_ci.pNext = NULL; |
| 2539 | ds_layout_ci.bindingCount = 1; |
| 2540 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2541 | |
| 2542 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2543 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 2544 | &ds_layout); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2545 | ASSERT_VK_SUCCESS(err); |
| 2546 | |
| 2547 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2548 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 2549 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 2550 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 2551 | alloc_info.descriptorPool = ds_pool; |
| 2552 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2553 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 2554 | &descriptorSet); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2555 | ASSERT_VK_SUCCESS(err); |
| 2556 | |
| 2557 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2558 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 2559 | pipeline_layout_ci.pNext = NULL; |
| 2560 | pipeline_layout_ci.setLayoutCount = 1; |
| 2561 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2562 | |
| 2563 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2564 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 2565 | &pipeline_layout); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2566 | ASSERT_VK_SUCCESS(err); |
| 2567 | |
Mark Young | ad77905 | 2016-01-06 14:26:04 -0700 | [diff] [blame] | 2568 | VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2569 | |
| 2570 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2571 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 2572 | VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2573 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2574 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2575 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2576 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 2577 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 2578 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2579 | } |
| 2580 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2581 | TEST_F(VkLayerTest, BindInvalidMemory) { |
| 2582 | VkResult err; |
| 2583 | bool pass; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2584 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2585 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2586 | "Invalid VkDeviceMemory Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2587 | |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2588 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2589 | |
| 2590 | // 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] | 2591 | VkImage image; |
| 2592 | VkDeviceMemory mem; |
| 2593 | VkMemoryRequirements mem_reqs; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2594 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2595 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2596 | const int32_t tex_width = 32; |
| 2597 | const int32_t tex_height = 32; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2598 | |
| 2599 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2600 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2601 | image_create_info.pNext = NULL; |
| 2602 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2603 | image_create_info.format = tex_format; |
| 2604 | image_create_info.extent.width = tex_width; |
| 2605 | image_create_info.extent.height = tex_height; |
| 2606 | image_create_info.extent.depth = 1; |
| 2607 | image_create_info.mipLevels = 1; |
| 2608 | image_create_info.arrayLayers = 1; |
| 2609 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2610 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2611 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2612 | image_create_info.flags = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2613 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2614 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2615 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2616 | mem_alloc.pNext = NULL; |
| 2617 | mem_alloc.allocationSize = 0; |
| 2618 | mem_alloc.memoryTypeIndex = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2619 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2620 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2621 | ASSERT_VK_SUCCESS(err); |
| 2622 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2623 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2624 | |
| 2625 | mem_alloc.allocationSize = mem_reqs.size; |
| 2626 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2627 | pass = |
| 2628 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 2629 | ASSERT_TRUE(pass); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2630 | |
| 2631 | // allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2632 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2633 | ASSERT_VK_SUCCESS(err); |
| 2634 | |
| 2635 | // Introduce validation failure, free memory before binding |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2636 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2637 | |
| 2638 | // Try to bind free memory that has been freed |
| 2639 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 2640 | // This may very well return an error. |
| 2641 | (void)err; |
| 2642 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2643 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2644 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2645 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2646 | } |
| 2647 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2648 | TEST_F(VkLayerTest, BindMemoryToDestroyedObject) { |
| 2649 | VkResult err; |
| 2650 | bool pass; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2651 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2652 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2653 | "Invalid VkImage Object "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 2654 | |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2655 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2656 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2657 | // Create an image object, allocate memory, destroy the object and then try |
| 2658 | // to bind it |
| 2659 | VkImage image; |
| 2660 | VkDeviceMemory mem; |
| 2661 | VkMemoryRequirements mem_reqs; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2662 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2663 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 2664 | const int32_t tex_width = 32; |
| 2665 | const int32_t tex_height = 32; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2666 | |
| 2667 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2668 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 2669 | image_create_info.pNext = NULL; |
| 2670 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 2671 | image_create_info.format = tex_format; |
| 2672 | image_create_info.extent.width = tex_width; |
| 2673 | image_create_info.extent.height = tex_height; |
| 2674 | image_create_info.extent.depth = 1; |
| 2675 | image_create_info.mipLevels = 1; |
| 2676 | image_create_info.arrayLayers = 1; |
| 2677 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 2678 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 2679 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 2680 | image_create_info.flags = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2681 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2682 | VkMemoryAllocateInfo mem_alloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2683 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2684 | mem_alloc.pNext = NULL; |
| 2685 | mem_alloc.allocationSize = 0; |
| 2686 | mem_alloc.memoryTypeIndex = 0; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2687 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2688 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2689 | ASSERT_VK_SUCCESS(err); |
| 2690 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2691 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2692 | |
| 2693 | mem_alloc.allocationSize = mem_reqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2694 | pass = |
| 2695 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 2696 | ASSERT_TRUE(pass); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2697 | |
| 2698 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 2699 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2700 | ASSERT_VK_SUCCESS(err); |
| 2701 | |
| 2702 | // Introduce validation failure, destroy Image object before binding |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2703 | vkDestroyImage(m_device->device(), image, NULL); |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2704 | ASSERT_VK_SUCCESS(err); |
| 2705 | |
| 2706 | // Now Try to bind memory to this destroyed object |
| 2707 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 2708 | // This may very well return an error. |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 2709 | (void)err; |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 2710 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 2711 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 2712 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 2713 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 2714 | } |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 2715 | |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 2716 | #endif // OBJ_TRACKER_TESTS |
| 2717 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 2718 | #if DRAW_STATE_TESTS |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 2719 | |
| 2720 | // This is a positive test. No errors should be generated. |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 2721 | TEST_F(VkLayerTest, WaitEventThenSet) { |
| 2722 | TEST_DESCRIPTION( |
| 2723 | "Wait on a event then set it after the wait has been submitted."); |
| 2724 | |
| 2725 | if ((m_device->queue_props.empty()) || |
| 2726 | (m_device->queue_props[0].queueCount < 2)) |
| 2727 | return; |
| 2728 | |
| 2729 | m_errorMonitor->ExpectSuccess(); |
| 2730 | |
| 2731 | VkEvent event; |
| 2732 | VkEventCreateInfo event_create_info{}; |
| 2733 | event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 2734 | vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event); |
| 2735 | |
| 2736 | VkCommandPool command_pool; |
| 2737 | VkCommandPoolCreateInfo pool_create_info{}; |
| 2738 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 2739 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 2740 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 2741 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 2742 | &command_pool); |
| 2743 | |
| 2744 | VkCommandBuffer command_buffer; |
| 2745 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 2746 | command_buffer_allocate_info.sType = |
| 2747 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 2748 | command_buffer_allocate_info.commandPool = command_pool; |
| 2749 | command_buffer_allocate_info.commandBufferCount = 1; |
| 2750 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 2751 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 2752 | &command_buffer); |
| 2753 | |
| 2754 | VkQueue queue = VK_NULL_HANDLE; |
| 2755 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 2756 | 1, &queue); |
| 2757 | |
| 2758 | { |
| 2759 | VkCommandBufferBeginInfo begin_info{}; |
| 2760 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 2761 | vkBeginCommandBuffer(command_buffer, &begin_info); |
| 2762 | |
| 2763 | vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, |
| 2764 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, |
| 2765 | nullptr, 0, nullptr); |
| 2766 | vkCmdResetEvent(command_buffer, event, |
| 2767 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 2768 | vkEndCommandBuffer(command_buffer); |
| 2769 | } |
| 2770 | { |
| 2771 | VkSubmitInfo submit_info{}; |
| 2772 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 2773 | submit_info.commandBufferCount = 1; |
| 2774 | submit_info.pCommandBuffers = &command_buffer; |
| 2775 | submit_info.signalSemaphoreCount = 0; |
| 2776 | submit_info.pSignalSemaphores = nullptr; |
| 2777 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 2778 | } |
| 2779 | { vkSetEvent(m_device->device(), event); } |
| 2780 | |
| 2781 | vkQueueWaitIdle(queue); |
| 2782 | |
| 2783 | vkDestroyEvent(m_device->device(), event, nullptr); |
| 2784 | vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer); |
| 2785 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 2786 | |
| 2787 | m_errorMonitor->VerifyNotFound(); |
| 2788 | } |
Michael Lentine | 5627e69 | 2016-05-20 17:45:02 -0500 | [diff] [blame] | 2789 | // This is a positive test. No errors should be generated. |
| 2790 | TEST_F(VkLayerTest, QueryAndCopyMultipleCommandBuffers) { |
| 2791 | TEST_DESCRIPTION( |
| 2792 | "Issue a query and copy from it on a second command buffer."); |
| 2793 | |
| 2794 | if ((m_device->queue_props.empty()) || |
| 2795 | (m_device->queue_props[0].queueCount < 2)) |
| 2796 | return; |
| 2797 | |
| 2798 | m_errorMonitor->ExpectSuccess(); |
| 2799 | |
| 2800 | VkQueryPool query_pool; |
| 2801 | VkQueryPoolCreateInfo query_pool_create_info{}; |
| 2802 | query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; |
| 2803 | query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP; |
| 2804 | query_pool_create_info.queryCount = 1; |
| 2805 | vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, |
| 2806 | &query_pool); |
| 2807 | |
| 2808 | VkCommandPool command_pool; |
| 2809 | VkCommandPoolCreateInfo pool_create_info{}; |
| 2810 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 2811 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 2812 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 2813 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 2814 | &command_pool); |
| 2815 | |
| 2816 | VkCommandBuffer command_buffer[2]; |
| 2817 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 2818 | command_buffer_allocate_info.sType = |
| 2819 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 2820 | command_buffer_allocate_info.commandPool = command_pool; |
| 2821 | command_buffer_allocate_info.commandBufferCount = 2; |
| 2822 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 2823 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 2824 | command_buffer); |
| 2825 | |
| 2826 | VkQueue queue = VK_NULL_HANDLE; |
| 2827 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 2828 | 1, &queue); |
| 2829 | |
| 2830 | uint32_t qfi = 0; |
| 2831 | VkBufferCreateInfo buff_create_info = {}; |
| 2832 | buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 2833 | buff_create_info.size = 1024; |
| 2834 | buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT; |
| 2835 | buff_create_info.queueFamilyIndexCount = 1; |
| 2836 | buff_create_info.pQueueFamilyIndices = &qfi; |
| 2837 | |
| 2838 | VkResult err; |
| 2839 | VkBuffer buffer; |
| 2840 | err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer); |
| 2841 | ASSERT_VK_SUCCESS(err); |
| 2842 | VkMemoryAllocateInfo mem_alloc = {}; |
| 2843 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 2844 | mem_alloc.pNext = NULL; |
| 2845 | mem_alloc.allocationSize = 1024; |
| 2846 | mem_alloc.memoryTypeIndex = 0; |
| 2847 | |
| 2848 | VkMemoryRequirements memReqs; |
| 2849 | vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs); |
| 2850 | bool pass = |
| 2851 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0); |
| 2852 | if (!pass) { |
| 2853 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 2854 | return; |
| 2855 | } |
| 2856 | |
| 2857 | VkDeviceMemory mem; |
| 2858 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 2859 | ASSERT_VK_SUCCESS(err); |
| 2860 | err = vkBindBufferMemory(m_device->device(), buffer, mem, 0); |
| 2861 | ASSERT_VK_SUCCESS(err); |
| 2862 | |
| 2863 | { |
| 2864 | VkCommandBufferBeginInfo begin_info{}; |
| 2865 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 2866 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 2867 | |
| 2868 | vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1); |
| 2869 | vkCmdWriteTimestamp(command_buffer[0], |
| 2870 | VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0); |
| 2871 | |
| 2872 | vkEndCommandBuffer(command_buffer[0]); |
| 2873 | |
| 2874 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 2875 | |
| 2876 | vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, |
| 2877 | 0, 0, 0); |
| 2878 | |
| 2879 | vkEndCommandBuffer(command_buffer[1]); |
| 2880 | } |
| 2881 | { |
| 2882 | VkSubmitInfo submit_info{}; |
| 2883 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 2884 | submit_info.commandBufferCount = 2; |
| 2885 | submit_info.pCommandBuffers = command_buffer; |
| 2886 | submit_info.signalSemaphoreCount = 0; |
| 2887 | submit_info.pSignalSemaphores = nullptr; |
| 2888 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 2889 | } |
| 2890 | |
| 2891 | vkQueueWaitIdle(queue); |
| 2892 | |
| 2893 | vkDestroyQueryPool(m_device->device(), query_pool, nullptr); |
| 2894 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer); |
| 2895 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 2896 | |
| 2897 | m_errorMonitor->VerifyNotFound(); |
| 2898 | } |
Michael Lentine | 860b0fe | 2016-05-20 10:14:00 -0500 | [diff] [blame] | 2899 | |
| 2900 | TEST_F(VkLayerTest, ResetEventThenSet) { |
| 2901 | TEST_DESCRIPTION( |
| 2902 | "Reset an event then set it after the reset has been submitted."); |
| 2903 | |
| 2904 | if ((m_device->queue_props.empty()) || |
| 2905 | (m_device->queue_props[0].queueCount < 2)) |
| 2906 | return; |
| 2907 | |
| 2908 | m_errorMonitor->ExpectSuccess(); |
| 2909 | |
| 2910 | VkEvent event; |
| 2911 | VkEventCreateInfo event_create_info{}; |
| 2912 | event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 2913 | vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event); |
| 2914 | |
| 2915 | VkCommandPool command_pool; |
| 2916 | VkCommandPoolCreateInfo pool_create_info{}; |
| 2917 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 2918 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 2919 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 2920 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 2921 | &command_pool); |
| 2922 | |
| 2923 | VkCommandBuffer command_buffer; |
| 2924 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 2925 | command_buffer_allocate_info.sType = |
| 2926 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 2927 | command_buffer_allocate_info.commandPool = command_pool; |
| 2928 | command_buffer_allocate_info.commandBufferCount = 1; |
| 2929 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 2930 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 2931 | &command_buffer); |
| 2932 | |
| 2933 | VkQueue queue = VK_NULL_HANDLE; |
| 2934 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 2935 | 1, &queue); |
| 2936 | |
| 2937 | { |
| 2938 | VkCommandBufferBeginInfo begin_info{}; |
| 2939 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 2940 | vkBeginCommandBuffer(command_buffer, &begin_info); |
| 2941 | |
| 2942 | vkCmdResetEvent(command_buffer, event, |
| 2943 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
| 2944 | vkCmdWaitEvents(command_buffer, 1, &event, |
| 2945 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 2946 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, |
| 2947 | nullptr, 0, nullptr); |
| 2948 | vkEndCommandBuffer(command_buffer); |
| 2949 | } |
| 2950 | { |
| 2951 | VkSubmitInfo submit_info{}; |
| 2952 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 2953 | submit_info.commandBufferCount = 1; |
| 2954 | submit_info.pCommandBuffers = &command_buffer; |
| 2955 | submit_info.signalSemaphoreCount = 0; |
| 2956 | submit_info.pSignalSemaphores = nullptr; |
| 2957 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 2958 | } |
| 2959 | { |
| 2960 | m_errorMonitor->SetDesiredFailureMsg( |
| 2961 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkSetEvent() on event " |
| 2962 | "0x1 that is already in use by a " |
| 2963 | "command buffer."); |
| 2964 | vkSetEvent(m_device->device(), event); |
| 2965 | m_errorMonitor->VerifyFound(); |
| 2966 | } |
| 2967 | |
| 2968 | vkQueueWaitIdle(queue); |
| 2969 | |
| 2970 | vkDestroyEvent(m_device->device(), event, nullptr); |
| 2971 | vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer); |
| 2972 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 2973 | } |
| 2974 | |
| 2975 | // This is a positive test. No errors should be generated. |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 2976 | TEST_F(VkLayerTest, TwoFencesThreeFrames) { |
| 2977 | TEST_DESCRIPTION("Two command buffers with two separate fences are each " |
| 2978 | "run through a Submit & WaitForFences cycle 3 times. This " |
| 2979 | "previously revealed a bug so running this positive test " |
| 2980 | "to prevent a regression."); |
| 2981 | m_errorMonitor->ExpectSuccess(); |
| 2982 | |
| 2983 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2984 | VkQueue queue = VK_NULL_HANDLE; |
| 2985 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 2986 | 0, &queue); |
| 2987 | |
| 2988 | static const uint32_t NUM_OBJECTS = 2; |
| 2989 | static const uint32_t NUM_FRAMES = 3; |
| 2990 | VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {}; |
| 2991 | VkFence fences[NUM_OBJECTS] = {}; |
| 2992 | |
| 2993 | VkCommandPool cmd_pool; |
| 2994 | VkCommandPoolCreateInfo cmd_pool_ci = {}; |
| 2995 | cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 2996 | cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 2997 | cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 2998 | VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, |
| 2999 | nullptr, &cmd_pool); |
| 3000 | ASSERT_VK_SUCCESS(err); |
| 3001 | |
| 3002 | VkCommandBufferAllocateInfo cmd_buf_info = {}; |
| 3003 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3004 | cmd_buf_info.commandPool = cmd_pool; |
| 3005 | cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3006 | cmd_buf_info.commandBufferCount = 1; |
| 3007 | |
| 3008 | VkFenceCreateInfo fence_ci = {}; |
| 3009 | fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3010 | fence_ci.pNext = nullptr; |
| 3011 | fence_ci.flags = 0; |
| 3012 | |
| 3013 | for (uint32_t i = 0; i < NUM_OBJECTS; ++i) { |
| 3014 | err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, |
| 3015 | &cmd_buffers[i]); |
| 3016 | ASSERT_VK_SUCCESS(err); |
| 3017 | err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]); |
| 3018 | ASSERT_VK_SUCCESS(err); |
| 3019 | } |
| 3020 | |
| 3021 | for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) { |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 3022 | for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) { |
| 3023 | // Create empty cmd buffer |
| 3024 | VkCommandBufferBeginInfo cmdBufBeginDesc = {}; |
| 3025 | cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3026 | |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 3027 | err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc); |
| 3028 | ASSERT_VK_SUCCESS(err); |
| 3029 | err = vkEndCommandBuffer(cmd_buffers[obj]); |
| 3030 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3031 | |
Tobin Ehlis | f902516 | 2016-05-26 06:55:21 -0600 | [diff] [blame] | 3032 | VkSubmitInfo submit_info = {}; |
| 3033 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3034 | submit_info.commandBufferCount = 1; |
| 3035 | submit_info.pCommandBuffers = &cmd_buffers[obj]; |
| 3036 | // Submit cmd buffer and wait for fence |
| 3037 | err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]); |
| 3038 | ASSERT_VK_SUCCESS(err); |
| 3039 | err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, |
| 3040 | UINT64_MAX); |
| 3041 | ASSERT_VK_SUCCESS(err); |
| 3042 | err = vkResetFences(m_device->device(), 1, &fences[obj]); |
| 3043 | ASSERT_VK_SUCCESS(err); |
| 3044 | } |
Tobin Ehlis | 0bb263b | 2016-05-10 12:13:02 -0600 | [diff] [blame] | 3045 | } |
| 3046 | m_errorMonitor->VerifyNotFound(); |
| 3047 | } |
| 3048 | // This is a positive test. No errors should be generated. |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3049 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) { |
| 3050 | |
| 3051 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 3052 | "submitted on separate queues followed by a QueueWaitIdle."); |
| 3053 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 3054 | if ((m_device->queue_props.empty()) || |
| 3055 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 3056 | return; |
| 3057 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3058 | m_errorMonitor->ExpectSuccess(); |
| 3059 | |
| 3060 | VkSemaphore semaphore; |
| 3061 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 3062 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 3063 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 3064 | &semaphore); |
| 3065 | |
| 3066 | VkCommandPool command_pool; |
| 3067 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3068 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3069 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3070 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3071 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3072 | &command_pool); |
| 3073 | |
| 3074 | VkCommandBuffer command_buffer[2]; |
| 3075 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3076 | command_buffer_allocate_info.sType = |
| 3077 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3078 | command_buffer_allocate_info.commandPool = command_pool; |
| 3079 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3080 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3081 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3082 | command_buffer); |
| 3083 | |
| 3084 | VkQueue queue = VK_NULL_HANDLE; |
| 3085 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3086 | 1, &queue); |
| 3087 | |
| 3088 | { |
| 3089 | VkCommandBufferBeginInfo begin_info{}; |
| 3090 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3091 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3092 | |
| 3093 | vkCmdPipelineBarrier(command_buffer[0], |
| 3094 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3095 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 3096 | 0, nullptr, 0, nullptr); |
| 3097 | |
| 3098 | VkViewport viewport{}; |
| 3099 | viewport.maxDepth = 1.0f; |
| 3100 | viewport.minDepth = 0.0f; |
| 3101 | viewport.width = 512; |
| 3102 | viewport.height = 512; |
| 3103 | viewport.x = 0; |
| 3104 | viewport.y = 0; |
| 3105 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 3106 | vkEndCommandBuffer(command_buffer[0]); |
| 3107 | } |
| 3108 | { |
| 3109 | VkCommandBufferBeginInfo begin_info{}; |
| 3110 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3111 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3112 | |
| 3113 | VkViewport viewport{}; |
| 3114 | viewport.maxDepth = 1.0f; |
| 3115 | viewport.minDepth = 0.0f; |
| 3116 | viewport.width = 512; |
| 3117 | viewport.height = 512; |
| 3118 | viewport.x = 0; |
| 3119 | viewport.y = 0; |
| 3120 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 3121 | vkEndCommandBuffer(command_buffer[1]); |
| 3122 | } |
| 3123 | { |
| 3124 | VkSubmitInfo submit_info{}; |
| 3125 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3126 | submit_info.commandBufferCount = 1; |
| 3127 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 3128 | submit_info.signalSemaphoreCount = 1; |
| 3129 | submit_info.pSignalSemaphores = &semaphore; |
| 3130 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3131 | } |
| 3132 | { |
| 3133 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 3134 | VkSubmitInfo submit_info{}; |
| 3135 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3136 | submit_info.commandBufferCount = 1; |
| 3137 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 3138 | submit_info.waitSemaphoreCount = 1; |
| 3139 | submit_info.pWaitSemaphores = &semaphore; |
| 3140 | submit_info.pWaitDstStageMask = flags; |
| 3141 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3142 | } |
| 3143 | |
| 3144 | vkQueueWaitIdle(m_device->m_queue); |
| 3145 | |
| 3146 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 3147 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 3148 | &command_buffer[0]); |
| 3149 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3150 | |
| 3151 | m_errorMonitor->VerifyNotFound(); |
| 3152 | } |
| 3153 | |
| 3154 | // This is a positive test. No errors should be generated. |
| 3155 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) { |
| 3156 | |
| 3157 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 3158 | "submitted on separate queues, the second having a fence" |
| 3159 | "followed by a QueueWaitIdle."); |
| 3160 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 3161 | if ((m_device->queue_props.empty()) || |
| 3162 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 3163 | return; |
| 3164 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3165 | m_errorMonitor->ExpectSuccess(); |
| 3166 | |
| 3167 | VkFence fence; |
| 3168 | VkFenceCreateInfo fence_create_info{}; |
| 3169 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3170 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 3171 | |
| 3172 | VkSemaphore semaphore; |
| 3173 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 3174 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 3175 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 3176 | &semaphore); |
| 3177 | |
| 3178 | VkCommandPool command_pool; |
| 3179 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3180 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3181 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3182 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3183 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3184 | &command_pool); |
| 3185 | |
| 3186 | VkCommandBuffer command_buffer[2]; |
| 3187 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3188 | command_buffer_allocate_info.sType = |
| 3189 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3190 | command_buffer_allocate_info.commandPool = command_pool; |
| 3191 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3192 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3193 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3194 | command_buffer); |
| 3195 | |
| 3196 | VkQueue queue = VK_NULL_HANDLE; |
| 3197 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3198 | 1, &queue); |
| 3199 | |
| 3200 | { |
| 3201 | VkCommandBufferBeginInfo begin_info{}; |
| 3202 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3203 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3204 | |
| 3205 | vkCmdPipelineBarrier(command_buffer[0], |
| 3206 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3207 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 3208 | 0, nullptr, 0, nullptr); |
| 3209 | |
| 3210 | VkViewport viewport{}; |
| 3211 | viewport.maxDepth = 1.0f; |
| 3212 | viewport.minDepth = 0.0f; |
| 3213 | viewport.width = 512; |
| 3214 | viewport.height = 512; |
| 3215 | viewport.x = 0; |
| 3216 | viewport.y = 0; |
| 3217 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 3218 | vkEndCommandBuffer(command_buffer[0]); |
| 3219 | } |
| 3220 | { |
| 3221 | VkCommandBufferBeginInfo begin_info{}; |
| 3222 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3223 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3224 | |
| 3225 | VkViewport viewport{}; |
| 3226 | viewport.maxDepth = 1.0f; |
| 3227 | viewport.minDepth = 0.0f; |
| 3228 | viewport.width = 512; |
| 3229 | viewport.height = 512; |
| 3230 | viewport.x = 0; |
| 3231 | viewport.y = 0; |
| 3232 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 3233 | vkEndCommandBuffer(command_buffer[1]); |
| 3234 | } |
| 3235 | { |
| 3236 | VkSubmitInfo submit_info{}; |
| 3237 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3238 | submit_info.commandBufferCount = 1; |
| 3239 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 3240 | submit_info.signalSemaphoreCount = 1; |
| 3241 | submit_info.pSignalSemaphores = &semaphore; |
| 3242 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3243 | } |
| 3244 | { |
| 3245 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 3246 | VkSubmitInfo submit_info{}; |
| 3247 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3248 | submit_info.commandBufferCount = 1; |
| 3249 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 3250 | submit_info.waitSemaphoreCount = 1; |
| 3251 | submit_info.pWaitSemaphores = &semaphore; |
| 3252 | submit_info.pWaitDstStageMask = flags; |
| 3253 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 3254 | } |
| 3255 | |
| 3256 | vkQueueWaitIdle(m_device->m_queue); |
| 3257 | |
| 3258 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 3259 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 3260 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 3261 | &command_buffer[0]); |
| 3262 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3263 | |
| 3264 | m_errorMonitor->VerifyNotFound(); |
| 3265 | } |
| 3266 | |
| 3267 | // This is a positive test. No errors should be generated. |
| 3268 | TEST_F(VkLayerTest, |
| 3269 | TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) { |
| 3270 | |
| 3271 | TEST_DESCRIPTION( |
| 3272 | "Two command buffers, each in a separate QueueSubmit call " |
| 3273 | "submitted on separate queues, the second having a fence" |
| 3274 | "followed by two consecutive WaitForFences calls on the same fence."); |
| 3275 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 3276 | if ((m_device->queue_props.empty()) || |
| 3277 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 3278 | return; |
| 3279 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3280 | m_errorMonitor->ExpectSuccess(); |
| 3281 | |
| 3282 | VkFence fence; |
| 3283 | VkFenceCreateInfo fence_create_info{}; |
| 3284 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3285 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 3286 | |
| 3287 | VkSemaphore semaphore; |
| 3288 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 3289 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 3290 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 3291 | &semaphore); |
| 3292 | |
| 3293 | VkCommandPool command_pool; |
| 3294 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3295 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3296 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3297 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3298 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3299 | &command_pool); |
| 3300 | |
| 3301 | VkCommandBuffer command_buffer[2]; |
| 3302 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3303 | command_buffer_allocate_info.sType = |
| 3304 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3305 | command_buffer_allocate_info.commandPool = command_pool; |
| 3306 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3307 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3308 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3309 | command_buffer); |
| 3310 | |
| 3311 | VkQueue queue = VK_NULL_HANDLE; |
| 3312 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3313 | 1, &queue); |
| 3314 | |
| 3315 | { |
| 3316 | VkCommandBufferBeginInfo begin_info{}; |
| 3317 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3318 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3319 | |
| 3320 | vkCmdPipelineBarrier(command_buffer[0], |
| 3321 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3322 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 3323 | 0, nullptr, 0, nullptr); |
| 3324 | |
| 3325 | VkViewport viewport{}; |
| 3326 | viewport.maxDepth = 1.0f; |
| 3327 | viewport.minDepth = 0.0f; |
| 3328 | viewport.width = 512; |
| 3329 | viewport.height = 512; |
| 3330 | viewport.x = 0; |
| 3331 | viewport.y = 0; |
| 3332 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 3333 | vkEndCommandBuffer(command_buffer[0]); |
| 3334 | } |
| 3335 | { |
| 3336 | VkCommandBufferBeginInfo begin_info{}; |
| 3337 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3338 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3339 | |
| 3340 | VkViewport viewport{}; |
| 3341 | viewport.maxDepth = 1.0f; |
| 3342 | viewport.minDepth = 0.0f; |
| 3343 | viewport.width = 512; |
| 3344 | viewport.height = 512; |
| 3345 | viewport.x = 0; |
| 3346 | viewport.y = 0; |
| 3347 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 3348 | vkEndCommandBuffer(command_buffer[1]); |
| 3349 | } |
| 3350 | { |
| 3351 | VkSubmitInfo submit_info{}; |
| 3352 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3353 | submit_info.commandBufferCount = 1; |
| 3354 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 3355 | submit_info.signalSemaphoreCount = 1; |
| 3356 | submit_info.pSignalSemaphores = &semaphore; |
| 3357 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3358 | } |
| 3359 | { |
| 3360 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 3361 | VkSubmitInfo submit_info{}; |
| 3362 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3363 | submit_info.commandBufferCount = 1; |
| 3364 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 3365 | submit_info.waitSemaphoreCount = 1; |
| 3366 | submit_info.pWaitSemaphores = &semaphore; |
| 3367 | submit_info.pWaitDstStageMask = flags; |
| 3368 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 3369 | } |
| 3370 | |
| 3371 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 3372 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 3373 | |
| 3374 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 3375 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 3376 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 3377 | &command_buffer[0]); |
| 3378 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3379 | |
| 3380 | m_errorMonitor->VerifyNotFound(); |
| 3381 | } |
| 3382 | |
| 3383 | // This is a positive test. No errors should be generated. |
| 3384 | TEST_F(VkLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) { |
| 3385 | |
| 3386 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 3387 | "submitted on separate queues, the second having a fence, " |
| 3388 | "followed by a WaitForFences call."); |
| 3389 | |
Dustin Graves | 4845814 | 2016-04-29 16:11:55 -0600 | [diff] [blame] | 3390 | if ((m_device->queue_props.empty()) || |
| 3391 | (m_device->queue_props[0].queueCount < 2)) |
Tony Barbour | dc18b26 | 2016-04-22 14:49:48 -0600 | [diff] [blame] | 3392 | return; |
| 3393 | |
Mark Lobodzinski | c808d44 | 2016-04-14 10:57:23 -0600 | [diff] [blame] | 3394 | m_errorMonitor->ExpectSuccess(); |
| 3395 | |
| 3396 | VkFence fence; |
| 3397 | VkFenceCreateInfo fence_create_info{}; |
| 3398 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3399 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 3400 | |
| 3401 | VkSemaphore semaphore; |
| 3402 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 3403 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 3404 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 3405 | &semaphore); |
| 3406 | |
| 3407 | VkCommandPool command_pool; |
| 3408 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3409 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3410 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3411 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3412 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3413 | &command_pool); |
| 3414 | |
| 3415 | VkCommandBuffer command_buffer[2]; |
| 3416 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3417 | command_buffer_allocate_info.sType = |
| 3418 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3419 | command_buffer_allocate_info.commandPool = command_pool; |
| 3420 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3421 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3422 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3423 | command_buffer); |
| 3424 | |
| 3425 | VkQueue queue = VK_NULL_HANDLE; |
| 3426 | vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, |
| 3427 | 1, &queue); |
| 3428 | |
| 3429 | |
| 3430 | { |
| 3431 | VkCommandBufferBeginInfo begin_info{}; |
| 3432 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3433 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3434 | |
| 3435 | vkCmdPipelineBarrier(command_buffer[0], |
| 3436 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3437 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 3438 | 0, nullptr, 0, nullptr); |
| 3439 | |
| 3440 | VkViewport viewport{}; |
| 3441 | viewport.maxDepth = 1.0f; |
| 3442 | viewport.minDepth = 0.0f; |
| 3443 | viewport.width = 512; |
| 3444 | viewport.height = 512; |
| 3445 | viewport.x = 0; |
| 3446 | viewport.y = 0; |
| 3447 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 3448 | vkEndCommandBuffer(command_buffer[0]); |
| 3449 | } |
| 3450 | { |
| 3451 | VkCommandBufferBeginInfo begin_info{}; |
| 3452 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3453 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3454 | |
| 3455 | VkViewport viewport{}; |
| 3456 | viewport.maxDepth = 1.0f; |
| 3457 | viewport.minDepth = 0.0f; |
| 3458 | viewport.width = 512; |
| 3459 | viewport.height = 512; |
| 3460 | viewport.x = 0; |
| 3461 | viewport.y = 0; |
| 3462 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 3463 | vkEndCommandBuffer(command_buffer[1]); |
| 3464 | } |
| 3465 | { |
| 3466 | VkSubmitInfo submit_info{}; |
| 3467 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3468 | submit_info.commandBufferCount = 1; |
| 3469 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 3470 | submit_info.signalSemaphoreCount = 1; |
| 3471 | submit_info.pSignalSemaphores = &semaphore; |
| 3472 | vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3473 | } |
| 3474 | { |
| 3475 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 3476 | VkSubmitInfo submit_info{}; |
| 3477 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3478 | submit_info.commandBufferCount = 1; |
| 3479 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 3480 | submit_info.waitSemaphoreCount = 1; |
| 3481 | submit_info.pWaitSemaphores = &semaphore; |
| 3482 | submit_info.pWaitDstStageMask = flags; |
| 3483 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 3484 | } |
| 3485 | |
| 3486 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 3487 | |
| 3488 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 3489 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 3490 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 3491 | &command_buffer[0]); |
| 3492 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3493 | |
| 3494 | m_errorMonitor->VerifyNotFound(); |
| 3495 | } |
| 3496 | |
| 3497 | // This is a positive test. No errors should be generated. |
| 3498 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) { |
| 3499 | |
| 3500 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 3501 | "on the same queue, sharing a signal/wait semaphore, the " |
| 3502 | "second having a fence, " |
| 3503 | "followed by a WaitForFences call."); |
| 3504 | |
| 3505 | m_errorMonitor->ExpectSuccess(); |
| 3506 | |
| 3507 | VkFence fence; |
| 3508 | VkFenceCreateInfo fence_create_info{}; |
| 3509 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3510 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 3511 | |
| 3512 | VkSemaphore semaphore; |
| 3513 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 3514 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 3515 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 3516 | &semaphore); |
| 3517 | |
| 3518 | VkCommandPool command_pool; |
| 3519 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3520 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3521 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3522 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3523 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3524 | &command_pool); |
| 3525 | |
| 3526 | VkCommandBuffer command_buffer[2]; |
| 3527 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3528 | command_buffer_allocate_info.sType = |
| 3529 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3530 | command_buffer_allocate_info.commandPool = command_pool; |
| 3531 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3532 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3533 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3534 | command_buffer); |
| 3535 | |
| 3536 | { |
| 3537 | VkCommandBufferBeginInfo begin_info{}; |
| 3538 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3539 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3540 | |
| 3541 | vkCmdPipelineBarrier(command_buffer[0], |
| 3542 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3543 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 3544 | 0, nullptr, 0, nullptr); |
| 3545 | |
| 3546 | VkViewport viewport{}; |
| 3547 | viewport.maxDepth = 1.0f; |
| 3548 | viewport.minDepth = 0.0f; |
| 3549 | viewport.width = 512; |
| 3550 | viewport.height = 512; |
| 3551 | viewport.x = 0; |
| 3552 | viewport.y = 0; |
| 3553 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 3554 | vkEndCommandBuffer(command_buffer[0]); |
| 3555 | } |
| 3556 | { |
| 3557 | VkCommandBufferBeginInfo begin_info{}; |
| 3558 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3559 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3560 | |
| 3561 | VkViewport viewport{}; |
| 3562 | viewport.maxDepth = 1.0f; |
| 3563 | viewport.minDepth = 0.0f; |
| 3564 | viewport.width = 512; |
| 3565 | viewport.height = 512; |
| 3566 | viewport.x = 0; |
| 3567 | viewport.y = 0; |
| 3568 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 3569 | vkEndCommandBuffer(command_buffer[1]); |
| 3570 | } |
| 3571 | { |
| 3572 | VkSubmitInfo submit_info{}; |
| 3573 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3574 | submit_info.commandBufferCount = 1; |
| 3575 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 3576 | submit_info.signalSemaphoreCount = 1; |
| 3577 | submit_info.pSignalSemaphores = &semaphore; |
| 3578 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3579 | } |
| 3580 | { |
| 3581 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 3582 | VkSubmitInfo submit_info{}; |
| 3583 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3584 | submit_info.commandBufferCount = 1; |
| 3585 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 3586 | submit_info.waitSemaphoreCount = 1; |
| 3587 | submit_info.pWaitSemaphores = &semaphore; |
| 3588 | submit_info.pWaitDstStageMask = flags; |
| 3589 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 3590 | } |
| 3591 | |
| 3592 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 3593 | |
| 3594 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 3595 | vkDestroySemaphore(m_device->device(), semaphore, nullptr); |
| 3596 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 3597 | &command_buffer[0]); |
| 3598 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3599 | |
| 3600 | m_errorMonitor->VerifyNotFound(); |
| 3601 | } |
| 3602 | |
| 3603 | // This is a positive test. No errors should be generated. |
| 3604 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) { |
| 3605 | |
| 3606 | TEST_DESCRIPTION( |
| 3607 | "Two command buffers, each in a separate QueueSubmit call " |
| 3608 | "on the same queue, no fences, followed by a third QueueSubmit with NO " |
| 3609 | "SubmitInfos but with a fence, followed by a WaitForFences call."); |
| 3610 | |
| 3611 | m_errorMonitor->ExpectSuccess(); |
| 3612 | |
| 3613 | VkFence fence; |
| 3614 | VkFenceCreateInfo fence_create_info{}; |
| 3615 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3616 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 3617 | |
| 3618 | VkCommandPool command_pool; |
| 3619 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3620 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3621 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3622 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3623 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3624 | &command_pool); |
| 3625 | |
| 3626 | VkCommandBuffer command_buffer[2]; |
| 3627 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3628 | command_buffer_allocate_info.sType = |
| 3629 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3630 | command_buffer_allocate_info.commandPool = command_pool; |
| 3631 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3632 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3633 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3634 | command_buffer); |
| 3635 | |
| 3636 | { |
| 3637 | VkCommandBufferBeginInfo begin_info{}; |
| 3638 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3639 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3640 | |
| 3641 | vkCmdPipelineBarrier(command_buffer[0], |
| 3642 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3643 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 3644 | 0, nullptr, 0, nullptr); |
| 3645 | |
| 3646 | VkViewport viewport{}; |
| 3647 | viewport.maxDepth = 1.0f; |
| 3648 | viewport.minDepth = 0.0f; |
| 3649 | viewport.width = 512; |
| 3650 | viewport.height = 512; |
| 3651 | viewport.x = 0; |
| 3652 | viewport.y = 0; |
| 3653 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 3654 | vkEndCommandBuffer(command_buffer[0]); |
| 3655 | } |
| 3656 | { |
| 3657 | VkCommandBufferBeginInfo begin_info{}; |
| 3658 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3659 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3660 | |
| 3661 | VkViewport viewport{}; |
| 3662 | viewport.maxDepth = 1.0f; |
| 3663 | viewport.minDepth = 0.0f; |
| 3664 | viewport.width = 512; |
| 3665 | viewport.height = 512; |
| 3666 | viewport.x = 0; |
| 3667 | viewport.y = 0; |
| 3668 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 3669 | vkEndCommandBuffer(command_buffer[1]); |
| 3670 | } |
| 3671 | { |
| 3672 | VkSubmitInfo submit_info{}; |
| 3673 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3674 | submit_info.commandBufferCount = 1; |
| 3675 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 3676 | submit_info.signalSemaphoreCount = 0; |
| 3677 | submit_info.pSignalSemaphores = VK_NULL_HANDLE; |
| 3678 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3679 | } |
| 3680 | { |
| 3681 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 3682 | VkSubmitInfo submit_info{}; |
| 3683 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3684 | submit_info.commandBufferCount = 1; |
| 3685 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 3686 | submit_info.waitSemaphoreCount = 0; |
| 3687 | submit_info.pWaitSemaphores = VK_NULL_HANDLE; |
| 3688 | submit_info.pWaitDstStageMask = flags; |
| 3689 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3690 | } |
| 3691 | |
| 3692 | vkQueueSubmit(m_device->m_queue, 0, NULL, fence); |
| 3693 | |
| 3694 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 3695 | |
| 3696 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 3697 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 3698 | &command_buffer[0]); |
| 3699 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3700 | |
| 3701 | m_errorMonitor->VerifyNotFound(); |
| 3702 | } |
| 3703 | |
| 3704 | // This is a positive test. No errors should be generated. |
| 3705 | TEST_F(VkLayerTest, TwoQueueSubmitsOneQueueOneFence) { |
| 3706 | |
| 3707 | TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call " |
| 3708 | "on the same queue, the second having a fence, followed " |
| 3709 | "by a WaitForFences call."); |
| 3710 | |
| 3711 | m_errorMonitor->ExpectSuccess(); |
| 3712 | |
| 3713 | VkFence fence; |
| 3714 | VkFenceCreateInfo fence_create_info{}; |
| 3715 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3716 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 3717 | |
| 3718 | VkCommandPool command_pool; |
| 3719 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3720 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3721 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3722 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3723 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3724 | &command_pool); |
| 3725 | |
| 3726 | VkCommandBuffer command_buffer[2]; |
| 3727 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3728 | command_buffer_allocate_info.sType = |
| 3729 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3730 | command_buffer_allocate_info.commandPool = command_pool; |
| 3731 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3732 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3733 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3734 | command_buffer); |
| 3735 | |
| 3736 | { |
| 3737 | VkCommandBufferBeginInfo begin_info{}; |
| 3738 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3739 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3740 | |
| 3741 | vkCmdPipelineBarrier(command_buffer[0], |
| 3742 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3743 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 3744 | 0, nullptr, 0, nullptr); |
| 3745 | |
| 3746 | VkViewport viewport{}; |
| 3747 | viewport.maxDepth = 1.0f; |
| 3748 | viewport.minDepth = 0.0f; |
| 3749 | viewport.width = 512; |
| 3750 | viewport.height = 512; |
| 3751 | viewport.x = 0; |
| 3752 | viewport.y = 0; |
| 3753 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 3754 | vkEndCommandBuffer(command_buffer[0]); |
| 3755 | } |
| 3756 | { |
| 3757 | VkCommandBufferBeginInfo begin_info{}; |
| 3758 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3759 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3760 | |
| 3761 | VkViewport viewport{}; |
| 3762 | viewport.maxDepth = 1.0f; |
| 3763 | viewport.minDepth = 0.0f; |
| 3764 | viewport.width = 512; |
| 3765 | viewport.height = 512; |
| 3766 | viewport.x = 0; |
| 3767 | viewport.y = 0; |
| 3768 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 3769 | vkEndCommandBuffer(command_buffer[1]); |
| 3770 | } |
| 3771 | { |
| 3772 | VkSubmitInfo submit_info{}; |
| 3773 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3774 | submit_info.commandBufferCount = 1; |
| 3775 | submit_info.pCommandBuffers = &command_buffer[0]; |
| 3776 | submit_info.signalSemaphoreCount = 0; |
| 3777 | submit_info.pSignalSemaphores = VK_NULL_HANDLE; |
| 3778 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE); |
| 3779 | } |
| 3780 | { |
| 3781 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 3782 | VkSubmitInfo submit_info{}; |
| 3783 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3784 | submit_info.commandBufferCount = 1; |
| 3785 | submit_info.pCommandBuffers = &command_buffer[1]; |
| 3786 | submit_info.waitSemaphoreCount = 0; |
| 3787 | submit_info.pWaitSemaphores = VK_NULL_HANDLE; |
| 3788 | submit_info.pWaitDstStageMask = flags; |
| 3789 | vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence); |
| 3790 | } |
| 3791 | |
| 3792 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 3793 | |
| 3794 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 3795 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 3796 | &command_buffer[0]); |
| 3797 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3798 | |
| 3799 | m_errorMonitor->VerifyNotFound(); |
| 3800 | } |
| 3801 | |
| 3802 | // This is a positive test. No errors should be generated. |
| 3803 | TEST_F(VkLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) { |
| 3804 | |
| 3805 | TEST_DESCRIPTION( |
| 3806 | "Two command buffers each in a separate SubmitInfo sent in a single " |
| 3807 | "QueueSubmit call followed by a WaitForFences call."); |
| 3808 | |
| 3809 | m_errorMonitor->ExpectSuccess(); |
| 3810 | |
| 3811 | VkFence fence; |
| 3812 | VkFenceCreateInfo fence_create_info{}; |
| 3813 | fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 3814 | vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence); |
| 3815 | |
| 3816 | VkSemaphore semaphore; |
| 3817 | VkSemaphoreCreateInfo semaphore_create_info{}; |
| 3818 | semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 3819 | vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, |
| 3820 | &semaphore); |
| 3821 | |
| 3822 | VkCommandPool command_pool; |
| 3823 | VkCommandPoolCreateInfo pool_create_info{}; |
| 3824 | pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 3825 | pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_; |
| 3826 | pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 3827 | vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, |
| 3828 | &command_pool); |
| 3829 | |
| 3830 | VkCommandBuffer command_buffer[2]; |
| 3831 | VkCommandBufferAllocateInfo command_buffer_allocate_info{}; |
| 3832 | command_buffer_allocate_info.sType = |
| 3833 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 3834 | command_buffer_allocate_info.commandPool = command_pool; |
| 3835 | command_buffer_allocate_info.commandBufferCount = 2; |
| 3836 | command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 3837 | vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, |
| 3838 | command_buffer); |
| 3839 | |
| 3840 | { |
| 3841 | VkCommandBufferBeginInfo begin_info{}; |
| 3842 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3843 | vkBeginCommandBuffer(command_buffer[0], &begin_info); |
| 3844 | |
| 3845 | vkCmdPipelineBarrier(command_buffer[0], |
| 3846 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, |
| 3847 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, |
| 3848 | 0, nullptr, 0, nullptr); |
| 3849 | |
| 3850 | VkViewport viewport{}; |
| 3851 | viewport.maxDepth = 1.0f; |
| 3852 | viewport.minDepth = 0.0f; |
| 3853 | viewport.width = 512; |
| 3854 | viewport.height = 512; |
| 3855 | viewport.x = 0; |
| 3856 | viewport.y = 0; |
| 3857 | vkCmdSetViewport(command_buffer[0], 0, 1, &viewport); |
| 3858 | vkEndCommandBuffer(command_buffer[0]); |
| 3859 | } |
| 3860 | { |
| 3861 | VkCommandBufferBeginInfo begin_info{}; |
| 3862 | begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 3863 | vkBeginCommandBuffer(command_buffer[1], &begin_info); |
| 3864 | |
| 3865 | VkViewport viewport{}; |
| 3866 | viewport.maxDepth = 1.0f; |
| 3867 | viewport.minDepth = 0.0f; |
| 3868 | viewport.width = 512; |
| 3869 | viewport.height = 512; |
| 3870 | viewport.x = 0; |
| 3871 | viewport.y = 0; |
| 3872 | vkCmdSetViewport(command_buffer[1], 0, 1, &viewport); |
| 3873 | vkEndCommandBuffer(command_buffer[1]); |
| 3874 | } |
| 3875 | { |
| 3876 | VkSubmitInfo submit_info[2]; |
| 3877 | VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; |
| 3878 | |
| 3879 | submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3880 | submit_info[0].pNext = NULL; |
| 3881 | submit_info[0].commandBufferCount = 1; |
| 3882 | submit_info[0].pCommandBuffers = &command_buffer[0]; |
| 3883 | submit_info[0].signalSemaphoreCount = 1; |
| 3884 | submit_info[0].pSignalSemaphores = &semaphore; |
| 3885 | submit_info[0].waitSemaphoreCount = 0; |
| 3886 | submit_info[0].pWaitSemaphores = NULL; |
| 3887 | submit_info[0].pWaitDstStageMask = 0; |
| 3888 | |
| 3889 | submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 3890 | submit_info[1].pNext = NULL; |
| 3891 | submit_info[1].commandBufferCount = 1; |
| 3892 | submit_info[1].pCommandBuffers = &command_buffer[1]; |
| 3893 | submit_info[1].waitSemaphoreCount = 1; |
| 3894 | submit_info[1].pWaitSemaphores = &semaphore; |
| 3895 | submit_info[1].pWaitDstStageMask = flags; |
| 3896 | submit_info[1].signalSemaphoreCount = 0; |
| 3897 | submit_info[1].pSignalSemaphores = NULL; |
| 3898 | vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence); |
| 3899 | } |
| 3900 | |
| 3901 | vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX); |
| 3902 | |
| 3903 | vkDestroyFence(m_device->device(), fence, nullptr); |
| 3904 | vkFreeCommandBuffers(m_device->device(), command_pool, 2, |
| 3905 | &command_buffer[0]); |
| 3906 | vkDestroyCommandPool(m_device->device(), command_pool, NULL); |
| 3907 | |
| 3908 | m_errorMonitor->VerifyNotFound(); |
| 3909 | } |
| 3910 | |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 3911 | TEST_F(VkLayerTest, DynamicDepthBiasNotBound) { |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 3912 | TEST_DESCRIPTION( |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 3913 | "Run a simple draw calls to validate failure when Depth Bias dynamic " |
| 3914 | "state is required but not correctly bound."); |
| 3915 | |
| 3916 | // Dynamic depth bias |
| 3917 | m_errorMonitor->SetDesiredFailureMsg( |
| 3918 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3919 | "Dynamic depth bias state not set for this command buffer"); |
| 3920 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 3921 | BsoFailDepthBias); |
| 3922 | m_errorMonitor->VerifyFound(); |
| 3923 | } |
| 3924 | |
| 3925 | TEST_F(VkLayerTest, DynamicLineWidthNotBound) { |
| 3926 | TEST_DESCRIPTION( |
| 3927 | "Run a simple draw calls to validate failure when Line Width dynamic " |
| 3928 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 3929 | |
| 3930 | // Dynamic line width |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3931 | m_errorMonitor->SetDesiredFailureMsg( |
| 3932 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 3933 | "Dynamic line width state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3934 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 3935 | BsoFailLineWidth); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 3936 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 3937 | } |
| 3938 | |
| 3939 | TEST_F(VkLayerTest, DynamicViewportNotBound) { |
| 3940 | TEST_DESCRIPTION( |
| 3941 | "Run a simple draw calls to validate failure when Viewport dynamic " |
| 3942 | "state is required but not correctly bound."); |
| 3943 | |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 3944 | // Dynamic viewport state |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3945 | m_errorMonitor->SetDesiredFailureMsg( |
| 3946 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 3947 | "Dynamic viewport state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3948 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 3949 | BsoFailViewport); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 3950 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 3951 | } |
| 3952 | |
| 3953 | TEST_F(VkLayerTest, DynamicScissorNotBound) { |
| 3954 | TEST_DESCRIPTION( |
| 3955 | "Run a simple draw calls to validate failure when Scissor dynamic " |
| 3956 | "state is required but not correctly bound."); |
| 3957 | |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 3958 | // Dynamic scissor state |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3959 | m_errorMonitor->SetDesiredFailureMsg( |
| 3960 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 3961 | "Dynamic scissor state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3962 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 3963 | BsoFailScissor); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 3964 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 3965 | } |
| 3966 | |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 3967 | TEST_F(VkLayerTest, DynamiBlendConstantsNotBound) { |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 3968 | TEST_DESCRIPTION( |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 3969 | "Run a simple draw calls to validate failure when Blend Constants " |
| 3970 | "dynamic state is required but not correctly bound."); |
| 3971 | // Dynamic blend constant state |
| 3972 | m_errorMonitor->SetDesiredFailureMsg( |
| 3973 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 3974 | "Dynamic blend constants state not set for this command buffer"); |
| 3975 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 3976 | BsoFailBlend); |
| 3977 | m_errorMonitor->VerifyFound(); |
| 3978 | } |
| 3979 | |
| 3980 | TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) { |
| 3981 | TEST_DESCRIPTION( |
| 3982 | "Run a simple draw calls to validate failure when Depth Bounds dynamic " |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 3983 | "state is required but not correctly bound."); |
Tobin Ehlis | 21c8835 | 2016-05-26 06:15:45 -0600 | [diff] [blame] | 3984 | if (!m_device->phy().features().depthBounds) { |
| 3985 | printf("Device does not support depthBounds test; skipped.\n"); |
| 3986 | return; |
| 3987 | } |
| 3988 | // Dynamic depth bounds |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3989 | m_errorMonitor->SetDesiredFailureMsg( |
| 3990 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 3991 | "Dynamic depth bounds state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 3992 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 3993 | BsoFailDepthBounds); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 3994 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 3995 | } |
| 3996 | |
| 3997 | TEST_F(VkLayerTest, DynamicStencilReadNotBound) { |
| 3998 | TEST_DESCRIPTION( |
| 3999 | "Run a simple draw calls to validate failure when Stencil Read dynamic " |
| 4000 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4001 | // Dynamic stencil read mask |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4002 | m_errorMonitor->SetDesiredFailureMsg( |
| 4003 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4004 | "Dynamic stencil read mask state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4005 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4006 | BsoFailStencilReadMask); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4007 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4008 | } |
| 4009 | |
| 4010 | TEST_F(VkLayerTest, DynamicStencilWriteNotBound) { |
| 4011 | TEST_DESCRIPTION( |
| 4012 | "Run a simple draw calls to validate failure when Stencil Write dynamic" |
| 4013 | " state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4014 | // Dynamic stencil write mask |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4015 | m_errorMonitor->SetDesiredFailureMsg( |
| 4016 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4017 | "Dynamic stencil write mask state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4018 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4019 | BsoFailStencilWriteMask); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4020 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b1a8799 | 2016-05-25 16:42:47 -0600 | [diff] [blame] | 4021 | } |
| 4022 | |
| 4023 | TEST_F(VkLayerTest, DynamicStencilRefNotBound) { |
| 4024 | TEST_DESCRIPTION( |
| 4025 | "Run a simple draw calls to validate failure when Stencil Ref dynamic " |
| 4026 | "state is required but not correctly bound."); |
Tobin Ehlis | a5200ef | 2016-05-03 10:34:08 -0600 | [diff] [blame] | 4027 | // Dynamic stencil reference |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4028 | m_errorMonitor->SetDesiredFailureMsg( |
| 4029 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4030 | "Dynamic stencil reference state not set for this command buffer"); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4031 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, |
| 4032 | BsoFailStencilReference); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4033 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 963a404 | 2015-09-29 08:18:34 -0600 | [diff] [blame] | 4034 | } |
| 4035 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4036 | TEST_F(VkLayerTest, CommandBufferTwoSubmits) { |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4037 | vk_testing::Fence testFence; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4038 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4039 | m_errorMonitor->SetDesiredFailureMsg( |
| 4040 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4041 | "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has " |
| 4042 | "been submitted"); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4043 | |
| 4044 | VkFenceCreateInfo fenceInfo = {}; |
| 4045 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 4046 | fenceInfo.pNext = NULL; |
| 4047 | fenceInfo.flags = 0; |
| 4048 | |
| 4049 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4050 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 4051 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 4052 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4053 | // We luck out b/c by default the framework creates CB w/ the |
| 4054 | // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4055 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4056 | m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, |
| 4057 | m_stencil_clear_color, NULL); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4058 | EndCommandBuffer(); |
| 4059 | |
| 4060 | testFence.init(*m_device, fenceInfo); |
| 4061 | |
| 4062 | // Bypass framework since it does the waits automatically |
| 4063 | VkResult err = VK_SUCCESS; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 4064 | VkSubmitInfo submit_info; |
Chia-I Wu | f9be13c | 2015-10-26 20:37:06 +0800 | [diff] [blame] | 4065 | submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 4066 | submit_info.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 4067 | submit_info.waitSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 4068 | submit_info.pWaitSemaphores = NULL; |
Jon Ashburn | 7f9716c | 2015-12-30 16:42:50 -0700 | [diff] [blame] | 4069 | submit_info.pWaitDstStageMask = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 4070 | submit_info.commandBufferCount = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 4071 | submit_info.pCommandBuffers = &m_commandBuffer->handle(); |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 4072 | submit_info.signalSemaphoreCount = 0; |
Courtney Goeltzenleuchter | 806c700 | 2015-10-27 11:22:14 -0600 | [diff] [blame] | 4073 | submit_info.pSignalSemaphores = NULL; |
| 4074 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4075 | err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle()); |
| 4076 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4077 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4078 | // Cause validation error by re-submitting cmd buffer that should only be |
| 4079 | // submitted once |
| 4080 | err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle()); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4081 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4082 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 59278bf | 2015-08-18 07:10:58 -0600 | [diff] [blame] | 4083 | } |
| 4084 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4085 | TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) { |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4086 | // Initiate Draw w/o a PSO bound |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4087 | VkResult err; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4088 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 4089 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4090 | "Unable to allocate 1 descriptors of " |
| 4091 | "type " |
| 4092 | "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4093 | |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4094 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4095 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4096 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4097 | // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer |
| 4098 | // descriptor from it |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 4099 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4100 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 4101 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4102 | |
| 4103 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4104 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 4105 | ds_pool_ci.pNext = NULL; |
| 4106 | ds_pool_ci.flags = 0; |
| 4107 | ds_pool_ci.maxSets = 1; |
| 4108 | ds_pool_ci.poolSizeCount = 1; |
| 4109 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4110 | |
| 4111 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4112 | err = |
| 4113 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4114 | ASSERT_VK_SUCCESS(err); |
| 4115 | |
| 4116 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4117 | dsl_binding.binding = 0; |
| 4118 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4119 | dsl_binding.descriptorCount = 1; |
| 4120 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 4121 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4122 | |
| 4123 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4124 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4125 | ds_layout_ci.pNext = NULL; |
| 4126 | ds_layout_ci.bindingCount = 1; |
| 4127 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4128 | |
| 4129 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4130 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 4131 | &ds_layout); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4132 | ASSERT_VK_SUCCESS(err); |
| 4133 | |
| 4134 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 4135 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 4136 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4137 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 4138 | alloc_info.descriptorPool = ds_pool; |
| 4139 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4140 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 4141 | &descriptorSet); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4142 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4143 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4144 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 4145 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 4146 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | f93f1e3 | 2015-10-20 16:16:04 -0600 | [diff] [blame] | 4147 | } |
| 4148 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4149 | TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) { |
| 4150 | VkResult err; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4151 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4152 | m_errorMonitor->SetDesiredFailureMsg( |
| 4153 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4154 | "It is invalid to call vkFreeDescriptorSets() with a pool created " |
| 4155 | "without setting VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4156 | |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4157 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4158 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4159 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 4160 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4161 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4162 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4163 | |
| 4164 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4165 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 4166 | ds_pool_ci.pNext = NULL; |
| 4167 | ds_pool_ci.maxSets = 1; |
| 4168 | ds_pool_ci.poolSizeCount = 1; |
| 4169 | ds_pool_ci.flags = 0; |
| 4170 | // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means |
| 4171 | // app can only call vkResetDescriptorPool on this pool.; |
| 4172 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4173 | |
| 4174 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4175 | err = |
| 4176 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4177 | ASSERT_VK_SUCCESS(err); |
| 4178 | |
| 4179 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4180 | dsl_binding.binding = 0; |
| 4181 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4182 | dsl_binding.descriptorCount = 1; |
| 4183 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 4184 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4185 | |
| 4186 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4187 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4188 | ds_layout_ci.pNext = NULL; |
| 4189 | ds_layout_ci.bindingCount = 1; |
| 4190 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4191 | |
| 4192 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4193 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 4194 | &ds_layout); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4195 | ASSERT_VK_SUCCESS(err); |
| 4196 | |
| 4197 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 4198 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 4199 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4200 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 4201 | alloc_info.descriptorPool = ds_pool; |
| 4202 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4203 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 4204 | &descriptorSet); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4205 | ASSERT_VK_SUCCESS(err); |
| 4206 | |
| 4207 | err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4208 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4209 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 4210 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 4211 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e735c69 | 2015-10-08 13:13:50 -0600 | [diff] [blame] | 4212 | } |
| 4213 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4214 | TEST_F(VkLayerTest, InvalidDescriptorPool) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4215 | // Attempt to clear Descriptor Pool with bad object. |
| 4216 | // ObjectTracker should catch this. |
| 4217 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4218 | "Invalid VkDescriptorPool Object 0xbaad6001"); |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4219 | uint64_t fake_pool_handle = 0xbaad6001; |
| 4220 | VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle); |
| 4221 | vkResetDescriptorPool(device(), bad_pool, 0); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4222 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4223 | } |
| 4224 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4225 | TEST_F(VkLayerTest, InvalidDescriptorSet) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4226 | // Attempt to bind an invalid Descriptor Set to a valid Command Buffer |
| 4227 | // ObjectTracker should catch this. |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4228 | // Create a valid cmd buffer |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4229 | // call vkCmdBindDescriptorSets w/ false Descriptor Set |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4230 | |
| 4231 | uint64_t fake_set_handle = 0xbaad6001; |
| 4232 | VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4233 | VkResult err; |
| 4234 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4235 | "Invalid VkDescriptorSet Object 0xbaad6001"); |
| 4236 | |
| 4237 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4238 | |
| 4239 | VkDescriptorSetLayoutBinding layout_bindings[1] = {}; |
| 4240 | layout_bindings[0].binding = 0; |
| 4241 | layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4242 | layout_bindings[0].descriptorCount = 1; |
| 4243 | layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; |
| 4244 | layout_bindings[0].pImmutableSamplers = NULL; |
| 4245 | |
| 4246 | VkDescriptorSetLayout descriptor_set_layout; |
| 4247 | VkDescriptorSetLayoutCreateInfo dslci = {}; |
| 4248 | dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4249 | dslci.pNext = NULL; |
| 4250 | dslci.bindingCount = 1; |
| 4251 | dslci.pBindings = layout_bindings; |
| 4252 | err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout); |
Karl Schultz | 5cb2111 | 2016-04-21 17:17:40 -0600 | [diff] [blame] | 4253 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4254 | |
| 4255 | VkPipelineLayout pipeline_layout; |
| 4256 | VkPipelineLayoutCreateInfo plci = {}; |
| 4257 | plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 4258 | plci.pNext = NULL; |
| 4259 | plci.setLayoutCount = 1; |
| 4260 | plci.pSetLayouts = &descriptor_set_layout; |
| 4261 | err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout); |
Karl Schultz | 5cb2111 | 2016-04-21 17:17:40 -0600 | [diff] [blame] | 4262 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4263 | |
| 4264 | BeginCommandBuffer(); |
| 4265 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4266 | pipeline_layout, 0, 1, &bad_set, 0, NULL); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4267 | m_errorMonitor->VerifyFound(); |
| 4268 | EndCommandBuffer(); |
| 4269 | vkDestroyPipelineLayout(device(), pipeline_layout, NULL); |
| 4270 | vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4271 | } |
| 4272 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4273 | TEST_F(VkLayerTest, InvalidDescriptorSetLayout) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4274 | // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout. |
| 4275 | // ObjectTracker should catch this. |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4276 | uint64_t fake_layout_handle = 0xbaad6001; |
| 4277 | VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4278 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4279 | "Invalid VkDescriptorSetLayout Object 0xbaad6001"); |
| 4280 | |
| 4281 | VkPipelineLayout pipeline_layout; |
| 4282 | VkPipelineLayoutCreateInfo plci = {}; |
| 4283 | plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 4284 | plci.pNext = NULL; |
| 4285 | plci.setLayoutCount = 1; |
| 4286 | plci.pSetLayouts = &bad_layout; |
| 4287 | vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout); |
| 4288 | |
| 4289 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4290 | } |
| 4291 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4292 | TEST_F(VkLayerTest, InvalidPipeline) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4293 | // Attempt to bind an invalid Pipeline to a valid Command Buffer |
| 4294 | // ObjectTracker should catch this. |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4295 | // Create a valid cmd buffer |
| 4296 | // call vkCmdBindPipeline w/ false Pipeline |
Mark Lobodzinski | 02bf89d | 2016-05-10 14:45:13 -0600 | [diff] [blame] | 4297 | uint64_t fake_pipeline_handle = 0xbaad6001; |
| 4298 | VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4299 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4300 | "Invalid VkPipeline Object 0xbaad6001"); |
| 4301 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4302 | BeginCommandBuffer(); |
| 4303 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 4304 | VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline); |
| 4305 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | b8b6b27 | 2016-05-02 13:26:06 -0600 | [diff] [blame] | 4306 | |
| 4307 | // Now issue a draw call with no pipeline bound |
| 4308 | m_errorMonitor->SetDesiredFailureMsg( |
| 4309 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4310 | "At Draw/Dispatch time no valid VkPipeline is bound!"); |
| 4311 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4312 | BeginCommandBuffer(); |
| 4313 | Draw(1, 0, 0, 0); |
| 4314 | m_errorMonitor->VerifyFound(); |
| 4315 | // Finally same check once more but with Dispatch/Compute |
| 4316 | m_errorMonitor->SetDesiredFailureMsg( |
| 4317 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4318 | "At Draw/Dispatch time no valid VkPipeline is bound!"); |
| 4319 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4320 | BeginCommandBuffer(); |
| 4321 | vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0); |
| 4322 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 4323 | } |
| 4324 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4325 | TEST_F(VkLayerTest, DescriptorSetNotUpdated) { |
| 4326 | // Create and update CommandBuffer then call QueueSubmit w/o calling End on |
| 4327 | // CommandBuffer |
| 4328 | VkResult err; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 4329 | |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 4330 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4331 | " bound but it was never updated. "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 4332 | |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 4333 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 4334 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 4335 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 4336 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4337 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4338 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 4339 | |
| 4340 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4341 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 4342 | ds_pool_ci.pNext = NULL; |
| 4343 | ds_pool_ci.maxSets = 1; |
| 4344 | ds_pool_ci.poolSizeCount = 1; |
| 4345 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Mike Stroyan | 713b2d7 | 2015-08-04 10:49:29 -0600 | [diff] [blame] | 4346 | |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 4347 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4348 | err = |
| 4349 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 4350 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 4351 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 4352 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4353 | dsl_binding.binding = 0; |
| 4354 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 4355 | dsl_binding.descriptorCount = 1; |
| 4356 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 4357 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 4358 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 4359 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4360 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4361 | ds_layout_ci.pNext = NULL; |
| 4362 | ds_layout_ci.bindingCount = 1; |
| 4363 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 4364 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4365 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 4366 | &ds_layout); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 4367 | ASSERT_VK_SUCCESS(err); |
| 4368 | |
| 4369 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 4370 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 4371 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4372 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 4373 | alloc_info.descriptorPool = ds_pool; |
| 4374 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4375 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 4376 | &descriptorSet); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 4377 | ASSERT_VK_SUCCESS(err); |
| 4378 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 4379 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4380 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 4381 | pipeline_layout_ci.pNext = NULL; |
| 4382 | pipeline_layout_ci.setLayoutCount = 1; |
| 4383 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 4384 | |
| 4385 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4386 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 4387 | &pipeline_layout); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 4388 | ASSERT_VK_SUCCESS(err); |
| 4389 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4390 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 4391 | VK_SHADER_STAGE_VERTEX_BIT, this); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 4392 | // 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] | 4393 | // on more devices |
| 4394 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 4395 | VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 4396 | |
Tony Barbour | c95e4ac | 2015-08-04 17:05:26 -0600 | [diff] [blame] | 4397 | VkPipelineObj pipe(m_device); |
| 4398 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 4399 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 4400 | pipe.AddColorAttachment(); |
Tony Barbour | c95e4ac | 2015-08-04 17:05:26 -0600 | [diff] [blame] | 4401 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 4402 | |
| 4403 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4404 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 4405 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 4406 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 4407 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 4408 | 1, &descriptorSet, 0, NULL); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 4409 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4410 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 4411 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 4412 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 4413 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 4414 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 4415 | } |
| 4416 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4417 | TEST_F(VkLayerTest, InvalidBufferViewObject) { |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 4418 | // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4419 | VkResult err; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 4420 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4421 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 4422 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempted write update to texel buffer " |
| 4423 | "descriptor with invalid buffer view"); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 4424 | |
| 4425 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4426 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4427 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 4428 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 4429 | |
| 4430 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4431 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 4432 | ds_pool_ci.pNext = NULL; |
| 4433 | ds_pool_ci.maxSets = 1; |
| 4434 | ds_pool_ci.poolSizeCount = 1; |
| 4435 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 4436 | |
| 4437 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4438 | err = |
| 4439 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 4440 | ASSERT_VK_SUCCESS(err); |
| 4441 | |
| 4442 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4443 | dsl_binding.binding = 0; |
| 4444 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 4445 | dsl_binding.descriptorCount = 1; |
| 4446 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 4447 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 4448 | |
| 4449 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4450 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4451 | ds_layout_ci.pNext = NULL; |
| 4452 | ds_layout_ci.bindingCount = 1; |
| 4453 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 4454 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4455 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 4456 | &ds_layout); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 4457 | ASSERT_VK_SUCCESS(err); |
| 4458 | |
| 4459 | VkDescriptorSet descriptorSet; |
| 4460 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 4461 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4462 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 4463 | alloc_info.descriptorPool = ds_pool; |
| 4464 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4465 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 4466 | &descriptorSet); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 4467 | ASSERT_VK_SUCCESS(err); |
| 4468 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4469 | VkBufferView view = |
| 4470 | (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 4471 | VkWriteDescriptorSet descriptor_write; |
| 4472 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 4473 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 4474 | descriptor_write.dstSet = descriptorSet; |
| 4475 | descriptor_write.dstBinding = 0; |
| 4476 | descriptor_write.descriptorCount = 1; |
| 4477 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER; |
| 4478 | descriptor_write.pTexelBufferView = &view; |
| 4479 | |
| 4480 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 4481 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4482 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 4483 | |
| 4484 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 4485 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 4486 | } |
| 4487 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4488 | TEST_F(VkLayerTest, InvalidDynamicOffsetCases) { |
| 4489 | // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error |
| 4490 | // cases: |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 4491 | // 1. No dynamicOffset supplied |
| 4492 | // 2. Too many dynamicOffsets supplied |
| 4493 | // 3. Dynamic offset oversteps buffer being updated |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4494 | VkResult err; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 4495 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4496 | " requires 1 dynamicOffsets, but only " |
| 4497 | "0 dynamicOffsets are left in " |
| 4498 | "pDynamicOffsets "); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 4499 | |
| 4500 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4501 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 4502 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 4503 | |
| 4504 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4505 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 4506 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 4507 | |
| 4508 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4509 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 4510 | ds_pool_ci.pNext = NULL; |
| 4511 | ds_pool_ci.maxSets = 1; |
| 4512 | ds_pool_ci.poolSizeCount = 1; |
| 4513 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 4514 | |
| 4515 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4516 | err = |
| 4517 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 4518 | ASSERT_VK_SUCCESS(err); |
| 4519 | |
| 4520 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4521 | dsl_binding.binding = 0; |
| 4522 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 4523 | dsl_binding.descriptorCount = 1; |
| 4524 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 4525 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 4526 | |
| 4527 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4528 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 4529 | ds_layout_ci.pNext = NULL; |
| 4530 | ds_layout_ci.bindingCount = 1; |
| 4531 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 4532 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4533 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 4534 | &ds_layout); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 4535 | ASSERT_VK_SUCCESS(err); |
| 4536 | |
| 4537 | VkDescriptorSet descriptorSet; |
| 4538 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 4539 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 4540 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 4541 | alloc_info.descriptorPool = ds_pool; |
| 4542 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4543 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 4544 | &descriptorSet); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 4545 | ASSERT_VK_SUCCESS(err); |
| 4546 | |
| 4547 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4548 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 4549 | pipeline_layout_ci.pNext = NULL; |
| 4550 | pipeline_layout_ci.setLayoutCount = 1; |
| 4551 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 4552 | |
| 4553 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4554 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 4555 | &pipeline_layout); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 4556 | ASSERT_VK_SUCCESS(err); |
| 4557 | |
| 4558 | // Create a buffer to update the descriptor with |
| 4559 | uint32_t qfi = 0; |
| 4560 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4561 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 4562 | buffCI.size = 1024; |
| 4563 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 4564 | buffCI.queueFamilyIndexCount = 1; |
| 4565 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 4566 | |
| 4567 | VkBuffer dyub; |
| 4568 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 4569 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 4570 | // Allocate memory and bind to buffer so we can make it to the appropriate |
| 4571 | // error |
| 4572 | VkMemoryAllocateInfo mem_alloc = {}; |
| 4573 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 4574 | mem_alloc.pNext = NULL; |
| 4575 | mem_alloc.allocationSize = 1024; |
Chris Forbes | b6116cc | 2016-05-08 11:39:59 +1200 | [diff] [blame] | 4576 | mem_alloc.memoryTypeIndex = 0; |
| 4577 | |
| 4578 | VkMemoryRequirements memReqs; |
| 4579 | vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs); |
| 4580 | bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, |
| 4581 | 0); |
| 4582 | if (!pass) { |
| 4583 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
| 4584 | return; |
| 4585 | } |
| 4586 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 4587 | VkDeviceMemory mem; |
| 4588 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem); |
| 4589 | ASSERT_VK_SUCCESS(err); |
| 4590 | err = vkBindBufferMemory(m_device->device(), dyub, mem, 0); |
| 4591 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 4592 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 4593 | VkDescriptorBufferInfo buffInfo = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4594 | buffInfo.buffer = dyub; |
| 4595 | buffInfo.offset = 0; |
| 4596 | buffInfo.range = 1024; |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 4597 | |
| 4598 | VkWriteDescriptorSet descriptor_write; |
| 4599 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 4600 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 4601 | descriptor_write.dstSet = descriptorSet; |
| 4602 | descriptor_write.dstBinding = 0; |
| 4603 | descriptor_write.descriptorCount = 1; |
| 4604 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; |
| 4605 | descriptor_write.pBufferInfo = &buffInfo; |
| 4606 | |
| 4607 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 4608 | |
| 4609 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4610 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 4611 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 4612 | 1, &descriptorSet, 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4613 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 4614 | uint32_t pDynOff[2] = {512, 756}; |
| 4615 | // 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] | 4616 | m_errorMonitor->SetDesiredFailureMsg( |
| 4617 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 4618 | "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4619 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 4620 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 4621 | 1, &descriptorSet, 2, pDynOff); |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 4622 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 4623 | // Finally cause error due to dynamicOffset being too big |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 4624 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4625 | " dynamic offset 512 combined with " |
| 4626 | "offset 0 and range 1024 that " |
| 4627 | "oversteps the buffer size of 1024"); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 4628 | // Create PSO to be used for draw-time errors below |
| 4629 | char const *vsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 4630 | "#version 450\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 4631 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 4632 | "out gl_PerVertex { \n" |
| 4633 | " vec4 gl_Position;\n" |
| 4634 | "};\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 4635 | "void main(){\n" |
| 4636 | " gl_Position = vec4(1);\n" |
| 4637 | "}\n"; |
| 4638 | char const *fsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 4639 | "#version 450\n" |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 4640 | "\n" |
| 4641 | "layout(location=0) out vec4 x;\n" |
| 4642 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 4643 | "void main(){\n" |
| 4644 | " x = vec4(bar.y);\n" |
| 4645 | "}\n"; |
| 4646 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 4647 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 4648 | VkPipelineObj pipe(m_device); |
| 4649 | pipe.AddShader(&vs); |
| 4650 | pipe.AddShader(&fs); |
| 4651 | pipe.AddColorAttachment(); |
| 4652 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 4653 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 4654 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 4655 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 4656 | // This update should succeed, but offset size of 512 will overstep buffer |
| 4657 | // /w range 1024 & size 1024 |
| 4658 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 4659 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 4660 | 1, &descriptorSet, 1, pDynOff); |
Tobin Ehlis | f658505 | 2015-12-17 11:48:42 -0700 | [diff] [blame] | 4661 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4662 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 4663 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 4664 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
Tobin Ehlis | 512098e | 2016-05-05 09:06:12 -0600 | [diff] [blame] | 4665 | vkFreeMemory(m_device->device(), mem, NULL); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 4666 | |
Tobin Ehlis | 49f903e | 2015-11-04 13:30:34 -0700 | [diff] [blame] | 4667 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 4668 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 4669 | } |
| 4670 | |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 4671 | TEST_F(VkLayerTest, InvalidPushConstants) { |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 4672 | VkResult err; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 4673 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 4674 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 4675 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 4676 | |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 4677 | VkPipelineLayout pipeline_layout; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 4678 | VkPushConstantRange pc_range = {}; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 4679 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 4680 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 4681 | pipeline_layout_ci.pushConstantRangeCount = 1; |
| 4682 | pipeline_layout_ci.pPushConstantRanges = &pc_range; |
| 4683 | |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 4684 | // |
| 4685 | // Check for invalid push constant ranges in pipeline layouts. |
| 4686 | // |
| 4687 | struct PipelineLayoutTestCase { |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 4688 | VkPushConstantRange const range; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 4689 | char const *msg; |
| 4690 | }; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 4691 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 4692 | const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4; |
| 4693 | const std::array<PipelineLayoutTestCase, 10> range_tests = {{ |
| 4694 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, |
| 4695 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 4696 | "size 0."}, |
| 4697 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1}, |
| 4698 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 4699 | "size 1."}, |
| 4700 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1}, |
| 4701 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 4702 | "size 1."}, |
| 4703 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0}, |
| 4704 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 4705 | "size 0."}, |
| 4706 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4}, |
| 4707 | "vkCreatePipelineLayout() call has push constants index 0 with " |
| 4708 | "offset 1. Offset must"}, |
| 4709 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big}, |
| 4710 | "vkCreatePipelineLayout() call has push constants index 0 " |
| 4711 | "with offset "}, |
| 4712 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big}, |
| 4713 | "vkCreatePipelineLayout() call has push constants " |
| 4714 | "index 0 with offset "}, |
| 4715 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0}, |
| 4716 | "vkCreatePipelineLayout() call has push constants index 0 " |
| 4717 | "with offset "}, |
| 4718 | {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020}, |
| 4719 | "vkCreatePipelineLayout() call has push " |
| 4720 | "constants index 0 with offset "}, |
| 4721 | {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0}, |
| 4722 | "vkCreatePipelineLayout() call has push " |
| 4723 | "constants index 0 with offset "}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 4724 | }}; |
| 4725 | |
| 4726 | // Check for invalid offset and size |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 4727 | for (const auto &iter : range_tests) { |
| 4728 | pc_range = iter.range; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 4729 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4730 | iter.msg); |
| 4731 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 4732 | NULL, &pipeline_layout); |
| 4733 | m_errorMonitor->VerifyFound(); |
| 4734 | if (VK_SUCCESS == err) { |
| 4735 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 4736 | } |
| 4737 | } |
| 4738 | |
| 4739 | // Check for invalid stage flag |
| 4740 | pc_range.offset = 0; |
| 4741 | pc_range.size = 16; |
| 4742 | pc_range.stageFlags = 0; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 4743 | m_errorMonitor->SetDesiredFailureMsg( |
| 4744 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 4745 | "vkCreatePipelineLayout() call has no stageFlags set."); |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 4746 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 4747 | &pipeline_layout); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4748 | m_errorMonitor->VerifyFound(); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 4749 | if (VK_SUCCESS == err) { |
| 4750 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 4751 | } |
| 4752 | |
| 4753 | // Check for overlapping ranges |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 4754 | const uint32_t ranges_per_test = 5; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 4755 | struct OverlappingRangeTestCase { |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 4756 | VkPushConstantRange const ranges[ranges_per_test]; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 4757 | char const *msg; |
| 4758 | }; |
| 4759 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 4760 | const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 4761 | {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 4762 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 4763 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 4764 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 4765 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 4766 | "vkCreatePipelineLayout() call has push constants with overlapping " |
| 4767 | "ranges: 0:[0, 4), 1:[0, 4)"}, |
| 4768 | { |
| 4769 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 4770 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 4771 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 4772 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 4773 | {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}}, |
| 4774 | "vkCreatePipelineLayout() call has push constants with " |
| 4775 | "overlapping " |
| 4776 | "ranges: 3:[12, 20), 4:[16, 20)", |
| 4777 | }, |
| 4778 | { |
| 4779 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 4780 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 4781 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 4782 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 4783 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 4784 | "vkCreatePipelineLayout() call has push constants with " |
| 4785 | "overlapping " |
| 4786 | "ranges: 0:[16, 20), 1:[12, 20)", |
| 4787 | }, |
| 4788 | { |
| 4789 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 4790 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 4791 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 4792 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 8}, |
| 4793 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 4794 | "vkCreatePipelineLayout() call has push constants with " |
| 4795 | "overlapping " |
| 4796 | "ranges: 0:[16, 20), 3:[12, 20)", |
| 4797 | }, |
| 4798 | { |
| 4799 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 4800 | {VK_SHADER_STAGE_VERTEX_BIT, 32, 4}, |
| 4801 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 96}, |
| 4802 | {VK_SHADER_STAGE_VERTEX_BIT, 40, 8}, |
| 4803 | {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}}, |
| 4804 | "vkCreatePipelineLayout() call has push constants with " |
| 4805 | "overlapping " |
| 4806 | "ranges: 0:[16, 20), 2:[4, 100)", |
| 4807 | }}}; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 4808 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 4809 | for (const auto &iter : overlapping_range_tests) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 4810 | pipeline_layout_ci.pPushConstantRanges = iter.ranges; |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 4811 | pipeline_layout_ci.pushConstantRangeCount = ranges_per_test; |
| 4812 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 4813 | iter.msg); |
| 4814 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 4815 | NULL, &pipeline_layout); |
| 4816 | m_errorMonitor->VerifyFound(); |
| 4817 | if (VK_SUCCESS == err) { |
| 4818 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 4819 | } |
| 4820 | } |
| 4821 | |
| 4822 | // 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] | 4823 | const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = |
| 4824 | {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 4825 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 4}, |
| 4826 | {VK_SHADER_STAGE_VERTEX_BIT, 8, 4}, |
| 4827 | {VK_SHADER_STAGE_VERTEX_BIT, 12, 4}, |
| 4828 | {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}}, |
| 4829 | ""}, |
| 4830 | {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24}, |
| 4831 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 4}, |
| 4832 | {VK_SHADER_STAGE_VERTEX_BIT, 64, 8}, |
| 4833 | {VK_SHADER_STAGE_VERTEX_BIT, 4, 16}, |
| 4834 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}}, |
| 4835 | ""}}}; |
| 4836 | for (const auto &iter : overlapping_range_tests_pos) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 4837 | pipeline_layout_ci.pPushConstantRanges = iter.ranges; |
| 4838 | m_errorMonitor->ExpectSuccess(); |
| 4839 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, |
| 4840 | NULL, &pipeline_layout); |
| 4841 | m_errorMonitor->VerifyNotFound(); |
| 4842 | if (VK_SUCCESS == err) { |
| 4843 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 4844 | } |
| 4845 | } |
| 4846 | |
| 4847 | // |
| 4848 | // CmdPushConstants tests |
| 4849 | // |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 4850 | const uint8_t dummy_values[100] = {}; |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 4851 | |
| 4852 | // 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] | 4853 | const std::array<PipelineLayoutTestCase, 16> cmd_range_tests = {{ |
| 4854 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, |
| 4855 | "vkCmdPushConstants() call has push constants with size 0. Size " |
| 4856 | "must be greater than zero and a multiple of 4."}, |
| 4857 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1}, |
| 4858 | "vkCmdPushConstants() call has push constants with size 1. Size " |
| 4859 | "must be greater than zero and a multiple of 4."}, |
| 4860 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 1}, |
| 4861 | "vkCmdPushConstants() call has push constants with size 1. Size " |
| 4862 | "must be greater than zero and a multiple of 4."}, |
| 4863 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 0}, |
| 4864 | "vkCmdPushConstants() call has push constants with offset 1. " |
| 4865 | "Offset must be a multiple of 4."}, |
| 4866 | {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4}, |
| 4867 | "vkCmdPushConstants() call has push constants with offset 1. " |
| 4868 | "Offset must be a multiple of 4."}, |
| 4869 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20}, |
| 4870 | "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = " |
| 4871 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 4872 | {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8}, |
| 4873 | "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = " |
| 4874 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 4875 | {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8}, |
| 4876 | "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = " |
| 4877 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 4878 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80}, |
| 4879 | "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = " |
| 4880 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 4881 | {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4}, |
| 4882 | "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in " |
| 4883 | "any of the ranges in pipeline layout"}, |
| 4884 | {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, |
| 4885 | 0, 16}, |
| 4886 | "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in " |
| 4887 | "any of the ranges in pipeline layout"}, |
| 4888 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 4889 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 4890 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 4891 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 4892 | {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 0}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 4893 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 4894 | {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 4895 | "vkCmdPushConstants() call has push constants with offset "}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 4896 | {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 4897 | "vkCmdPushConstants() call has push constants with offset "}, |
| 4898 | }}; |
| 4899 | |
| 4900 | // Two ranges for testing robustness |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 4901 | const VkPushConstantRange pc_range2[] = { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 4902 | {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 4903 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 4904 | }; |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 4905 | pipeline_layout_ci.pushConstantRangeCount = |
| 4906 | sizeof(pc_range2) / sizeof(VkPushConstantRange); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 4907 | pipeline_layout_ci.pPushConstantRanges = pc_range2; |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 4908 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 4909 | &pipeline_layout); |
| 4910 | ASSERT_VK_SUCCESS(err); |
| 4911 | BeginCommandBuffer(); |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 4912 | for (const auto &iter : cmd_range_tests) { |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 4913 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4914 | iter.msg); |
| 4915 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 4916 | iter.range.stageFlags, iter.range.offset, |
| 4917 | iter.range.size, dummy_values); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 4918 | m_errorMonitor->VerifyFound(); |
| 4919 | } |
| 4920 | |
| 4921 | // Check for invalid stage flag |
| 4922 | m_errorMonitor->SetDesiredFailureMsg( |
| 4923 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4924 | "vkCmdPushConstants() call has no stageFlags set."); |
| 4925 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 4926 | 0, 16, dummy_values); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 4927 | m_errorMonitor->VerifyFound(); |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 4928 | EndCommandBuffer(); |
| 4929 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
| 4930 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
Karl Schultz | fc8eaf1 | 2016-05-06 13:56:42 -0600 | [diff] [blame] | 4931 | |
Karl Schultz | c81037d | 2016-05-12 08:11:23 -0600 | [diff] [blame] | 4932 | // overlapping range tests with cmd |
| 4933 | const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{ |
| 4934 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20}, |
| 4935 | "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = " |
| 4936 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 4937 | {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4}, |
| 4938 | "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = " |
| 4939 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 4940 | {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16}, |
| 4941 | "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = " |
| 4942 | "0x1 not within flag-matching ranges in pipeline layout"}, |
| 4943 | }}; |
| 4944 | const VkPushConstantRange pc_range3[] = { |
| 4945 | {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, |
| 4946 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
| 4947 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 4948 | {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, |
| 4949 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, |
| 4950 | {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, |
| 4951 | {VK_SHADER_STAGE_VERTEX_BIT, 56, 28}, |
| 4952 | }; |
| 4953 | pipeline_layout_ci.pushConstantRangeCount = |
| 4954 | sizeof(pc_range3) / sizeof(VkPushConstantRange); |
| 4955 | pipeline_layout_ci.pPushConstantRanges = pc_range3; |
| 4956 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 4957 | &pipeline_layout); |
| 4958 | ASSERT_VK_SUCCESS(err); |
| 4959 | BeginCommandBuffer(); |
| 4960 | for (const auto &iter : cmd_overlap_tests) { |
| 4961 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 4962 | iter.msg); |
| 4963 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
| 4964 | iter.range.stageFlags, iter.range.offset, |
| 4965 | iter.range.size, dummy_values); |
| 4966 | m_errorMonitor->VerifyFound(); |
| 4967 | } |
| 4968 | EndCommandBuffer(); |
| 4969 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
| 4970 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 4971 | |
| 4972 | // positive overlapping range tests with cmd |
| 4973 | const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{ |
| 4974 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""}, |
| 4975 | {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""}, |
| 4976 | {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""}, |
| 4977 | {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""}, |
| 4978 | }}; |
| 4979 | const VkPushConstantRange pc_range4[] = { |
| 4980 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 64}, |
| 4981 | {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, |
| 4982 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, |
| 4983 | {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, |
| 4984 | {VK_SHADER_STAGE_VERTEX_BIT, 44, 8}, |
| 4985 | {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, |
| 4986 | {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, |
| 4987 | {VK_SHADER_STAGE_VERTEX_BIT, 56, 28}, |
| 4988 | }; |
| 4989 | pipeline_layout_ci.pushConstantRangeCount = |
| 4990 | sizeof(pc_range4) / sizeof(VkPushConstantRange); |
| 4991 | pipeline_layout_ci.pPushConstantRanges = pc_range4; |
| 4992 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 4993 | &pipeline_layout); |
| 4994 | ASSERT_VK_SUCCESS(err); |
| 4995 | BeginCommandBuffer(); |
| 4996 | for (const auto &iter : cmd_overlap_tests_pos) { |
| 4997 | m_errorMonitor->ExpectSuccess(); |
| 4998 | vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, |
| 4999 | iter.range.stageFlags, iter.range.offset, |
| 5000 | iter.range.size, dummy_values); |
| 5001 | m_errorMonitor->VerifyNotFound(); |
| 5002 | } |
| 5003 | EndCommandBuffer(); |
| 5004 | vkResetCommandBuffer(m_commandBuffer->GetBufferHandle(), 0); |
Tobin Ehlis | 3a23b6a | 2016-02-17 10:35:18 -0700 | [diff] [blame] | 5005 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5006 | } |
| 5007 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5008 | TEST_F(VkLayerTest, DescriptorSetCompatibility) { |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5009 | // Test various desriptorSet errors with bad binding combinations |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5010 | VkResult err; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5011 | |
| 5012 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5013 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 5014 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 5015 | |
| 5016 | static const uint32_t NUM_DESCRIPTOR_TYPES = 5; |
| 5017 | VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5018 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5019 | ds_type_count[0].descriptorCount = 10; |
| 5020 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 5021 | ds_type_count[1].descriptorCount = 2; |
| 5022 | ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
| 5023 | ds_type_count[2].descriptorCount = 2; |
| 5024 | ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 5025 | ds_type_count[3].descriptorCount = 5; |
| 5026 | // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT |
| 5027 | // type |
| 5028 | // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; |
| 5029 | ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
| 5030 | ds_type_count[4].descriptorCount = 2; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5031 | |
| 5032 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5033 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5034 | ds_pool_ci.pNext = NULL; |
| 5035 | ds_pool_ci.maxSets = 5; |
| 5036 | ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES; |
| 5037 | ds_pool_ci.pPoolSizes = ds_type_count; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5038 | |
| 5039 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5040 | err = |
| 5041 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5042 | ASSERT_VK_SUCCESS(err); |
| 5043 | |
| 5044 | static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2; |
| 5045 | VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5046 | dsl_binding[0].binding = 0; |
| 5047 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5048 | dsl_binding[0].descriptorCount = 5; |
| 5049 | dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 5050 | dsl_binding[0].pImmutableSamplers = NULL; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5051 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5052 | // Create layout identical to set0 layout but w/ different stageFlags |
| 5053 | VkDescriptorSetLayoutBinding dsl_fs_stage_only = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5054 | dsl_fs_stage_only.binding = 0; |
| 5055 | dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5056 | dsl_fs_stage_only.descriptorCount = 5; |
| 5057 | dsl_fs_stage_only.stageFlags = |
| 5058 | VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at |
| 5059 | // bind time |
| 5060 | dsl_fs_stage_only.pImmutableSamplers = NULL; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5061 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5062 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5063 | ds_layout_ci.pNext = NULL; |
| 5064 | ds_layout_ci.bindingCount = 1; |
| 5065 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5066 | static const uint32_t NUM_LAYOUTS = 4; |
| 5067 | VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5068 | VkDescriptorSetLayout ds_layout_fs_only = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5069 | // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only |
| 5070 | // layout for error case |
| 5071 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5072 | &ds_layout[0]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5073 | ASSERT_VK_SUCCESS(err); |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 5074 | ds_layout_ci.pBindings = &dsl_fs_stage_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5075 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5076 | &ds_layout_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5077 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5078 | dsl_binding[0].binding = 0; |
| 5079 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5080 | dsl_binding[0].descriptorCount = 2; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 5081 | dsl_binding[1].binding = 1; |
| 5082 | dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
| 5083 | dsl_binding[1].descriptorCount = 2; |
| 5084 | dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL; |
| 5085 | dsl_binding[1].pImmutableSamplers = NULL; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 5086 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5087 | ds_layout_ci.bindingCount = 2; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5088 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5089 | &ds_layout[1]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5090 | ASSERT_VK_SUCCESS(err); |
| 5091 | dsl_binding[0].binding = 0; |
| 5092 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5093 | dsl_binding[0].descriptorCount = 5; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5094 | ds_layout_ci.bindingCount = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5095 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5096 | &ds_layout[2]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5097 | ASSERT_VK_SUCCESS(err); |
| 5098 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5099 | dsl_binding[0].descriptorCount = 2; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5100 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5101 | &ds_layout[3]); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5102 | ASSERT_VK_SUCCESS(err); |
| 5103 | |
| 5104 | static const uint32_t NUM_SETS = 4; |
| 5105 | VkDescriptorSet descriptorSet[NUM_SETS] = {}; |
| 5106 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5107 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5108 | alloc_info.descriptorSetCount = NUM_LAYOUTS; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5109 | alloc_info.descriptorPool = ds_pool; |
| 5110 | alloc_info.pSetLayouts = ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5111 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5112 | descriptorSet); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5113 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5114 | VkDescriptorSet ds0_fs_only = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5115 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5116 | alloc_info.pSetLayouts = &ds_layout_fs_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5117 | err = |
| 5118 | vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5119 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5120 | |
| 5121 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5122 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5123 | pipeline_layout_ci.pNext = NULL; |
| 5124 | pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS; |
| 5125 | pipeline_layout_ci.pSetLayouts = ds_layout; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5126 | |
| 5127 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5128 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5129 | &pipeline_layout); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5130 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5131 | // Create pipelineLayout with only one setLayout |
| 5132 | pipeline_layout_ci.setLayoutCount = 1; |
| 5133 | VkPipelineLayout single_pipe_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5134 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5135 | &single_pipe_layout); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5136 | ASSERT_VK_SUCCESS(err); |
| 5137 | // Create pipelineLayout with 2 descriptor setLayout at index 0 |
| 5138 | pipeline_layout_ci.pSetLayouts = &ds_layout[3]; |
| 5139 | VkPipelineLayout pipe_layout_one_desc; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5140 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5141 | &pipe_layout_one_desc); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5142 | ASSERT_VK_SUCCESS(err); |
| 5143 | // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0 |
| 5144 | pipeline_layout_ci.pSetLayouts = &ds_layout[2]; |
| 5145 | VkPipelineLayout pipe_layout_five_samp; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5146 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5147 | &pipe_layout_five_samp); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5148 | ASSERT_VK_SUCCESS(err); |
| 5149 | // Create pipelineLayout with UB type, but stageFlags for FS only |
| 5150 | pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only; |
| 5151 | VkPipelineLayout pipe_layout_fs_only; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5152 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5153 | &pipe_layout_fs_only); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5154 | ASSERT_VK_SUCCESS(err); |
| 5155 | // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine |
| 5156 | VkDescriptorSetLayout pl_bad_s0[2] = {}; |
| 5157 | pl_bad_s0[0] = ds_layout_fs_only; |
| 5158 | pl_bad_s0[1] = ds_layout[1]; |
| 5159 | pipeline_layout_ci.setLayoutCount = 2; |
| 5160 | pipeline_layout_ci.pSetLayouts = pl_bad_s0; |
| 5161 | VkPipelineLayout pipe_layout_bad_set0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5162 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5163 | &pipe_layout_bad_set0); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5164 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5165 | |
| 5166 | // Create a buffer to update the descriptor with |
| 5167 | uint32_t qfi = 0; |
| 5168 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5169 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 5170 | buffCI.size = 1024; |
| 5171 | buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| 5172 | buffCI.queueFamilyIndexCount = 1; |
| 5173 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5174 | |
| 5175 | VkBuffer dyub; |
| 5176 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub); |
| 5177 | ASSERT_VK_SUCCESS(err); |
| 5178 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 5179 | static const uint32_t NUM_BUFFS = 5; |
| 5180 | VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5181 | for (uint32_t i = 0; i < NUM_BUFFS; ++i) { |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5182 | buffInfo[i].buffer = dyub; |
| 5183 | buffInfo[i].offset = 0; |
| 5184 | buffInfo[i].range = 1024; |
| 5185 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5186 | VkImage image; |
| 5187 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 5188 | const int32_t tex_width = 32; |
| 5189 | const int32_t tex_height = 32; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5190 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5191 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 5192 | image_create_info.pNext = NULL; |
| 5193 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 5194 | image_create_info.format = tex_format; |
| 5195 | image_create_info.extent.width = tex_width; |
| 5196 | image_create_info.extent.height = tex_height; |
| 5197 | image_create_info.extent.depth = 1; |
| 5198 | image_create_info.mipLevels = 1; |
| 5199 | image_create_info.arrayLayers = 1; |
| 5200 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 5201 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 5202 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 5203 | image_create_info.flags = 0; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5204 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 5205 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5206 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5207 | VkMemoryRequirements memReqs; |
| 5208 | VkDeviceMemory imageMem; |
| 5209 | bool pass; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 5210 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5211 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 5212 | memAlloc.pNext = NULL; |
| 5213 | memAlloc.allocationSize = 0; |
| 5214 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 5215 | vkGetImageMemoryRequirements(m_device->device(), image, &memReqs); |
| 5216 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5217 | pass = |
| 5218 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Mike Stroyan | 9c70cdb | 2016-01-06 14:14:17 -0700 | [diff] [blame] | 5219 | ASSERT_TRUE(pass); |
| 5220 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem); |
| 5221 | ASSERT_VK_SUCCESS(err); |
| 5222 | err = vkBindImageMemory(m_device->device(), image, imageMem, 0); |
| 5223 | ASSERT_VK_SUCCESS(err); |
| 5224 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5225 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5226 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 5227 | image_view_create_info.image = image; |
| 5228 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 5229 | image_view_create_info.format = tex_format; |
| 5230 | image_view_create_info.subresourceRange.layerCount = 1; |
| 5231 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 5232 | image_view_create_info.subresourceRange.levelCount = 1; |
| 5233 | image_view_create_info.subresourceRange.aspectMask = |
| 5234 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5235 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5236 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5237 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 5238 | &view); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5239 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 5240 | VkDescriptorImageInfo imageInfo[4] = {}; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5241 | imageInfo[0].imageView = view; |
| 5242 | imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 5243 | imageInfo[1].imageView = view; |
| 5244 | imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 5245 | imageInfo[2].imageView = view; |
| 5246 | imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
| 5247 | imageInfo[3].imageView = view; |
| 5248 | imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5249 | |
| 5250 | static const uint32_t NUM_SET_UPDATES = 3; |
| 5251 | VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {}; |
| 5252 | descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5253 | descriptor_write[0].dstSet = descriptorSet[0]; |
| 5254 | descriptor_write[0].dstBinding = 0; |
| 5255 | descriptor_write[0].descriptorCount = 5; |
| 5256 | descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5257 | descriptor_write[0].pBufferInfo = buffInfo; |
| 5258 | descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5259 | descriptor_write[1].dstSet = descriptorSet[1]; |
| 5260 | descriptor_write[1].dstBinding = 0; |
| 5261 | descriptor_write[1].descriptorCount = 2; |
| 5262 | descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 5263 | descriptor_write[1].pImageInfo = imageInfo; |
| 5264 | descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 5265 | descriptor_write[2].dstSet = descriptorSet[1]; |
| 5266 | descriptor_write[2].dstBinding = 1; |
| 5267 | descriptor_write[2].descriptorCount = 2; |
| 5268 | descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 5269 | descriptor_write[2].pImageInfo = &imageInfo[2]; |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5270 | |
| 5271 | vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5272 | |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 5273 | // Create PSO to be used for draw-time errors below |
| 5274 | char const *vsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5275 | "#version 450\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 5276 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 5277 | "out gl_PerVertex {\n" |
| 5278 | " vec4 gl_Position;\n" |
| 5279 | "};\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 5280 | "void main(){\n" |
| 5281 | " gl_Position = vec4(1);\n" |
| 5282 | "}\n"; |
| 5283 | char const *fsSource = |
Chris Forbes | 7b34280 | 2016-04-07 13:20:10 +1200 | [diff] [blame] | 5284 | "#version 450\n" |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 5285 | "\n" |
| 5286 | "layout(location=0) out vec4 x;\n" |
| 5287 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 5288 | "void main(){\n" |
| 5289 | " x = vec4(bar.y);\n" |
| 5290 | "}\n"; |
| 5291 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 5292 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5293 | VkPipelineObj pipe(m_device); |
| 5294 | pipe.AddShader(&vs); |
| 5295 | pipe.AddShader(&fs); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 5296 | pipe.AddColorAttachment(); |
| 5297 | pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass()); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5298 | |
| 5299 | BeginCommandBuffer(); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 5300 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5301 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 5302 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 5303 | // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding |
| 5304 | // of PSO |
| 5305 | // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of |
| 5306 | // cmd_pipeline.c |
| 5307 | // due to the fact that cmd_alloc_dset_data() has not been called in |
| 5308 | // cmd_bind_graphics_pipeline() |
| 5309 | // TODO : Want to cause various binding incompatibility issues here to test |
| 5310 | // DrawState |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5311 | // First cause various verify_layout_compatibility() fails |
| 5312 | // Second disturb early and late sets and verify INFO msgs |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5313 | // verify_set_layout_compatibility fail cases: |
| 5314 | // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5315 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5316 | " due to: invalid VkPipelineLayout "); |
| 5317 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5318 | VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 5319 | (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, |
| 5320 | &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5321 | m_errorMonitor->VerifyFound(); |
| 5322 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5323 | // 2. layoutIndex exceeds # of layouts in layout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5324 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5325 | " attempting to bind set to index 1"); |
| 5326 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5327 | VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, |
| 5328 | 0, 2, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5329 | m_errorMonitor->VerifyFound(); |
| 5330 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5331 | vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5332 | // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5 |
| 5333 | // descriptors |
| 5334 | m_errorMonitor->SetDesiredFailureMsg( |
| 5335 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 5336 | " has 2 descriptors, but DescriptorSetLayout "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5337 | vkCmdBindDescriptorSets( |
| 5338 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 5339 | pipe_layout_one_desc, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5340 | m_errorMonitor->VerifyFound(); |
| 5341 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5342 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL); |
| 5343 | // 4. same # of descriptors but mismatch in type |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5344 | m_errorMonitor->SetDesiredFailureMsg( |
| 5345 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 5346 | " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5347 | vkCmdBindDescriptorSets( |
| 5348 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 5349 | pipe_layout_five_samp, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5350 | m_errorMonitor->VerifyFound(); |
| 5351 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5352 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL); |
| 5353 | // 5. same # of descriptors but mismatch in stageFlags |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5354 | m_errorMonitor->SetDesiredFailureMsg( |
| 5355 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 5356 | " has stageFlags 16 but binding 0 for DescriptorSetLayout "); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5357 | vkCmdBindDescriptorSets( |
| 5358 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 5359 | pipe_layout_fs_only, 0, 1, &descriptorSet[0], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5360 | m_errorMonitor->VerifyFound(); |
| 5361 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5362 | // Cause INFO messages due to disturbing previously bound Sets |
| 5363 | // First bind sets 0 & 1 |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5364 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5365 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5366 | 2, &descriptorSet[0], 0, NULL); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5367 | // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5368 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 5369 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5370 | " previously bound as set #0 was disturbed "); |
| 5371 | vkCmdBindDescriptorSets( |
| 5372 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 5373 | pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5374 | m_errorMonitor->VerifyFound(); |
| 5375 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5376 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5377 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5378 | 2, &descriptorSet[0], 0, NULL); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5379 | // 2. Disturb set after last bound set |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 5380 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5381 | " newly bound as set #0 so set #1 and " |
| 5382 | "any subsequent sets were disturbed "); |
| 5383 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5384 | VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 5385 | pipe_layout_fs_only, 0, 1, &ds0_fs_only, 0, NULL); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5386 | m_errorMonitor->VerifyFound(); |
| 5387 | |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 5388 | // Cause draw-time errors due to PSO incompatibilities |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5389 | // 1. Error due to not binding required set (we actually use same code as |
| 5390 | // above to disturb set0) |
| 5391 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5392 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5393 | 2, &descriptorSet[0], 0, NULL); |
| 5394 | vkCmdBindDescriptorSets( |
| 5395 | m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 5396 | pipe_layout_bad_set0, 1, 1, &descriptorSet[1], 0, NULL); |
| 5397 | m_errorMonitor->SetDesiredFailureMsg( |
| 5398 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5399 | " uses set #0 but that set is not bound."); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 5400 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5401 | m_errorMonitor->VerifyFound(); |
| 5402 | |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 5403 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5404 | // 2. Error due to bound set not being compatible with PSO's |
| 5405 | // VkPipelineLayout (diff stageFlags in this case) |
| 5406 | vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), |
| 5407 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, |
| 5408 | 2, &descriptorSet[0], 0, NULL); |
| 5409 | m_errorMonitor->SetDesiredFailureMsg( |
| 5410 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5411 | " bound as set #0 is not compatible with "); |
Tobin Ehlis | 8845283 | 2015-12-03 09:40:56 -0700 | [diff] [blame] | 5412 | Draw(1, 0, 0, 0); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5413 | m_errorMonitor->VerifyFound(); |
| 5414 | |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5415 | // Remaining clean-up |
| 5416 | vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5417 | for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) { |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5418 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL); |
| 5419 | } |
| 5420 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL); |
Tobin Ehlis | 9bfd449 | 2016-05-05 15:09:11 -0600 | [diff] [blame] | 5421 | vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &ds0_fs_only); |
| 5422 | vkFreeDescriptorSets(m_device->device(), ds_pool, NUM_SETS, descriptorSet); |
Tobin Ehlis | 8fab656 | 2015-12-01 09:57:09 -0700 | [diff] [blame] | 5423 | vkDestroyBuffer(m_device->device(), dyub, NULL); |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5424 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5425 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 5426 | } |
Tobin Ehlis | 559c638 | 2015-11-05 09:52:49 -0700 | [diff] [blame] | 5427 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5428 | TEST_F(VkLayerTest, NoBeginCommandBuffer) { |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5429 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5430 | m_errorMonitor->SetDesiredFailureMsg( |
| 5431 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5432 | "You must call vkBeginCommandBuffer() before this call to "); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 5433 | |
| 5434 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5435 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 5436 | // Call EndCommandBuffer() w/o calling BeginCommandBuffer() |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5437 | vkEndCommandBuffer(commandBuffer.GetBufferHandle()); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5438 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5439 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 5440 | } |
| 5441 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5442 | TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) { |
| 5443 | VkResult err; |
| 5444 | VkCommandBuffer draw_cmd; |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5445 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5446 | m_errorMonitor->SetDesiredFailureMsg( |
| 5447 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 61b36f3 | 2015-12-16 08:19:42 -0700 | [diff] [blame] | 5448 | " must specify a valid renderpass parameter."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5449 | |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 5450 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 5451 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5452 | VkCommandBufferAllocateInfo cmd = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5453 | cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 5454 | cmd.pNext = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5455 | cmd.commandPool = m_commandPool; |
| 5456 | cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5457 | cmd.commandBufferCount = 1; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 5458 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5459 | err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 5460 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 5461 | |
| 5462 | // Force the failure by not setting the Renderpass and Framebuffer fields |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5463 | VkCommandBufferBeginInfo cmd_buf_info = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5464 | VkCommandBufferInheritanceInfo cmd_buf_hinfo = {}; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5465 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
Cody Northrop | b456970 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 5466 | cmd_buf_info.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5467 | cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | |
| 5468 | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5469 | cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo; |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 5470 | |
| 5471 | // The error should be caught by validation of the BeginCommandBuffer call |
| 5472 | vkBeginCommandBuffer(draw_cmd, &cmd_buf_info); |
| 5473 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5474 | m_errorMonitor->VerifyFound(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5475 | vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd); |
Mark Lobodzinski | d9139a6 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 5476 | } |
| 5477 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5478 | TEST_F(VkLayerTest, CommandBufferResetErrors) { |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 5479 | // Cause error due to Begin while recording CB |
| 5480 | // Then cause 2 errors for attempting to reset CB w/o having |
| 5481 | // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from |
| 5482 | // which CBs were allocated. Note that this bit is off by default. |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 5483 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5484 | "Cannot call Begin on CB"); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 5485 | |
| 5486 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5487 | |
| 5488 | // Calls AllocateCommandBuffers |
| 5489 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
| 5490 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5491 | // Force the failure by setting the Renderpass and Framebuffer fields with |
| 5492 | // (fake) data |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 5493 | VkCommandBufferBeginInfo cmd_buf_info = {}; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5494 | VkCommandBufferInheritanceInfo cmd_buf_hinfo = {}; |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 5495 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 5496 | cmd_buf_info.pNext = NULL; |
| 5497 | cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5498 | cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo; |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 5499 | |
| 5500 | // Begin CB to transition to recording state |
| 5501 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
| 5502 | // Can't re-begin. This should trigger error |
| 5503 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5504 | m_errorMonitor->VerifyFound(); |
| 5505 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5506 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5507 | "Attempt to reset command buffer "); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 5508 | VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test |
| 5509 | // Reset attempt will trigger error due to incorrect CommandPool state |
| 5510 | vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5511 | m_errorMonitor->VerifyFound(); |
| 5512 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5513 | m_errorMonitor->SetDesiredFailureMsg( |
| 5514 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 5515 | " attempts to implicitly reset cmdBuffer created from "); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 5516 | // Transition CB to RECORDED state |
| 5517 | vkEndCommandBuffer(commandBuffer.GetBufferHandle()); |
| 5518 | // Now attempting to Begin will implicitly reset, which triggers error |
| 5519 | vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5520 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | ac0ef84 | 2015-12-14 13:46:38 -0700 | [diff] [blame] | 5521 | } |
| 5522 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5523 | TEST_F(VkLayerTest, InvalidPipelineCreateState) { |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 5524 | // Attempt to Create Gfx Pipeline w/o a VS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5525 | VkResult err; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 5526 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5527 | m_errorMonitor->SetDesiredFailureMsg( |
| 5528 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5529 | "Invalid Pipeline CreateInfo State: Vtx Shader required"); |
| 5530 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 5531 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 5532 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 5533 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 5534 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5535 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5536 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5537 | |
| 5538 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5539 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5540 | ds_pool_ci.pNext = NULL; |
| 5541 | ds_pool_ci.maxSets = 1; |
| 5542 | ds_pool_ci.poolSizeCount = 1; |
| 5543 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 5544 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 5545 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5546 | err = |
| 5547 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 5548 | ASSERT_VK_SUCCESS(err); |
| 5549 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5550 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5551 | dsl_binding.binding = 0; |
| 5552 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5553 | dsl_binding.descriptorCount = 1; |
| 5554 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5555 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 5556 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5557 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5558 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5559 | ds_layout_ci.pNext = NULL; |
| 5560 | ds_layout_ci.bindingCount = 1; |
| 5561 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5562 | |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 5563 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5564 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5565 | &ds_layout); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 5566 | ASSERT_VK_SUCCESS(err); |
| 5567 | |
| 5568 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5569 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5570 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5571 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 5572 | alloc_info.descriptorPool = ds_pool; |
| 5573 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5574 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5575 | &descriptorSet); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 5576 | ASSERT_VK_SUCCESS(err); |
| 5577 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5578 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5579 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5580 | pipeline_layout_ci.setLayoutCount = 1; |
| 5581 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 5582 | |
| 5583 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5584 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5585 | &pipeline_layout); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 5586 | ASSERT_VK_SUCCESS(err); |
| 5587 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5588 | VkViewport vp = {}; // Just need dummy vp to point to |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5589 | VkRect2D sc = {}; // dummy scissor to point to |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5590 | |
| 5591 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5592 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 5593 | vp_state_ci.scissorCount = 1; |
| 5594 | vp_state_ci.pScissors = ≻ |
| 5595 | vp_state_ci.viewportCount = 1; |
| 5596 | vp_state_ci.pViewports = &vp; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5597 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 5598 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 5599 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 5600 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 5601 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 5602 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 5603 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 5604 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 5605 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 5606 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5607 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5608 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 5609 | gp_ci.pViewportState = &vp_state_ci; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 5610 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5611 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 5612 | gp_ci.layout = pipeline_layout; |
| 5613 | gp_ci.renderPass = renderPass(); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 5614 | |
| 5615 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5616 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 5617 | pc_ci.initialDataSize = 0; |
| 5618 | pc_ci.pInitialData = 0; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 5619 | |
| 5620 | VkPipeline pipeline; |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 5621 | VkPipelineCache pipelineCache; |
| 5622 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5623 | err = |
| 5624 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Jon Ashburn | c669cc6 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 5625 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5626 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 5627 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | 7d1a711 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 5628 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5629 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 5630 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 5631 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 5632 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5633 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5634 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 5635 | } |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 5636 | /*// TODO : This test should be good, but needs Tess support in compiler to run |
| 5637 | TEST_F(VkLayerTest, InvalidPatchControlPoints) |
| 5638 | { |
| 5639 | // Attempt to Create Gfx Pipeline w/o a VS |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 5640 | VkResult err; |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 5641 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 5642 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5643 | "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH |
| 5644 | primitive "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5645 | |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 5646 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5647 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 5648 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 5649 | VkDescriptorPoolSize ds_type_count = {}; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 5650 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 5651 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 5652 | |
| 5653 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 5654 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5655 | ds_pool_ci.pNext = NULL; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 5656 | ds_pool_ci.poolSizeCount = 1; |
| 5657 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 5658 | |
| 5659 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5660 | err = vkCreateDescriptorPool(m_device->device(), |
| 5661 | 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] | 5662 | ASSERT_VK_SUCCESS(err); |
| 5663 | |
| 5664 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 5665 | dsl_binding.binding = 0; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 5666 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | 0212448 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 5667 | dsl_binding.descriptorCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 5668 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 5669 | dsl_binding.pImmutableSamplers = NULL; |
| 5670 | |
| 5671 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5672 | ds_layout_ci.sType = |
| 5673 | VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 5674 | ds_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 5675 | ds_layout_ci.bindingCount = 1; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 5676 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 5677 | |
| 5678 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5679 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5680 | &ds_layout); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 5681 | ASSERT_VK_SUCCESS(err); |
| 5682 | |
| 5683 | VkDescriptorSet descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5684 | err = vkAllocateDescriptorSets(m_device->device(), ds_pool, |
| 5685 | VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 5686 | ASSERT_VK_SUCCESS(err); |
| 5687 | |
| 5688 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5689 | pipeline_layout_ci.sType = |
| 5690 | VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 5691 | pipeline_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 5692 | pipeline_layout_ci.setLayoutCount = 1; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 5693 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 5694 | |
| 5695 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5696 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5697 | &pipeline_layout); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 5698 | ASSERT_VK_SUCCESS(err); |
| 5699 | |
| 5700 | VkPipelineShaderStageCreateInfo shaderStages[3]; |
| 5701 | memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 5702 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5703 | VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT, |
| 5704 | this); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 5705 | // 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] | 5706 | VkShaderObj |
| 5707 | tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, |
| 5708 | this); |
| 5709 | VkShaderObj |
| 5710 | te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, |
| 5711 | this); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 5712 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5713 | shaderStages[0].sType = |
| 5714 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 5715 | shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 5716 | shaderStages[0].shader = vs.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5717 | shaderStages[1].sType = |
| 5718 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 5719 | shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 5720 | shaderStages[1].shader = tc.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5721 | shaderStages[2].sType = |
| 5722 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 5723 | shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 5724 | shaderStages[2].shader = te.handle(); |
| 5725 | |
| 5726 | VkPipelineInputAssemblyStateCreateInfo iaCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5727 | iaCI.sType = |
| 5728 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
Chia-I Wu | 515eb8f | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 5729 | iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 5730 | |
| 5731 | VkPipelineTessellationStateCreateInfo tsCI = {}; |
| 5732 | tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO; |
| 5733 | tsCI.patchControlPoints = 0; // This will cause an error |
| 5734 | |
| 5735 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 5736 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 5737 | gp_ci.pNext = NULL; |
| 5738 | gp_ci.stageCount = 3; |
| 5739 | gp_ci.pStages = shaderStages; |
| 5740 | gp_ci.pVertexInputState = NULL; |
| 5741 | gp_ci.pInputAssemblyState = &iaCI; |
| 5742 | gp_ci.pTessellationState = &tsCI; |
| 5743 | gp_ci.pViewportState = NULL; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5744 | gp_ci.pRasterizationState = NULL; |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 5745 | gp_ci.pMultisampleState = NULL; |
| 5746 | gp_ci.pDepthStencilState = NULL; |
| 5747 | gp_ci.pColorBlendState = NULL; |
| 5748 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 5749 | gp_ci.layout = pipeline_layout; |
| 5750 | gp_ci.renderPass = renderPass(); |
| 5751 | |
| 5752 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 5753 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 5754 | pc_ci.pNext = NULL; |
| 5755 | pc_ci.initialSize = 0; |
| 5756 | pc_ci.initialData = 0; |
| 5757 | pc_ci.maxSize = 0; |
| 5758 | |
| 5759 | VkPipeline pipeline; |
| 5760 | VkPipelineCache pipelineCache; |
| 5761 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5762 | err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, |
| 5763 | &pipelineCache); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 5764 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5765 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 5766 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 5767 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5768 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 5769 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 5770 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 5771 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5772 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5773 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 912df02 | 2015-09-17 08:46:18 -0600 | [diff] [blame] | 5774 | } |
| 5775 | */ |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5776 | // Set scissor and viewport counts to different numbers |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5777 | TEST_F(VkLayerTest, PSOViewportScissorCountMismatch) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5778 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5779 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5780 | m_errorMonitor->SetDesiredFailureMsg( |
| 5781 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5782 | "Gfx Pipeline viewport count (1) must match scissor count (0)."); |
| 5783 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5784 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5785 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5786 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 5787 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5788 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5789 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5790 | |
| 5791 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5792 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5793 | ds_pool_ci.maxSets = 1; |
| 5794 | ds_pool_ci.poolSizeCount = 1; |
| 5795 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5796 | |
| 5797 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5798 | err = |
| 5799 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5800 | ASSERT_VK_SUCCESS(err); |
| 5801 | |
| 5802 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5803 | dsl_binding.binding = 0; |
| 5804 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5805 | dsl_binding.descriptorCount = 1; |
| 5806 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5807 | |
| 5808 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5809 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5810 | ds_layout_ci.bindingCount = 1; |
| 5811 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5812 | |
| 5813 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5814 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5815 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5816 | ASSERT_VK_SUCCESS(err); |
| 5817 | |
| 5818 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5819 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5820 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5821 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 5822 | alloc_info.descriptorPool = ds_pool; |
| 5823 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5824 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5825 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5826 | ASSERT_VK_SUCCESS(err); |
| 5827 | |
| 5828 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5829 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5830 | pipeline_layout_ci.setLayoutCount = 1; |
| 5831 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5832 | |
| 5833 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5834 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5835 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5836 | ASSERT_VK_SUCCESS(err); |
| 5837 | |
| 5838 | VkViewport vp = {}; // Just need dummy vp to point to |
| 5839 | |
| 5840 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5841 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 5842 | vp_state_ci.scissorCount = 0; |
| 5843 | vp_state_ci.viewportCount = 1; // Count mismatch should cause error |
| 5844 | vp_state_ci.pViewports = &vp; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5845 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 5846 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 5847 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 5848 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 5849 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 5850 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 5851 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 5852 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 5853 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 5854 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 5855 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5856 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5857 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5858 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 5859 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 5860 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 5861 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5862 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5863 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 5864 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 5865 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5866 | |
| 5867 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5868 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 5869 | gp_ci.stageCount = 2; |
| 5870 | gp_ci.pStages = shaderStages; |
| 5871 | gp_ci.pViewportState = &vp_state_ci; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 5872 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5873 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 5874 | gp_ci.layout = pipeline_layout; |
| 5875 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5876 | |
| 5877 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5878 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5879 | |
| 5880 | VkPipeline pipeline; |
| 5881 | VkPipelineCache pipelineCache; |
| 5882 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5883 | err = |
| 5884 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5885 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5886 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 5887 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5888 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 5889 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5890 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 5891 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 5892 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 5893 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 5894 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5895 | } |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5896 | // Don't set viewport state in PSO. This is an error b/c we always need this |
| 5897 | // state |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 5898 | // 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] | 5899 | TEST_F(VkLayerTest, PSOViewportStateNotSet) { |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5900 | // Attempt to Create Gfx Pipeline w/o a VS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5901 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5902 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5903 | m_errorMonitor->SetDesiredFailureMsg( |
| 5904 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 5905 | "Gfx Pipeline pViewportState is null. Even if "); |
| 5906 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5907 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 5908 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5909 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 5910 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5911 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5912 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5913 | |
| 5914 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5915 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 5916 | ds_pool_ci.maxSets = 1; |
| 5917 | ds_pool_ci.poolSizeCount = 1; |
| 5918 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5919 | |
| 5920 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5921 | err = |
| 5922 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5923 | ASSERT_VK_SUCCESS(err); |
| 5924 | |
| 5925 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5926 | dsl_binding.binding = 0; |
| 5927 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 5928 | dsl_binding.descriptorCount = 1; |
| 5929 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5930 | |
| 5931 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5932 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 5933 | ds_layout_ci.bindingCount = 1; |
| 5934 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5935 | |
| 5936 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5937 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 5938 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5939 | ASSERT_VK_SUCCESS(err); |
| 5940 | |
| 5941 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 5942 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 5943 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5944 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 5945 | alloc_info.descriptorPool = ds_pool; |
| 5946 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5947 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 5948 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5949 | ASSERT_VK_SUCCESS(err); |
| 5950 | |
| 5951 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5952 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 5953 | pipeline_layout_ci.setLayoutCount = 1; |
| 5954 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5955 | |
| 5956 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5957 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 5958 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5959 | ASSERT_VK_SUCCESS(err); |
| 5960 | |
| 5961 | VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR; |
| 5962 | // Set scissor as dynamic to avoid second error |
| 5963 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5964 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 5965 | dyn_state_ci.dynamicStateCount = 1; |
| 5966 | dyn_state_ci.pDynamicStates = &sc_state; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5967 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 5968 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5969 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5970 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5971 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 5972 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 5973 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 5974 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 5975 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5976 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 5977 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 5978 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5979 | |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 5980 | |
| 5981 | VkPipelineRasterizationStateCreateInfo rs_state_ci = {}; |
| 5982 | rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 5983 | rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL; |
| 5984 | rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT; |
| 5985 | rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 5986 | rs_state_ci.depthClampEnable = VK_FALSE; |
| 5987 | rs_state_ci.rasterizerDiscardEnable = VK_FALSE; |
| 5988 | rs_state_ci.depthBiasEnable = VK_FALSE; |
| 5989 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 5990 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5991 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 5992 | gp_ci.stageCount = 2; |
| 5993 | gp_ci.pStages = shaderStages; |
Karl Schultz | dfdb8d4 | 2016-03-08 10:30:21 -0700 | [diff] [blame] | 5994 | gp_ci.pRasterizationState = &rs_state_ci; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5995 | gp_ci.pViewportState = NULL; // Not setting VP state w/o dynamic vp state |
| 5996 | // should cause validation error |
| 5997 | gp_ci.pDynamicState = &dyn_state_ci; |
| 5998 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 5999 | gp_ci.layout = pipeline_layout; |
| 6000 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6001 | |
| 6002 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6003 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6004 | |
| 6005 | VkPipeline pipeline; |
| 6006 | VkPipelineCache pipelineCache; |
| 6007 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6008 | err = |
| 6009 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6010 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6011 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6012 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6013 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6014 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6015 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6016 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6017 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6018 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6019 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6020 | } |
| 6021 | // Create PSO w/o non-zero viewportCount but no viewport data |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6022 | // Then run second test where dynamic scissor count doesn't match PSO scissor |
| 6023 | // count |
| 6024 | TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) { |
| 6025 | VkResult err; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6026 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6027 | m_errorMonitor->SetDesiredFailureMsg( |
| 6028 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6029 | "Gfx Pipeline viewportCount is 1, but pViewports is NULL. "); |
| 6030 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6031 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6032 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6033 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6034 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6035 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6036 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6037 | |
| 6038 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6039 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6040 | ds_pool_ci.maxSets = 1; |
| 6041 | ds_pool_ci.poolSizeCount = 1; |
| 6042 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6043 | |
| 6044 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6045 | err = |
| 6046 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6047 | ASSERT_VK_SUCCESS(err); |
| 6048 | |
| 6049 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6050 | dsl_binding.binding = 0; |
| 6051 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6052 | dsl_binding.descriptorCount = 1; |
| 6053 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6054 | |
| 6055 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6056 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6057 | ds_layout_ci.bindingCount = 1; |
| 6058 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6059 | |
| 6060 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6061 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6062 | &ds_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6063 | ASSERT_VK_SUCCESS(err); |
| 6064 | |
| 6065 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6066 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 6067 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 6068 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 6069 | alloc_info.descriptorPool = ds_pool; |
| 6070 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6071 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6072 | &descriptorSet); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6073 | ASSERT_VK_SUCCESS(err); |
| 6074 | |
| 6075 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6076 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6077 | pipeline_layout_ci.setLayoutCount = 1; |
| 6078 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6079 | |
| 6080 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6081 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6082 | &pipeline_layout); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6083 | ASSERT_VK_SUCCESS(err); |
| 6084 | |
| 6085 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6086 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 6087 | vp_state_ci.viewportCount = 1; |
| 6088 | vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error |
| 6089 | vp_state_ci.scissorCount = 1; |
| 6090 | vp_state_ci.pScissors = |
| 6091 | NULL; // Scissor is dynamic (below) so this won't cause error |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6092 | |
| 6093 | VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR; |
| 6094 | // Set scissor as dynamic to avoid that error |
| 6095 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6096 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 6097 | dyn_state_ci.dynamicStateCount = 1; |
| 6098 | dyn_state_ci.pDynamicStates = &sc_state; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6099 | |
Cody Northrop | eb3a6c1 | 2015-10-05 14:44:45 -0600 | [diff] [blame] | 6100 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6101 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6102 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6103 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 6104 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6105 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 6106 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6107 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6108 | // but add it to be able to run on more devices |
Chia-I Wu | 28e0691 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 6109 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 6110 | shaderStages[1] = fs.GetStageCreateInfo(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6111 | |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6112 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 6113 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 6114 | vi_ci.pNext = nullptr; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6115 | vi_ci.vertexBindingDescriptionCount = 0; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6116 | vi_ci.pVertexBindingDescriptions = nullptr; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 6117 | vi_ci.vertexAttributeDescriptionCount = 0; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6118 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 6119 | |
| 6120 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 6121 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 6122 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 6123 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6124 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 6125 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6126 | rs_ci.pNext = nullptr; |
| 6127 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 6128 | VkPipelineColorBlendAttachmentState att = {}; |
| 6129 | att.blendEnable = VK_FALSE; |
| 6130 | att.colorWriteMask = 0xf; |
| 6131 | |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6132 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 6133 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 6134 | cb_ci.pNext = nullptr; |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 6135 | cb_ci.attachmentCount = 1; |
| 6136 | cb_ci.pAttachments = &att; |
Cody Northrop | f6622dc | 2015-10-06 10:33:21 -0600 | [diff] [blame] | 6137 | |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6138 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6139 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6140 | gp_ci.stageCount = 2; |
| 6141 | gp_ci.pStages = shaderStages; |
| 6142 | gp_ci.pVertexInputState = &vi_ci; |
| 6143 | gp_ci.pInputAssemblyState = &ia_ci; |
| 6144 | gp_ci.pViewportState = &vp_state_ci; |
| 6145 | gp_ci.pRasterizationState = &rs_ci; |
| 6146 | gp_ci.pColorBlendState = &cb_ci; |
| 6147 | gp_ci.pDynamicState = &dyn_state_ci; |
| 6148 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6149 | gp_ci.layout = pipeline_layout; |
| 6150 | gp_ci.renderPass = renderPass(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6151 | |
| 6152 | VkPipelineCacheCreateInfo pc_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6153 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6154 | |
| 6155 | VkPipeline pipeline; |
| 6156 | VkPipelineCache pipelineCache; |
| 6157 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6158 | err = |
| 6159 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6160 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6161 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6162 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6163 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6164 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6165 | |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 6166 | // 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] | 6167 | // First need to successfully create the PSO from above by setting |
| 6168 | // pViewports |
| 6169 | m_errorMonitor->SetDesiredFailureMsg( |
| 6170 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6171 | "Dynamic scissorCount from vkCmdSetScissor() is 2, but PSO " |
| 6172 | "scissorCount is 1. These counts must match."); |
| 6173 | |
| 6174 | VkViewport vp = {}; // Just need dummy vp to point to |
| 6175 | vp_state_ci.pViewports = &vp; |
| 6176 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6177 | &gp_ci, NULL, &pipeline); |
| 6178 | ASSERT_VK_SUCCESS(err); |
| 6179 | BeginCommandBuffer(); |
| 6180 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 6181 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 6182 | VkRect2D scissors[2] = {}; // don't care about data |
| 6183 | // Count of 2 doesn't match PSO count of 1 |
| 6184 | vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 0, 2, scissors); |
| 6185 | Draw(1, 0, 0, 0); |
| 6186 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6187 | m_errorMonitor->VerifyFound(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6188 | |
| 6189 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6190 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6191 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6192 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 6193 | } |
| 6194 | // Create PSO w/o non-zero scissorCount but no scissor data |
| 6195 | // Then run second test where dynamic viewportCount doesn't match PSO |
| 6196 | // viewportCount |
| 6197 | TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) { |
| 6198 | VkResult err; |
| 6199 | |
| 6200 | m_errorMonitor->SetDesiredFailureMsg( |
| 6201 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6202 | "Gfx Pipeline scissorCount is 1, but pScissors is NULL. "); |
| 6203 | |
| 6204 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6205 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 6206 | |
| 6207 | VkDescriptorPoolSize ds_type_count = {}; |
| 6208 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6209 | ds_type_count.descriptorCount = 1; |
| 6210 | |
| 6211 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 6212 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6213 | ds_pool_ci.maxSets = 1; |
| 6214 | ds_pool_ci.poolSizeCount = 1; |
| 6215 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 6216 | |
| 6217 | VkDescriptorPool ds_pool; |
| 6218 | err = |
| 6219 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 6220 | ASSERT_VK_SUCCESS(err); |
| 6221 | |
| 6222 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 6223 | dsl_binding.binding = 0; |
| 6224 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6225 | dsl_binding.descriptorCount = 1; |
| 6226 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 6227 | |
| 6228 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 6229 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6230 | ds_layout_ci.bindingCount = 1; |
| 6231 | ds_layout_ci.pBindings = &dsl_binding; |
| 6232 | |
| 6233 | VkDescriptorSetLayout ds_layout; |
| 6234 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6235 | &ds_layout); |
| 6236 | ASSERT_VK_SUCCESS(err); |
| 6237 | |
| 6238 | VkDescriptorSet descriptorSet; |
| 6239 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 6240 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 6241 | alloc_info.descriptorSetCount = 1; |
| 6242 | alloc_info.descriptorPool = ds_pool; |
| 6243 | alloc_info.pSetLayouts = &ds_layout; |
| 6244 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6245 | &descriptorSet); |
| 6246 | ASSERT_VK_SUCCESS(err); |
| 6247 | |
| 6248 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 6249 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6250 | pipeline_layout_ci.setLayoutCount = 1; |
| 6251 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 6252 | |
| 6253 | VkPipelineLayout pipeline_layout; |
| 6254 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6255 | &pipeline_layout); |
| 6256 | ASSERT_VK_SUCCESS(err); |
| 6257 | |
| 6258 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 6259 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 6260 | vp_state_ci.scissorCount = 1; |
| 6261 | vp_state_ci.pScissors = |
| 6262 | NULL; // Null scissor w/ count of 1 should cause error |
| 6263 | vp_state_ci.viewportCount = 1; |
| 6264 | vp_state_ci.pViewports = |
| 6265 | NULL; // vp is dynamic (below) so this won't cause error |
| 6266 | |
| 6267 | VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT; |
| 6268 | // Set scissor as dynamic to avoid that error |
| 6269 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
| 6270 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 6271 | dyn_state_ci.dynamicStateCount = 1; |
| 6272 | dyn_state_ci.pDynamicStates = &vp_state; |
| 6273 | |
| 6274 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
| 6275 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 6276 | |
| 6277 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 6278 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6279 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 6280 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 6281 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6282 | // but add it to be able to run on more devices |
| 6283 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 6284 | shaderStages[1] = fs.GetStageCreateInfo(); |
| 6285 | |
| 6286 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 6287 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 6288 | vi_ci.pNext = nullptr; |
| 6289 | vi_ci.vertexBindingDescriptionCount = 0; |
| 6290 | vi_ci.pVertexBindingDescriptions = nullptr; |
| 6291 | vi_ci.vertexAttributeDescriptionCount = 0; |
| 6292 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 6293 | |
| 6294 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 6295 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 6296 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 6297 | |
| 6298 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
| 6299 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 6300 | rs_ci.pNext = nullptr; |
| 6301 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 6302 | VkPipelineColorBlendAttachmentState att = {}; |
| 6303 | att.blendEnable = VK_FALSE; |
| 6304 | att.colorWriteMask = 0xf; |
| 6305 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6306 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 6307 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 6308 | cb_ci.pNext = nullptr; |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 6309 | cb_ci.attachmentCount = 1; |
| 6310 | cb_ci.pAttachments = &att; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6311 | |
| 6312 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 6313 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6314 | gp_ci.stageCount = 2; |
| 6315 | gp_ci.pStages = shaderStages; |
| 6316 | gp_ci.pVertexInputState = &vi_ci; |
| 6317 | gp_ci.pInputAssemblyState = &ia_ci; |
| 6318 | gp_ci.pViewportState = &vp_state_ci; |
| 6319 | gp_ci.pRasterizationState = &rs_ci; |
| 6320 | gp_ci.pColorBlendState = &cb_ci; |
| 6321 | gp_ci.pDynamicState = &dyn_state_ci; |
| 6322 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6323 | gp_ci.layout = pipeline_layout; |
| 6324 | gp_ci.renderPass = renderPass(); |
| 6325 | |
| 6326 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 6327 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 6328 | |
| 6329 | VkPipeline pipeline; |
| 6330 | VkPipelineCache pipelineCache; |
| 6331 | |
| 6332 | err = |
| 6333 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 6334 | ASSERT_VK_SUCCESS(err); |
| 6335 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6336 | &gp_ci, NULL, &pipeline); |
| 6337 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6338 | m_errorMonitor->VerifyFound(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6339 | |
| 6340 | // Now hit second fail case where we set scissor w/ different count than PSO |
| 6341 | // First need to successfully create the PSO from above by setting |
| 6342 | // pViewports |
| 6343 | m_errorMonitor->SetDesiredFailureMsg( |
| 6344 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6345 | "Dynamic viewportCount from vkCmdSetViewport() is 2, but PSO " |
| 6346 | "viewportCount is 1. These counts must match."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6347 | |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 6348 | VkRect2D sc = {}; // Just need dummy vp to point to |
| 6349 | vp_state_ci.pScissors = ≻ |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6350 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6351 | &gp_ci, NULL, &pipeline); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 6352 | ASSERT_VK_SUCCESS(err); |
| 6353 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6354 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 6355 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 6356 | VkViewport viewports[2] = {}; // don't care about data |
| 6357 | // Count of 2 doesn't match PSO count of 1 |
Jon Ashburn | 19d3bf1 | 2015-12-30 14:06:55 -0700 | [diff] [blame] | 6358 | vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 0, 2, viewports); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 6359 | Draw(1, 0, 0, 0); |
| 6360 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6361 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6362 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6363 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6364 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6365 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6366 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | e68360f | 2015-10-01 11:15:13 -0600 | [diff] [blame] | 6367 | } |
| 6368 | |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 6369 | TEST_F(VkLayerTest, PSOLineWidthInvalid) { |
| 6370 | VkResult err; |
| 6371 | |
| 6372 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 6373 | "Attempt to set lineWidth to -1"); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 6374 | |
| 6375 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6376 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 6377 | |
| 6378 | VkDescriptorPoolSize ds_type_count = {}; |
| 6379 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6380 | ds_type_count.descriptorCount = 1; |
| 6381 | |
| 6382 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 6383 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 6384 | ds_pool_ci.maxSets = 1; |
| 6385 | ds_pool_ci.poolSizeCount = 1; |
| 6386 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 6387 | |
| 6388 | VkDescriptorPool ds_pool; |
| 6389 | err = |
| 6390 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 6391 | ASSERT_VK_SUCCESS(err); |
| 6392 | |
| 6393 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 6394 | dsl_binding.binding = 0; |
| 6395 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 6396 | dsl_binding.descriptorCount = 1; |
| 6397 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 6398 | |
| 6399 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 6400 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 6401 | ds_layout_ci.bindingCount = 1; |
| 6402 | ds_layout_ci.pBindings = &dsl_binding; |
| 6403 | |
| 6404 | VkDescriptorSetLayout ds_layout; |
| 6405 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 6406 | &ds_layout); |
| 6407 | ASSERT_VK_SUCCESS(err); |
| 6408 | |
| 6409 | VkDescriptorSet descriptorSet; |
| 6410 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 6411 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 6412 | alloc_info.descriptorSetCount = 1; |
| 6413 | alloc_info.descriptorPool = ds_pool; |
| 6414 | alloc_info.pSetLayouts = &ds_layout; |
| 6415 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 6416 | &descriptorSet); |
| 6417 | ASSERT_VK_SUCCESS(err); |
| 6418 | |
| 6419 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 6420 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 6421 | pipeline_layout_ci.setLayoutCount = 1; |
| 6422 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 6423 | |
| 6424 | VkPipelineLayout pipeline_layout; |
| 6425 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 6426 | &pipeline_layout); |
| 6427 | ASSERT_VK_SUCCESS(err); |
| 6428 | |
| 6429 | VkPipelineViewportStateCreateInfo vp_state_ci = {}; |
| 6430 | vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; |
| 6431 | vp_state_ci.scissorCount = 1; |
| 6432 | vp_state_ci.pScissors = NULL; |
| 6433 | vp_state_ci.viewportCount = 1; |
| 6434 | vp_state_ci.pViewports = NULL; |
| 6435 | |
| 6436 | VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, |
| 6437 | VK_DYNAMIC_STATE_SCISSOR, |
| 6438 | VK_DYNAMIC_STATE_LINE_WIDTH}; |
| 6439 | // Set scissor as dynamic to avoid that error |
| 6440 | VkPipelineDynamicStateCreateInfo dyn_state_ci = {}; |
| 6441 | dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; |
| 6442 | dyn_state_ci.dynamicStateCount = 2; |
| 6443 | dyn_state_ci.pDynamicStates = dynamic_states; |
| 6444 | |
| 6445 | VkPipelineShaderStageCreateInfo shaderStages[2]; |
| 6446 | memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo)); |
| 6447 | |
| 6448 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 6449 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 6450 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 6451 | VK_SHADER_STAGE_FRAGMENT_BIT, |
| 6452 | this); // TODO - We shouldn't need a fragment shader |
| 6453 | // but add it to be able to run on more devices |
| 6454 | shaderStages[0] = vs.GetStageCreateInfo(); |
| 6455 | shaderStages[1] = fs.GetStageCreateInfo(); |
| 6456 | |
| 6457 | VkPipelineVertexInputStateCreateInfo vi_ci = {}; |
| 6458 | vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; |
| 6459 | vi_ci.pNext = nullptr; |
| 6460 | vi_ci.vertexBindingDescriptionCount = 0; |
| 6461 | vi_ci.pVertexBindingDescriptions = nullptr; |
| 6462 | vi_ci.vertexAttributeDescriptionCount = 0; |
| 6463 | vi_ci.pVertexAttributeDescriptions = nullptr; |
| 6464 | |
| 6465 | VkPipelineInputAssemblyStateCreateInfo ia_ci = {}; |
| 6466 | ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; |
| 6467 | ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 6468 | |
| 6469 | VkPipelineRasterizationStateCreateInfo rs_ci = {}; |
| 6470 | rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; |
| 6471 | rs_ci.pNext = nullptr; |
| 6472 | |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 6473 | // Check too low (line width of -1.0f). |
| 6474 | rs_ci.lineWidth = -1.0f; |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 6475 | |
| 6476 | VkPipelineColorBlendAttachmentState att = {}; |
| 6477 | att.blendEnable = VK_FALSE; |
| 6478 | att.colorWriteMask = 0xf; |
| 6479 | |
| 6480 | VkPipelineColorBlendStateCreateInfo cb_ci = {}; |
| 6481 | cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; |
| 6482 | cb_ci.pNext = nullptr; |
| 6483 | cb_ci.attachmentCount = 1; |
| 6484 | cb_ci.pAttachments = &att; |
| 6485 | |
| 6486 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 6487 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 6488 | gp_ci.stageCount = 2; |
| 6489 | gp_ci.pStages = shaderStages; |
| 6490 | gp_ci.pVertexInputState = &vi_ci; |
| 6491 | gp_ci.pInputAssemblyState = &ia_ci; |
| 6492 | gp_ci.pViewportState = &vp_state_ci; |
| 6493 | gp_ci.pRasterizationState = &rs_ci; |
| 6494 | gp_ci.pColorBlendState = &cb_ci; |
| 6495 | gp_ci.pDynamicState = &dyn_state_ci; |
| 6496 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 6497 | gp_ci.layout = pipeline_layout; |
| 6498 | gp_ci.renderPass = renderPass(); |
| 6499 | |
| 6500 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 6501 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 6502 | |
| 6503 | VkPipeline pipeline; |
| 6504 | VkPipelineCache pipelineCache; |
| 6505 | |
| 6506 | err = |
| 6507 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 6508 | ASSERT_VK_SUCCESS(err); |
| 6509 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6510 | &gp_ci, NULL, &pipeline); |
| 6511 | |
| 6512 | m_errorMonitor->VerifyFound(); |
| 6513 | |
| 6514 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6515 | "Attempt to set lineWidth to 65536"); |
| 6516 | |
| 6517 | // Check too high (line width of 65536.0f). |
| 6518 | rs_ci.lineWidth = 65536.0f; |
| 6519 | |
| 6520 | err = |
| 6521 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 6522 | ASSERT_VK_SUCCESS(err); |
| 6523 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6524 | &gp_ci, NULL, &pipeline); |
| 6525 | |
| 6526 | m_errorMonitor->VerifyFound(); |
| 6527 | |
| 6528 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 6529 | "Attempt to set lineWidth to -1"); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 6530 | |
| 6531 | dyn_state_ci.dynamicStateCount = 3; |
| 6532 | |
| 6533 | rs_ci.lineWidth = 1.0f; |
| 6534 | |
| 6535 | err = |
| 6536 | vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache); |
| 6537 | ASSERT_VK_SUCCESS(err); |
| 6538 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, |
| 6539 | &gp_ci, NULL, &pipeline); |
| 6540 | BeginCommandBuffer(); |
| 6541 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 6542 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 6543 | |
| 6544 | // Check too low with dynamic setting. |
Mark Young | 4710795 | 2016-05-02 15:59:55 -0600 | [diff] [blame] | 6545 | vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f); |
Mark Young | 7394fdd | 2016-03-31 14:56:43 -0600 | [diff] [blame] | 6546 | m_errorMonitor->VerifyFound(); |
| 6547 | |
| 6548 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6549 | "Attempt to set lineWidth to 65536"); |
| 6550 | |
| 6551 | // Check too high with dynamic setting. |
| 6552 | vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f); |
| 6553 | m_errorMonitor->VerifyFound(); |
| 6554 | EndCommandBuffer(); |
| 6555 | |
| 6556 | vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL); |
| 6557 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 6558 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 6559 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 6560 | } |
| 6561 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6562 | TEST_F(VkLayerTest, NullRenderPass) { |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 6563 | // Bind a NULL RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6564 | m_errorMonitor->SetDesiredFailureMsg( |
| 6565 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6566 | "You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()"); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 6567 | |
| 6568 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6569 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 6570 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 6571 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6572 | // Don't care about RenderPass handle b/c error should be flagged before |
| 6573 | // that |
| 6574 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, |
| 6575 | VK_SUBPASS_CONTENTS_INLINE); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 6576 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6577 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 98aa0ed | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 6578 | } |
| 6579 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6580 | TEST_F(VkLayerTest, RenderPassWithinRenderPass) { |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6581 | // Bind a BeginRenderPass within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6582 | m_errorMonitor->SetDesiredFailureMsg( |
| 6583 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6584 | "It is invalid to issue this call inside an active render pass"); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6585 | |
| 6586 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6587 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6588 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 6589 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6590 | // Just create a dummy Renderpass that's non-NULL so we can get to the |
| 6591 | // proper error |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 6592 | VkRenderPassBeginInfo rp_begin = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6593 | rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 6594 | rp_begin.pNext = NULL; |
| 6595 | rp_begin.renderPass = renderPass(); |
| 6596 | rp_begin.framebuffer = framebuffer(); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 6597 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6598 | vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, |
| 6599 | VK_SUBPASS_CONTENTS_INLINE); |
Tobin Ehlis | af1f3a4 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 6600 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6601 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 6602 | } |
| 6603 | |
Cody Northrop | 3bb4d96 | 2016-05-09 16:15:57 -0600 | [diff] [blame] | 6604 | TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) { |
| 6605 | |
| 6606 | TEST_DESCRIPTION("End a command buffer with an active render pass"); |
| 6607 | |
| 6608 | m_errorMonitor->SetDesiredFailureMsg( |
| 6609 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6610 | "It is invalid to issue this call inside an active render pass"); |
| 6611 | |
| 6612 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6613 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 6614 | |
| 6615 | // The framework's BeginCommandBuffer calls CreateRenderPass |
| 6616 | BeginCommandBuffer(); |
| 6617 | |
| 6618 | // Call directly into vkEndCommandBuffer instead of the |
| 6619 | // the framework's EndCommandBuffer, which inserts a |
| 6620 | // vkEndRenderPass |
| 6621 | vkEndCommandBuffer(m_commandBuffer->GetBufferHandle()); |
| 6622 | |
| 6623 | m_errorMonitor->VerifyFound(); |
| 6624 | |
| 6625 | // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY |
| 6626 | // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT |
| 6627 | } |
| 6628 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6629 | TEST_F(VkLayerTest, FillBufferWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6630 | // Call CmdFillBuffer within an active renderpass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6631 | m_errorMonitor->SetDesiredFailureMsg( |
| 6632 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6633 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6634 | |
| 6635 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6636 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6637 | |
| 6638 | // Renderpass is started here |
| 6639 | BeginCommandBuffer(); |
| 6640 | |
| 6641 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6642 | vk_testing::Buffer dstBuffer; |
| 6643 | dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6644 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6645 | m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6646 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6647 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6648 | } |
| 6649 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6650 | TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6651 | // Call CmdUpdateBuffer within an active renderpass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6652 | m_errorMonitor->SetDesiredFailureMsg( |
| 6653 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6654 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6655 | |
| 6656 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6657 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6658 | |
| 6659 | // Renderpass is started here |
| 6660 | BeginCommandBuffer(); |
| 6661 | |
| 6662 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6663 | vk_testing::Buffer dstBuffer; |
| 6664 | dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6665 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6666 | VkDeviceSize dstOffset = 0; |
| 6667 | VkDeviceSize dataSize = 1024; |
| 6668 | const uint32_t *pData = NULL; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6669 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6670 | vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), |
| 6671 | dstOffset, dataSize, pData); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6672 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6673 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6674 | } |
| 6675 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6676 | TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6677 | // Call CmdClearColorImage within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6678 | m_errorMonitor->SetDesiredFailureMsg( |
| 6679 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6680 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6681 | |
| 6682 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6683 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6684 | |
| 6685 | // Renderpass is started here |
| 6686 | BeginCommandBuffer(); |
| 6687 | |
Michael Lentine | 0a369f6 | 2016-02-03 16:51:46 -0600 | [diff] [blame] | 6688 | VkClearColorValue clear_color; |
| 6689 | memset(clear_color.uint32, 0, sizeof(uint32_t) * 4); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6690 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 6691 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 6692 | const int32_t tex_width = 32; |
| 6693 | const int32_t tex_height = 32; |
| 6694 | VkImageCreateInfo image_create_info = {}; |
| 6695 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 6696 | image_create_info.pNext = NULL; |
| 6697 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 6698 | image_create_info.format = tex_format; |
| 6699 | image_create_info.extent.width = tex_width; |
| 6700 | image_create_info.extent.height = tex_height; |
| 6701 | image_create_info.extent.depth = 1; |
| 6702 | image_create_info.mipLevels = 1; |
| 6703 | image_create_info.arrayLayers = 1; |
| 6704 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 6705 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 6706 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6707 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6708 | vk_testing::Image dstImage; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6709 | dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 6710 | reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6711 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6712 | const VkImageSubresourceRange range = vk_testing::Image::subresource_range( |
| 6713 | image_create_info, VK_IMAGE_ASPECT_COLOR_BIT); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6714 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6715 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), |
| 6716 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6717 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6718 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6719 | } |
| 6720 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6721 | TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) { |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6722 | // Call CmdClearDepthStencilImage within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6723 | m_errorMonitor->SetDesiredFailureMsg( |
| 6724 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6725 | "It is invalid to issue this call inside an active render pass"); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6726 | |
| 6727 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6728 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6729 | |
| 6730 | // Renderpass is started here |
| 6731 | BeginCommandBuffer(); |
| 6732 | |
| 6733 | VkClearDepthStencilValue clear_value = {0}; |
Dustin Graves | a2e5c94 | 2016-02-11 18:28:06 -0700 | [diff] [blame] | 6734 | VkMemoryPropertyFlags reqs = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6735 | VkImageCreateInfo image_create_info = vk_testing::Image::create_info(); |
| 6736 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 6737 | image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 6738 | image_create_info.extent.width = 64; |
| 6739 | image_create_info.extent.height = 64; |
| 6740 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 6741 | image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6742 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6743 | vk_testing::Image dstImage; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6744 | dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 6745 | reqs); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6746 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6747 | const VkImageSubresourceRange range = vk_testing::Image::subresource_range( |
| 6748 | image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6749 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6750 | vkCmdClearDepthStencilImage( |
| 6751 | m_commandBuffer->GetBufferHandle(), dstImage.handle(), |
| 6752 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, |
| 6753 | &range); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6754 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6755 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6756 | } |
| 6757 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6758 | TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) { |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 6759 | // Call CmdClearAttachmentss outside of an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6760 | VkResult err; |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6761 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 6762 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6763 | "vkCmdClearAttachments: This call " |
| 6764 | "must be issued inside an active " |
| 6765 | "render pass"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6766 | |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6767 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6768 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6769 | |
| 6770 | // Start no RenderPass |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 6771 | err = m_commandBuffer->BeginCommandBuffer(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6772 | ASSERT_VK_SUCCESS(err); |
| 6773 | |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 6774 | VkClearAttachment color_attachment; |
| 6775 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 6776 | color_attachment.clearValue.color.float32[0] = 0; |
| 6777 | color_attachment.clearValue.color.float32[1] = 0; |
| 6778 | color_attachment.clearValue.color.float32[2] = 0; |
| 6779 | color_attachment.clearValue.color.float32[3] = 0; |
| 6780 | color_attachment.colorAttachment = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6781 | VkClearRect clear_rect = {{{0, 0}, {32, 32}}}; |
| 6782 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 6783 | &color_attachment, 1, &clear_rect); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6784 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6785 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | d563950 | 2015-09-24 09:51:47 -0600 | [diff] [blame] | 6786 | } |
| 6787 | |
Karl Schultz | 9e66a29 | 2016-04-21 15:57:51 -0600 | [diff] [blame] | 6788 | TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) { |
| 6789 | // Try to add a buffer memory barrier with no buffer. |
| 6790 | m_errorMonitor->SetDesiredFailureMsg( |
| 6791 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6792 | "required parameter pBufferMemoryBarriers[i].buffer specified as VK_NULL_HANDLE"); |
| 6793 | |
| 6794 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6795 | BeginCommandBuffer(); |
| 6796 | |
| 6797 | VkBufferMemoryBarrier buf_barrier = {}; |
| 6798 | buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; |
| 6799 | buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 6800 | buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 6801 | buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 6802 | buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 6803 | buf_barrier.buffer = VK_NULL_HANDLE; |
| 6804 | buf_barrier.offset = 0; |
| 6805 | buf_barrier.size = VK_WHOLE_SIZE; |
| 6806 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 6807 | VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, |
| 6808 | 0, 0, nullptr, 1, &buf_barrier, 0, nullptr); |
| 6809 | |
| 6810 | m_errorMonitor->VerifyFound(); |
| 6811 | } |
| 6812 | |
Tony Barbour | 7fd5c0f | 2016-05-03 16:11:53 -0600 | [diff] [blame] | 6813 | TEST_F(VkLayerTest, InvalidBarriers) { |
| 6814 | TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER "); |
| 6815 | |
| 6816 | m_errorMonitor->SetDesiredFailureMsg( |
| 6817 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass"); |
| 6818 | |
| 6819 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6820 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 6821 | |
| 6822 | VkMemoryBarrier mem_barrier = {}; |
| 6823 | mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER; |
| 6824 | mem_barrier.pNext = NULL; |
| 6825 | mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 6826 | mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 6827 | BeginCommandBuffer(); |
| 6828 | // BeginCommandBuffer() starts a render pass |
| 6829 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 6830 | VK_PIPELINE_STAGE_HOST_BIT, |
| 6831 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1, |
| 6832 | &mem_barrier, 0, nullptr, 0, nullptr); |
| 6833 | m_errorMonitor->VerifyFound(); |
| 6834 | |
| 6835 | m_errorMonitor->SetDesiredFailureMsg( |
| 6836 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6837 | "Image Layout cannot be transitioned to UNDEFINED"); |
| 6838 | VkImageObj image(m_device); |
| 6839 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 6840 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0); |
| 6841 | ASSERT_TRUE(image.initialized()); |
| 6842 | VkImageMemoryBarrier img_barrier = {}; |
| 6843 | img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 6844 | img_barrier.pNext = NULL; |
| 6845 | img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 6846 | img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 6847 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 6848 | // New layout can't be UNDEFINED |
| 6849 | img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 6850 | img_barrier.image = image.handle(); |
| 6851 | img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 6852 | img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 6853 | img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 6854 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 6855 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 6856 | img_barrier.subresourceRange.layerCount = 1; |
| 6857 | img_barrier.subresourceRange.levelCount = 1; |
| 6858 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 6859 | VK_PIPELINE_STAGE_HOST_BIT, |
| 6860 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 6861 | nullptr, 1, &img_barrier); |
| 6862 | m_errorMonitor->VerifyFound(); |
| 6863 | img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 6864 | |
| 6865 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6866 | "Subresource must have the sum of the " |
| 6867 | "baseArrayLayer"); |
| 6868 | // baseArrayLayer + layerCount must be <= image's arrayLayers |
| 6869 | img_barrier.subresourceRange.baseArrayLayer = 1; |
| 6870 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 6871 | VK_PIPELINE_STAGE_HOST_BIT, |
| 6872 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 6873 | nullptr, 1, &img_barrier); |
| 6874 | m_errorMonitor->VerifyFound(); |
| 6875 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 6876 | |
| 6877 | m_errorMonitor->SetDesiredFailureMsg( |
| 6878 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6879 | "Subresource must have the sum of the baseMipLevel"); |
| 6880 | // baseMipLevel + levelCount must be <= image's mipLevels |
| 6881 | img_barrier.subresourceRange.baseMipLevel = 1; |
| 6882 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 6883 | VK_PIPELINE_STAGE_HOST_BIT, |
| 6884 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 6885 | nullptr, 1, &img_barrier); |
| 6886 | m_errorMonitor->VerifyFound(); |
| 6887 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 6888 | |
| 6889 | m_errorMonitor->SetDesiredFailureMsg( |
| 6890 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6891 | "Buffer Barriers cannot be used during a render pass"); |
| 6892 | vk_testing::Buffer buffer; |
| 6893 | buffer.init(*m_device, 256); |
| 6894 | VkBufferMemoryBarrier buf_barrier = {}; |
| 6895 | buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; |
| 6896 | buf_barrier.pNext = NULL; |
| 6897 | buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 6898 | buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 6899 | buf_barrier.buffer = buffer.handle(); |
| 6900 | buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 6901 | buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 6902 | buf_barrier.offset = 0; |
| 6903 | buf_barrier.size = VK_WHOLE_SIZE; |
| 6904 | // Can't send buffer barrier during a render pass |
| 6905 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 6906 | VK_PIPELINE_STAGE_HOST_BIT, |
| 6907 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 6908 | &buf_barrier, 0, nullptr); |
| 6909 | m_errorMonitor->VerifyFound(); |
| 6910 | vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); |
| 6911 | |
| 6912 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6913 | "which is not less than total size"); |
| 6914 | buf_barrier.offset = 257; |
| 6915 | // Offset greater than total size |
| 6916 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 6917 | VK_PIPELINE_STAGE_HOST_BIT, |
| 6918 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 6919 | &buf_barrier, 0, nullptr); |
| 6920 | m_errorMonitor->VerifyFound(); |
| 6921 | buf_barrier.offset = 0; |
| 6922 | |
| 6923 | m_errorMonitor->SetDesiredFailureMsg( |
| 6924 | VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size"); |
| 6925 | buf_barrier.size = 257; |
| 6926 | // Size greater than total size |
| 6927 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 6928 | VK_PIPELINE_STAGE_HOST_BIT, |
| 6929 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1, |
| 6930 | &buf_barrier, 0, nullptr); |
| 6931 | m_errorMonitor->VerifyFound(); |
| 6932 | buf_barrier.size = VK_WHOLE_SIZE; |
| 6933 | |
| 6934 | m_errorMonitor->SetDesiredFailureMsg( |
| 6935 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 6936 | "Image is a depth and stencil format and thus must " |
| 6937 | "have both VK_IMAGE_ASPECT_DEPTH_BIT and " |
| 6938 | "VK_IMAGE_ASPECT_STENCIL_BIT set."); |
| 6939 | VkDepthStencilObj ds_image(m_device); |
| 6940 | ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT); |
| 6941 | ASSERT_TRUE(ds_image.initialized()); |
| 6942 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 6943 | img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 6944 | img_barrier.image = ds_image.handle(); |
| 6945 | // Leave aspectMask at COLOR on purpose |
| 6946 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 6947 | VK_PIPELINE_STAGE_HOST_BIT, |
| 6948 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 6949 | nullptr, 1, &img_barrier); |
| 6950 | m_errorMonitor->VerifyFound(); |
| 6951 | } |
| 6952 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6953 | TEST_F(VkLayerTest, IdxBufferAlignmentError) { |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 6954 | // Bind a BeginRenderPass within an active RenderPass |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6955 | VkResult err; |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 6956 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6957 | m_errorMonitor->SetDesiredFailureMsg( |
| 6958 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 6959 | "vkCmdBindIndexBuffer() offset (0x7) does not fall on "); |
| 6960 | |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 6961 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6962 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 6963 | uint32_t qfi = 0; |
| 6964 | VkBufferCreateInfo buffCI = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6965 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 6966 | buffCI.size = 1024; |
| 6967 | buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; |
| 6968 | buffCI.queueFamilyIndexCount = 1; |
| 6969 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 6970 | |
| 6971 | VkBuffer ib; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6972 | err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 6973 | ASSERT_VK_SUCCESS(err); |
| 6974 | |
| 6975 | BeginCommandBuffer(); |
| 6976 | ASSERT_VK_SUCCESS(err); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 6977 | // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 6978 | // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 6979 | // 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] | 6980 | vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, |
| 6981 | VK_INDEX_TYPE_UINT16); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 6982 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 6983 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 6984 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 6985 | vkDestroyBuffer(m_device->device(), ib, NULL); |
Tobin Ehlis | c4c2318 | 2015-09-17 12:24:13 -0600 | [diff] [blame] | 6986 | } |
| 6987 | |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 6988 | TEST_F(VkLayerTest, InvalidQueueFamilyIndex) { |
| 6989 | // Create an out-of-range queueFamilyIndex |
| 6990 | m_errorMonitor->SetDesiredFailureMsg( |
| 6991 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Dustin Graves | de62853 | 2016-04-21 16:30:17 -0600 | [diff] [blame] | 6992 | "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one " |
| 6993 | "of the indices specified when the device was created, via the " |
| 6994 | "VkDeviceQueueCreateInfo structure."); |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 6995 | |
| 6996 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 6997 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 6998 | VkBufferCreateInfo buffCI = {}; |
| 6999 | buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 7000 | buffCI.size = 1024; |
| 7001 | buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT; |
| 7002 | buffCI.queueFamilyIndexCount = 1; |
| 7003 | // Introduce failure by specifying invalid queue_family_index |
| 7004 | uint32_t qfi = 777; |
| 7005 | buffCI.pQueueFamilyIndices = &qfi; |
Tobin Ehlis | 24aab04 | 2016-03-24 10:54:18 -0600 | [diff] [blame] | 7006 | buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 7007 | |
| 7008 | VkBuffer ib; |
| 7009 | vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib); |
| 7010 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7011 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 52a6e7d | 2016-02-25 15:09:52 -0700 | [diff] [blame] | 7012 | } |
| 7013 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7014 | TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) { |
| 7015 | // Attempt vkCmdExecuteCommands w/ a primary cmd buffer (should only be |
| 7016 | // secondary) |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7017 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7018 | m_errorMonitor->SetDesiredFailureMsg( |
| 7019 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7020 | "vkCmdExecuteCommands() called w/ Primary Cmd Buffer "); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 7021 | |
| 7022 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7023 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 7024 | |
| 7025 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7026 | // ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7027 | VkCommandBuffer primCB = m_commandBuffer->GetBufferHandle(); |
| 7028 | vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &primCB); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 7029 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7030 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 4b34ddc | 2015-09-17 14:18:16 -0600 | [diff] [blame] | 7031 | } |
| 7032 | |
Tobin Ehlis | 17826bd | 2016-05-25 11:12:50 -0600 | [diff] [blame] | 7033 | TEST_F(VkLayerTest, DSUsageBitsErrors) { |
| 7034 | TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers " |
| 7035 | "that do not have correct usage bits sets."); |
| 7036 | VkResult err; |
| 7037 | |
| 7038 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7039 | VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {}; |
| 7040 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 7041 | ds_type_count[i].type = VkDescriptorType(i); |
| 7042 | ds_type_count[i].descriptorCount = 1; |
| 7043 | } |
| 7044 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 7045 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7046 | ds_pool_ci.pNext = NULL; |
| 7047 | ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 7048 | ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 7049 | ds_pool_ci.pPoolSizes = ds_type_count; |
| 7050 | |
| 7051 | VkDescriptorPool ds_pool; |
| 7052 | err = |
| 7053 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 7054 | ASSERT_VK_SUCCESS(err); |
| 7055 | |
| 7056 | // Create 10 layouts where each has a single descriptor of different type |
| 7057 | VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = |
| 7058 | {}; |
| 7059 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 7060 | dsl_binding[i].binding = 0; |
| 7061 | dsl_binding[i].descriptorType = VkDescriptorType(i); |
| 7062 | dsl_binding[i].descriptorCount = 1; |
| 7063 | dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL; |
| 7064 | dsl_binding[i].pImmutableSamplers = NULL; |
| 7065 | } |
| 7066 | |
| 7067 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 7068 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7069 | ds_layout_ci.pNext = NULL; |
| 7070 | ds_layout_ci.bindingCount = 1; |
| 7071 | VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE]; |
| 7072 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 7073 | ds_layout_ci.pBindings = dsl_binding + i; |
| 7074 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, |
| 7075 | NULL, ds_layouts + i); |
| 7076 | ASSERT_VK_SUCCESS(err); |
| 7077 | } |
| 7078 | VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {}; |
| 7079 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 7080 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 7081 | alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE; |
| 7082 | alloc_info.descriptorPool = ds_pool; |
| 7083 | alloc_info.pSetLayouts = ds_layouts; |
| 7084 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7085 | descriptor_sets); |
| 7086 | ASSERT_VK_SUCCESS(err); |
| 7087 | |
| 7088 | // Create a buffer & bufferView to be used for invalid updates |
| 7089 | VkBufferCreateInfo buff_ci = {}; |
| 7090 | buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 7091 | // This usage is not valid for any descriptor type |
| 7092 | buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; |
| 7093 | buff_ci.size = 256; |
| 7094 | buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 7095 | VkBuffer buffer; |
| 7096 | err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer); |
| 7097 | ASSERT_VK_SUCCESS(err); |
| 7098 | |
| 7099 | VkBufferViewCreateInfo buff_view_ci = {}; |
| 7100 | buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; |
| 7101 | buff_view_ci.buffer = buffer; |
| 7102 | buff_view_ci.format = VK_FORMAT_R8_UNORM; |
| 7103 | buff_view_ci.range = VK_WHOLE_SIZE; |
| 7104 | VkBufferView buff_view; |
| 7105 | err = |
| 7106 | vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view); |
| 7107 | ASSERT_VK_SUCCESS(err); |
| 7108 | |
| 7109 | // Create an image to be used for invalid updates |
| 7110 | VkImageCreateInfo image_ci = {}; |
| 7111 | image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 7112 | image_ci.imageType = VK_IMAGE_TYPE_2D; |
| 7113 | image_ci.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 7114 | image_ci.extent.width = 64; |
| 7115 | image_ci.extent.height = 64; |
| 7116 | image_ci.extent.depth = 1; |
| 7117 | image_ci.mipLevels = 1; |
| 7118 | image_ci.arrayLayers = 1; |
| 7119 | image_ci.samples = VK_SAMPLE_COUNT_1_BIT; |
| 7120 | image_ci.tiling = VK_IMAGE_TILING_LINEAR; |
| 7121 | image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 7122 | // This usage is not valid for any descriptor type |
| 7123 | image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 7124 | image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 7125 | VkImage image; |
| 7126 | err = vkCreateImage(m_device->device(), &image_ci, NULL, &image); |
| 7127 | ASSERT_VK_SUCCESS(err); |
| 7128 | // Bind memory to image |
| 7129 | VkMemoryRequirements mem_reqs; |
| 7130 | VkDeviceMemory image_mem; |
| 7131 | bool pass; |
| 7132 | VkMemoryAllocateInfo mem_alloc = {}; |
| 7133 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 7134 | mem_alloc.pNext = NULL; |
| 7135 | mem_alloc.allocationSize = 0; |
| 7136 | mem_alloc.memoryTypeIndex = 0; |
| 7137 | vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs); |
| 7138 | mem_alloc.allocationSize = mem_reqs.size; |
| 7139 | pass = |
| 7140 | m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 7141 | ASSERT_TRUE(pass); |
| 7142 | err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem); |
| 7143 | ASSERT_VK_SUCCESS(err); |
| 7144 | err = vkBindImageMemory(m_device->device(), image, image_mem, 0); |
| 7145 | ASSERT_VK_SUCCESS(err); |
| 7146 | // Now create view for image |
| 7147 | VkImageViewCreateInfo image_view_ci = {}; |
| 7148 | image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 7149 | image_view_ci.image = image; |
| 7150 | image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 7151 | image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 7152 | image_view_ci.subresourceRange.layerCount = 1; |
| 7153 | image_view_ci.subresourceRange.baseArrayLayer = 0; |
| 7154 | image_view_ci.subresourceRange.levelCount = 1; |
| 7155 | image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 7156 | VkImageView image_view; |
| 7157 | err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, |
| 7158 | &image_view); |
| 7159 | ASSERT_VK_SUCCESS(err); |
| 7160 | |
| 7161 | VkDescriptorBufferInfo buff_info = {}; |
| 7162 | buff_info.buffer = buffer; |
| 7163 | VkDescriptorImageInfo img_info = {}; |
| 7164 | img_info.imageView = image_view; |
| 7165 | VkWriteDescriptorSet descriptor_write = {}; |
| 7166 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 7167 | descriptor_write.dstBinding = 0; |
| 7168 | descriptor_write.descriptorCount = 1; |
| 7169 | descriptor_write.pTexelBufferView = &buff_view; |
| 7170 | descriptor_write.pBufferInfo = &buff_info; |
| 7171 | descriptor_write.pImageInfo = &img_info; |
| 7172 | |
| 7173 | // These error messages align with VkDescriptorType struct |
| 7174 | const char *error_msgs[] = { |
| 7175 | "", // placeholder, no error for SAMPLER descriptor |
| 7176 | " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.", |
| 7177 | " does not have VK_IMAGE_USAGE_SAMPLED_BIT set.", |
| 7178 | " does not have VK_IMAGE_USAGE_STORAGE_BIT set.", |
| 7179 | " does not have VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT set.", |
| 7180 | " does not have VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT set.", |
| 7181 | " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.", |
| 7182 | " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.", |
| 7183 | " does not have VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT set.", |
| 7184 | " does not have VK_BUFFER_USAGE_STORAGE_BUFFER_BIT set.", |
| 7185 | " does not have VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set."}; |
| 7186 | // Start loop at 1 as SAMPLER desc type has no usage bit error |
| 7187 | for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) { |
| 7188 | descriptor_write.descriptorType = VkDescriptorType(i); |
| 7189 | descriptor_write.dstSet = descriptor_sets[i]; |
| 7190 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7191 | error_msgs[i]); |
| 7192 | |
| 7193 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, |
| 7194 | NULL); |
| 7195 | |
| 7196 | m_errorMonitor->VerifyFound(); |
| 7197 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL); |
| 7198 | } |
| 7199 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL); |
| 7200 | vkDestroyImage(m_device->device(), image, NULL); |
| 7201 | vkDestroyImageView(m_device->device(), image_view, NULL); |
| 7202 | vkDestroyBuffer(m_device->device(), buffer, NULL); |
| 7203 | vkDestroyBufferView(m_device->device(), buff_view, NULL); |
| 7204 | vkFreeDescriptorSets(m_device->device(), ds_pool, |
| 7205 | VK_DESCRIPTOR_TYPE_RANGE_SIZE, descriptor_sets); |
| 7206 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 7207 | } |
| 7208 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7209 | TEST_F(VkLayerTest, DSTypeMismatch) { |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 7210 | // 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] | 7211 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7212 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7213 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 7214 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7215 | " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update " |
| 7216 | "type is VK_DESCRIPTOR_TYPE_SAMPLER"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7217 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7218 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7219 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7220 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7221 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7222 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7223 | |
| 7224 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7225 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7226 | ds_pool_ci.pNext = NULL; |
| 7227 | ds_pool_ci.maxSets = 1; |
| 7228 | ds_pool_ci.poolSizeCount = 1; |
| 7229 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7230 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7231 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7232 | err = |
| 7233 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7234 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7235 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7236 | dsl_binding.binding = 0; |
| 7237 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7238 | dsl_binding.descriptorCount = 1; |
| 7239 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7240 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7241 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7242 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7243 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7244 | ds_layout_ci.pNext = NULL; |
| 7245 | ds_layout_ci.bindingCount = 1; |
| 7246 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7247 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7248 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7249 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7250 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7251 | ASSERT_VK_SUCCESS(err); |
| 7252 | |
| 7253 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7254 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 7255 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7256 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 7257 | alloc_info.descriptorPool = ds_pool; |
| 7258 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7259 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7260 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7261 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7262 | |
Tobin Ehlis | 30db8f8 | 2016-05-05 08:19:48 -0600 | [diff] [blame] | 7263 | VkSamplerCreateInfo sampler_ci = {}; |
| 7264 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 7265 | sampler_ci.pNext = NULL; |
| 7266 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 7267 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 7268 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 7269 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 7270 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 7271 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 7272 | sampler_ci.mipLodBias = 1.0; |
| 7273 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 7274 | sampler_ci.maxAnisotropy = 1; |
| 7275 | sampler_ci.compareEnable = VK_FALSE; |
| 7276 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 7277 | sampler_ci.minLod = 1.0; |
| 7278 | sampler_ci.maxLod = 1.0; |
| 7279 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 7280 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
| 7281 | VkSampler sampler; |
| 7282 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
| 7283 | ASSERT_VK_SUCCESS(err); |
| 7284 | |
| 7285 | VkDescriptorImageInfo info = {}; |
| 7286 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 7287 | |
| 7288 | VkWriteDescriptorSet descriptor_write; |
| 7289 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 7290 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7291 | descriptor_write.dstSet = descriptorSet; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7292 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7293 | // This is a mismatched type for the layout which expects BUFFER |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 7294 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 7295 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 7296 | |
| 7297 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 7298 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7299 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 7300 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7301 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 7302 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7303 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 7304 | } |
| 7305 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7306 | TEST_F(VkLayerTest, DSUpdateOutOfBounds) { |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 7307 | // For overlapping Update, have arrayIndex exceed that of layout |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7308 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7309 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7310 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 7311 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7312 | " binding #0 with 1 total descriptors but update of 1 descriptors " |
| 7313 | "starting at binding offset of 0 combined with update array element " |
| 7314 | "offset of 1 oversteps the size of this descriptor set."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7315 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7316 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7317 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7318 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7319 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7320 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7321 | |
| 7322 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7323 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7324 | ds_pool_ci.pNext = NULL; |
| 7325 | ds_pool_ci.maxSets = 1; |
| 7326 | ds_pool_ci.poolSizeCount = 1; |
| 7327 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7328 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7329 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7330 | err = |
| 7331 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7332 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7333 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7334 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7335 | dsl_binding.binding = 0; |
| 7336 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7337 | dsl_binding.descriptorCount = 1; |
| 7338 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7339 | dsl_binding.pImmutableSamplers = NULL; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7340 | |
| 7341 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7342 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7343 | ds_layout_ci.pNext = NULL; |
| 7344 | ds_layout_ci.bindingCount = 1; |
| 7345 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7346 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7347 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7348 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7349 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7350 | ASSERT_VK_SUCCESS(err); |
| 7351 | |
| 7352 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7353 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 7354 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7355 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 7356 | alloc_info.descriptorPool = ds_pool; |
| 7357 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7358 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7359 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7360 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7361 | |
Tobin Ehlis | 30db8f8 | 2016-05-05 08:19:48 -0600 | [diff] [blame] | 7362 | // Correctly update descriptor to avoid "NOT_UPDATED" error |
| 7363 | VkDescriptorBufferInfo buff_info = {}; |
| 7364 | buff_info.buffer = |
| 7365 | VkBuffer(0); // Don't care about buffer handle for this test |
| 7366 | buff_info.offset = 0; |
| 7367 | buff_info.range = 1024; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 7368 | |
| 7369 | VkWriteDescriptorSet descriptor_write; |
| 7370 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 7371 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7372 | descriptor_write.dstSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7373 | descriptor_write.dstArrayElement = |
| 7374 | 1; /* This index out of bounds for the update */ |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7375 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 7376 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7377 | descriptor_write.pBufferInfo = &buff_info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 7378 | |
| 7379 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 7380 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7381 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 7382 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7383 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7384 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 7385 | } |
| 7386 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7387 | TEST_F(VkLayerTest, InvalidDSUpdateIndex) { |
| 7388 | // Create layout w/ count of 1 and attempt update to that layout w/ binding |
| 7389 | // index 2 |
| 7390 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7391 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 7392 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7393 | " does not have binding 2."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7394 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7395 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7396 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7397 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7398 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7399 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7400 | |
| 7401 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7402 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7403 | ds_pool_ci.pNext = NULL; |
| 7404 | ds_pool_ci.maxSets = 1; |
| 7405 | ds_pool_ci.poolSizeCount = 1; |
| 7406 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 7407 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7408 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7409 | err = |
| 7410 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7411 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7412 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7413 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7414 | dsl_binding.binding = 0; |
| 7415 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7416 | dsl_binding.descriptorCount = 1; |
| 7417 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7418 | dsl_binding.pImmutableSamplers = NULL; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7419 | |
| 7420 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7421 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7422 | ds_layout_ci.pNext = NULL; |
| 7423 | ds_layout_ci.bindingCount = 1; |
| 7424 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7425 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7426 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7427 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7428 | ASSERT_VK_SUCCESS(err); |
| 7429 | |
| 7430 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7431 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 7432 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7433 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 7434 | alloc_info.descriptorPool = ds_pool; |
| 7435 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7436 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7437 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7438 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7439 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7440 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7441 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 7442 | sampler_ci.pNext = NULL; |
| 7443 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 7444 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 7445 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 7446 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 7447 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 7448 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 7449 | sampler_ci.mipLodBias = 1.0; |
| 7450 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 7451 | sampler_ci.maxAnisotropy = 1; |
| 7452 | sampler_ci.compareEnable = VK_FALSE; |
| 7453 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 7454 | sampler_ci.minLod = 1.0; |
| 7455 | sampler_ci.maxLod = 1.0; |
| 7456 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 7457 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7458 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7459 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7460 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7461 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 7462 | |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 7463 | VkDescriptorImageInfo info = {}; |
| 7464 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 7465 | |
| 7466 | VkWriteDescriptorSet descriptor_write; |
| 7467 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 7468 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7469 | descriptor_write.dstSet = descriptorSet; |
| 7470 | descriptor_write.dstBinding = 2; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7471 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7472 | // 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] | 7473 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 7474 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 7475 | |
| 7476 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 7477 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7478 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 7479 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7480 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 7481 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7482 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 7483 | } |
| 7484 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7485 | TEST_F(VkLayerTest, InvalidDSUpdateStruct) { |
| 7486 | // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* |
| 7487 | // types |
| 7488 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7489 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 7490 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 660bcdc | 2016-05-17 10:39:46 -0600 | [diff] [blame] | 7491 | ".sType must be VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7492 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7493 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 7494 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7495 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7496 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7497 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7498 | |
| 7499 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7500 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7501 | ds_pool_ci.pNext = NULL; |
| 7502 | ds_pool_ci.maxSets = 1; |
| 7503 | ds_pool_ci.poolSizeCount = 1; |
| 7504 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 7505 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7506 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7507 | err = |
| 7508 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7509 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7510 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7511 | dsl_binding.binding = 0; |
| 7512 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7513 | dsl_binding.descriptorCount = 1; |
| 7514 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7515 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7516 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7517 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7518 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7519 | ds_layout_ci.pNext = NULL; |
| 7520 | ds_layout_ci.bindingCount = 1; |
| 7521 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7522 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7523 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7524 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7525 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7526 | ASSERT_VK_SUCCESS(err); |
| 7527 | |
| 7528 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7529 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 7530 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7531 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 7532 | alloc_info.descriptorPool = ds_pool; |
| 7533 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7534 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7535 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7536 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7537 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7538 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7539 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 7540 | sampler_ci.pNext = NULL; |
| 7541 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 7542 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 7543 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 7544 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 7545 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 7546 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 7547 | sampler_ci.mipLodBias = 1.0; |
| 7548 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 7549 | sampler_ci.maxAnisotropy = 1; |
| 7550 | sampler_ci.compareEnable = VK_FALSE; |
| 7551 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 7552 | sampler_ci.minLod = 1.0; |
| 7553 | sampler_ci.maxLod = 1.0; |
| 7554 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 7555 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7556 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7557 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7558 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 7559 | |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 7560 | VkDescriptorImageInfo info = {}; |
| 7561 | info.sampler = sampler; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 7562 | |
| 7563 | VkWriteDescriptorSet descriptor_write; |
| 7564 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7565 | descriptor_write.sType = |
| 7566 | (VkStructureType)0x99999999; /* Intentionally broken struct type */ |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7567 | descriptor_write.dstSet = descriptorSet; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7568 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7569 | // 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] | 7570 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
Courtney Goeltzenleuchter | 4cb6d92 | 2015-10-23 13:38:14 -0600 | [diff] [blame] | 7571 | descriptor_write.pImageInfo = &info; |
Chia-I Wu | 9d00ed7 | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 7572 | |
| 7573 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 7574 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7575 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 7576 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7577 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 7578 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7579 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 7580 | } |
| 7581 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7582 | TEST_F(VkLayerTest, SampleDescriptorUpdateError) { |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7583 | // Create a single Sampler descriptor and send it an invalid Sampler |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7584 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7585 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7586 | m_errorMonitor->SetDesiredFailureMsg( |
| 7587 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 7588 | "Attempted write update to sampler descriptor with invalid sampler"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7589 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7590 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7591 | // TODO : Farm Descriptor setup code to helper function(s) to reduce copied |
| 7592 | // code |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7593 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7594 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 7595 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7596 | |
| 7597 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7598 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7599 | ds_pool_ci.pNext = NULL; |
| 7600 | ds_pool_ci.maxSets = 1; |
| 7601 | ds_pool_ci.poolSizeCount = 1; |
| 7602 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7603 | |
| 7604 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7605 | err = |
| 7606 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7607 | ASSERT_VK_SUCCESS(err); |
| 7608 | |
| 7609 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7610 | dsl_binding.binding = 0; |
| 7611 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 7612 | dsl_binding.descriptorCount = 1; |
| 7613 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7614 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7615 | |
| 7616 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7617 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7618 | ds_layout_ci.pNext = NULL; |
| 7619 | ds_layout_ci.bindingCount = 1; |
| 7620 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7621 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7622 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7623 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7624 | ASSERT_VK_SUCCESS(err); |
| 7625 | |
| 7626 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7627 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 7628 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7629 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7630 | alloc_info.descriptorPool = ds_pool; |
| 7631 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7632 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7633 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7634 | ASSERT_VK_SUCCESS(err); |
| 7635 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7636 | VkSampler sampler = |
| 7637 | (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7638 | |
| 7639 | VkDescriptorImageInfo descriptor_info; |
| 7640 | memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo)); |
| 7641 | descriptor_info.sampler = sampler; |
| 7642 | |
| 7643 | VkWriteDescriptorSet descriptor_write; |
| 7644 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 7645 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7646 | descriptor_write.dstSet = descriptorSet; |
| 7647 | descriptor_write.dstBinding = 0; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7648 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7649 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 7650 | descriptor_write.pImageInfo = &descriptor_info; |
| 7651 | |
| 7652 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 7653 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7654 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7655 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7656 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7657 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7658 | } |
| 7659 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7660 | TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) { |
| 7661 | // Create a single combined Image/Sampler descriptor and send it an invalid |
| 7662 | // imageView |
| 7663 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7664 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 7665 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7666 | "Attempted write update to combined " |
| 7667 | "image sampler descriptor failed due " |
Tobin Ehlis | 63c4b8a | 2016-05-09 10:29:34 -0600 | [diff] [blame] | 7668 | "to: Invalid VkImageView:"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7669 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7670 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7671 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7672 | ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 7673 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7674 | |
| 7675 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7676 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7677 | ds_pool_ci.pNext = NULL; |
| 7678 | ds_pool_ci.maxSets = 1; |
| 7679 | ds_pool_ci.poolSizeCount = 1; |
| 7680 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7681 | |
| 7682 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7683 | err = |
| 7684 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7685 | ASSERT_VK_SUCCESS(err); |
| 7686 | |
| 7687 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7688 | dsl_binding.binding = 0; |
| 7689 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 7690 | dsl_binding.descriptorCount = 1; |
| 7691 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7692 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7693 | |
| 7694 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7695 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7696 | ds_layout_ci.pNext = NULL; |
| 7697 | ds_layout_ci.bindingCount = 1; |
| 7698 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7699 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7700 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7701 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7702 | ASSERT_VK_SUCCESS(err); |
| 7703 | |
| 7704 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7705 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 7706 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7707 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7708 | alloc_info.descriptorPool = ds_pool; |
| 7709 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7710 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7711 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7712 | ASSERT_VK_SUCCESS(err); |
| 7713 | |
| 7714 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7715 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 7716 | sampler_ci.pNext = NULL; |
| 7717 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 7718 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 7719 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 7720 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 7721 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 7722 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 7723 | sampler_ci.mipLodBias = 1.0; |
| 7724 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 7725 | sampler_ci.maxAnisotropy = 1; |
| 7726 | sampler_ci.compareEnable = VK_FALSE; |
| 7727 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 7728 | sampler_ci.minLod = 1.0; |
| 7729 | sampler_ci.maxLod = 1.0; |
| 7730 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 7731 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7732 | |
| 7733 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7734 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7735 | ASSERT_VK_SUCCESS(err); |
| 7736 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7737 | VkImageView view = |
| 7738 | (VkImageView)((size_t)0xbaadbeef); // invalid imageView object |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7739 | |
| 7740 | VkDescriptorImageInfo descriptor_info; |
| 7741 | memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo)); |
| 7742 | descriptor_info.sampler = sampler; |
| 7743 | descriptor_info.imageView = view; |
| 7744 | |
| 7745 | VkWriteDescriptorSet descriptor_write; |
| 7746 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 7747 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7748 | descriptor_write.dstSet = descriptorSet; |
| 7749 | descriptor_write.dstBinding = 0; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7750 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7751 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; |
| 7752 | descriptor_write.pImageInfo = &descriptor_info; |
| 7753 | |
| 7754 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 7755 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7756 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7757 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7758 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 7759 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7760 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 7761 | } |
| 7762 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7763 | TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) { |
| 7764 | // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update |
| 7765 | // into the other |
| 7766 | VkResult err; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 7767 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 7768 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 7769 | " binding #1 with type " |
| 7770 | "VK_DESCRIPTOR_TYPE_SAMPLER. Types do " |
| 7771 | "not match."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7772 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 7773 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7774 | // VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7775 | VkDescriptorPoolSize ds_type_count[2] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7776 | ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7777 | ds_type_count[0].descriptorCount = 1; |
| 7778 | ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 7779 | ds_type_count[1].descriptorCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 7780 | |
| 7781 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7782 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7783 | ds_pool_ci.pNext = NULL; |
| 7784 | ds_pool_ci.maxSets = 1; |
| 7785 | ds_pool_ci.poolSizeCount = 2; |
| 7786 | ds_pool_ci.pPoolSizes = ds_type_count; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 7787 | |
| 7788 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7789 | err = |
| 7790 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 7791 | ASSERT_VK_SUCCESS(err); |
| 7792 | VkDescriptorSetLayoutBinding dsl_binding[2] = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7793 | dsl_binding[0].binding = 0; |
| 7794 | dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 7795 | dsl_binding[0].descriptorCount = 1; |
| 7796 | dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL; |
| 7797 | dsl_binding[0].pImmutableSamplers = NULL; |
| 7798 | dsl_binding[1].binding = 1; |
| 7799 | dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 7800 | dsl_binding[1].descriptorCount = 1; |
| 7801 | dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL; |
| 7802 | dsl_binding[1].pImmutableSamplers = NULL; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 7803 | |
| 7804 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7805 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7806 | ds_layout_ci.pNext = NULL; |
| 7807 | ds_layout_ci.bindingCount = 2; |
| 7808 | ds_layout_ci.pBindings = dsl_binding; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 7809 | |
| 7810 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7811 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7812 | &ds_layout); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 7813 | ASSERT_VK_SUCCESS(err); |
| 7814 | |
| 7815 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7816 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 7817 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7818 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 7819 | alloc_info.descriptorPool = ds_pool; |
| 7820 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7821 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7822 | &descriptorSet); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 7823 | ASSERT_VK_SUCCESS(err); |
| 7824 | |
| 7825 | VkSamplerCreateInfo sampler_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7826 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 7827 | sampler_ci.pNext = NULL; |
| 7828 | sampler_ci.magFilter = VK_FILTER_NEAREST; |
| 7829 | sampler_ci.minFilter = VK_FILTER_NEAREST; |
| 7830 | sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; |
| 7831 | sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 7832 | sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 7833 | sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; |
| 7834 | sampler_ci.mipLodBias = 1.0; |
| 7835 | sampler_ci.anisotropyEnable = VK_FALSE; |
| 7836 | sampler_ci.maxAnisotropy = 1; |
| 7837 | sampler_ci.compareEnable = VK_FALSE; |
| 7838 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 7839 | sampler_ci.minLod = 1.0; |
| 7840 | sampler_ci.maxLod = 1.0; |
| 7841 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 7842 | sampler_ci.unnormalizedCoordinates = VK_FALSE; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 7843 | |
| 7844 | VkSampler sampler; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7845 | err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 7846 | ASSERT_VK_SUCCESS(err); |
| 7847 | |
| 7848 | VkDescriptorImageInfo info = {}; |
| 7849 | info.sampler = sampler; |
| 7850 | |
| 7851 | VkWriteDescriptorSet descriptor_write; |
| 7852 | memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet)); |
| 7853 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7854 | descriptor_write.dstSet = descriptorSet; |
| 7855 | descriptor_write.dstBinding = 1; // SAMPLER binding from layout above |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7856 | descriptor_write.descriptorCount = 1; |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 7857 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 7858 | descriptor_write.pImageInfo = &info; |
| 7859 | // This write update should succeed |
| 7860 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 7861 | // Now perform a copy update that fails due to type mismatch |
| 7862 | VkCopyDescriptorSet copy_ds_update; |
| 7863 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 7864 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 7865 | copy_ds_update.srcSet = descriptorSet; |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 7866 | copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7867 | copy_ds_update.dstSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7868 | copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7869 | copy_ds_update.descriptorCount = 1; // copy 1 descriptor |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 7870 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 7871 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7872 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 7873 | // 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] | 7874 | m_errorMonitor->SetDesiredFailureMsg( |
| 7875 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 7876 | " does not have copy update src binding of 3."); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 7877 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 7878 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 7879 | copy_ds_update.srcSet = descriptorSet; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7880 | copy_ds_update.srcBinding = |
| 7881 | 3; // ERROR : Invalid binding for matching layout |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7882 | copy_ds_update.dstSet = descriptorSet; |
| 7883 | copy_ds_update.dstBinding = 0; |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 7884 | copy_ds_update.descriptorCount = 1; // Copy 1 descriptor |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 7885 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 7886 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7887 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7888 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 7889 | // 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] | 7890 | m_errorMonitor->SetDesiredFailureMsg( |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 7891 | VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus " |
| 7892 | "update array offset of 0 and update of " |
| 7893 | "5 descriptors oversteps total number " |
| 7894 | "of descriptors in set: 2."); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7895 | |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 7896 | memset(©_ds_update, 0, sizeof(VkCopyDescriptorSet)); |
| 7897 | copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 7898 | copy_ds_update.srcSet = descriptorSet; |
| 7899 | copy_ds_update.srcBinding = 1; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7900 | copy_ds_update.dstSet = descriptorSet; |
| 7901 | copy_ds_update.dstBinding = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7902 | copy_ds_update.descriptorCount = |
| 7903 | 5; // ERROR copy 5 descriptors (out of bounds for layout) |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 7904 | vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, ©_ds_update); |
| 7905 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 7906 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 7907 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 7908 | vkDestroySampler(m_device->device(), sampler, NULL); |
| 7909 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 7910 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 04356f9 | 2015-10-27 16:35:27 -0600 | [diff] [blame] | 7911 | } |
| 7912 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7913 | TEST_F(VkLayerTest, NumSamplesMismatch) { |
| 7914 | // Create CommandBuffer where MSAA samples doesn't match RenderPass |
| 7915 | // sampleCount |
| 7916 | VkResult err; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7917 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 7918 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7919 | "Num samples mismatch! "); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 7920 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7921 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 7922 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 7923 | VkDescriptorPoolSize ds_type_count = {}; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7924 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7925 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7926 | |
| 7927 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7928 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 7929 | ds_pool_ci.pNext = NULL; |
| 7930 | ds_pool_ci.maxSets = 1; |
| 7931 | ds_pool_ci.poolSizeCount = 1; |
| 7932 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 7933 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7934 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7935 | err = |
| 7936 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7937 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7938 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7939 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Chia-I Wu | d46e6ae | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 7940 | dsl_binding.binding = 0; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7941 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
Chia-I Wu | 0212448 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 7942 | dsl_binding.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7943 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 7944 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7945 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7946 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 7947 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 7948 | ds_layout_ci.pNext = NULL; |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 7949 | ds_layout_ci.bindingCount = 1; |
Jon Ashburn | 6e23c1f | 2015-12-30 18:01:16 -0700 | [diff] [blame] | 7950 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7951 | |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7952 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7953 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 7954 | &ds_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7955 | ASSERT_VK_SUCCESS(err); |
| 7956 | |
| 7957 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 7958 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 7959 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 7960 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 7961 | alloc_info.descriptorPool = ds_pool; |
| 7962 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7963 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 7964 | &descriptorSet); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7965 | ASSERT_VK_SUCCESS(err); |
| 7966 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7967 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7968 | pipe_ms_state_ci.sType = |
| 7969 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 7970 | pipe_ms_state_ci.pNext = NULL; |
| 7971 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT; |
| 7972 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 7973 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 7974 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7975 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 7976 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7977 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 7978 | pipeline_layout_ci.pNext = NULL; |
| 7979 | pipeline_layout_ci.setLayoutCount = 1; |
| 7980 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7981 | |
| 7982 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7983 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 7984 | &pipeline_layout); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7985 | ASSERT_VK_SUCCESS(err); |
| 7986 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7987 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 7988 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 7989 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 7990 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 7991 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 7992 | // but add it to be able to run on more devices |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 7993 | VkPipelineObj pipe(m_device); |
| 7994 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 7995 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 7996 | pipe.AddColorAttachment(); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 7997 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 7998 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 7999 | |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 8000 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8001 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 8002 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | 3b78066 | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 8003 | |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 8004 | // Render triangle (the error should trigger on the attempt to draw). |
| 8005 | Draw(3, 1, 0, 0); |
| 8006 | |
| 8007 | // Finalize recording of the command buffer |
| 8008 | EndCommandBuffer(); |
| 8009 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8010 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8011 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8012 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 8013 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8014 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 49eb23d | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 8015 | } |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 8016 | |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 8017 | TEST_F(VkLayerTest, NumBlendAttachMismatch) { |
| 8018 | // Create Pipeline where the number of blend attachments doesn't match the |
| 8019 | // number of color attachments. In this case, we don't add any color |
| 8020 | // blend attachments even though we have a color attachment. |
| 8021 | VkResult err; |
| 8022 | |
| 8023 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 8024 | "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] | 8025 | |
| 8026 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8027 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8028 | VkDescriptorPoolSize ds_type_count = {}; |
| 8029 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8030 | ds_type_count.descriptorCount = 1; |
| 8031 | |
| 8032 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 8033 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8034 | ds_pool_ci.pNext = NULL; |
| 8035 | ds_pool_ci.maxSets = 1; |
| 8036 | ds_pool_ci.poolSizeCount = 1; |
| 8037 | ds_pool_ci.pPoolSizes = &ds_type_count; |
| 8038 | |
| 8039 | VkDescriptorPool ds_pool; |
| 8040 | err = |
| 8041 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
| 8042 | ASSERT_VK_SUCCESS(err); |
| 8043 | |
| 8044 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 8045 | dsl_binding.binding = 0; |
| 8046 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8047 | dsl_binding.descriptorCount = 1; |
| 8048 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8049 | dsl_binding.pImmutableSamplers = NULL; |
| 8050 | |
| 8051 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 8052 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8053 | ds_layout_ci.pNext = NULL; |
| 8054 | ds_layout_ci.bindingCount = 1; |
| 8055 | ds_layout_ci.pBindings = &dsl_binding; |
| 8056 | |
| 8057 | VkDescriptorSetLayout ds_layout; |
| 8058 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8059 | &ds_layout); |
| 8060 | ASSERT_VK_SUCCESS(err); |
| 8061 | |
| 8062 | VkDescriptorSet descriptorSet; |
| 8063 | VkDescriptorSetAllocateInfo alloc_info = {}; |
| 8064 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 8065 | alloc_info.descriptorSetCount = 1; |
| 8066 | alloc_info.descriptorPool = ds_pool; |
| 8067 | alloc_info.pSetLayouts = &ds_layout; |
| 8068 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8069 | &descriptorSet); |
| 8070 | ASSERT_VK_SUCCESS(err); |
| 8071 | |
| 8072 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
| 8073 | pipe_ms_state_ci.sType = |
| 8074 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 8075 | pipe_ms_state_ci.pNext = NULL; |
| 8076 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; |
| 8077 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 8078 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 8079 | pipe_ms_state_ci.pSampleMask = NULL; |
| 8080 | |
| 8081 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 8082 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 8083 | pipeline_layout_ci.pNext = NULL; |
| 8084 | pipeline_layout_ci.setLayoutCount = 1; |
| 8085 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 8086 | |
| 8087 | VkPipelineLayout pipeline_layout; |
| 8088 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 8089 | &pipeline_layout); |
| 8090 | ASSERT_VK_SUCCESS(err); |
| 8091 | |
| 8092 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 8093 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 8094 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 8095 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 8096 | this); // We shouldn't need a fragment shader |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 8097 | // but add it to be able to run on more devices |
| 8098 | VkPipelineObj pipe(m_device); |
| 8099 | pipe.AddShader(&vs); |
| 8100 | pipe.AddShader(&fs); |
| 8101 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 8102 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
| 8103 | |
| 8104 | BeginCommandBuffer(); |
| 8105 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 8106 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
| 8107 | |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 8108 | // Render triangle (the error should trigger on the attempt to draw). |
| 8109 | Draw(3, 1, 0, 0); |
| 8110 | |
| 8111 | // Finalize recording of the command buffer |
| 8112 | EndCommandBuffer(); |
| 8113 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8114 | m_errorMonitor->VerifyFound(); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 8115 | |
| 8116 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 8117 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8118 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
| 8119 | } |
Mark Young | 2992748 | 2016-05-04 14:38:51 -0600 | [diff] [blame] | 8120 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8121 | TEST_F(VkLayerTest, ClearCmdNoDraw) { |
| 8122 | // Create CommandBuffer where we add ClearCmd for FB Color attachment prior |
| 8123 | // to issuing a Draw |
| 8124 | VkResult err; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 8125 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8126 | m_errorMonitor->SetDesiredFailureMsg( |
Tony Barbour | 7e56d30 | 2016-03-02 15:12:01 -0700 | [diff] [blame] | 8127 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8128 | "vkCmdClearAttachments() issued on CB object "); |
| 8129 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 8130 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8131 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8132 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8133 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8134 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8135 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8136 | |
| 8137 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8138 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8139 | ds_pool_ci.pNext = NULL; |
| 8140 | ds_pool_ci.maxSets = 1; |
| 8141 | ds_pool_ci.poolSizeCount = 1; |
| 8142 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8143 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 8144 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8145 | err = |
| 8146 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 8147 | ASSERT_VK_SUCCESS(err); |
| 8148 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8149 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8150 | dsl_binding.binding = 0; |
| 8151 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8152 | dsl_binding.descriptorCount = 1; |
| 8153 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8154 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 8155 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8156 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8157 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8158 | ds_layout_ci.pNext = NULL; |
| 8159 | ds_layout_ci.bindingCount = 1; |
| 8160 | ds_layout_ci.pBindings = &dsl_binding; |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 8161 | |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 8162 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8163 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8164 | &ds_layout); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 8165 | ASSERT_VK_SUCCESS(err); |
| 8166 | |
| 8167 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8168 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8169 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8170 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8171 | alloc_info.descriptorPool = ds_pool; |
| 8172 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8173 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8174 | &descriptorSet); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 8175 | ASSERT_VK_SUCCESS(err); |
| 8176 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8177 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8178 | pipe_ms_state_ci.sType = |
| 8179 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 8180 | pipe_ms_state_ci.pNext = NULL; |
| 8181 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT; |
| 8182 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 8183 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 8184 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 8185 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8186 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8187 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 8188 | pipeline_layout_ci.pNext = NULL; |
| 8189 | pipeline_layout_ci.setLayoutCount = 1; |
| 8190 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 8191 | |
| 8192 | VkPipelineLayout pipeline_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8193 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 8194 | &pipeline_layout); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 8195 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 8196 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8197 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 8198 | VK_SHADER_STAGE_VERTEX_BIT, this); |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 8199 | // 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] | 8200 | // on more devices |
| 8201 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 8202 | VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8203 | |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 8204 | VkPipelineObj pipe(m_device); |
| 8205 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 8206 | pipe.AddShader(&fs); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 8207 | pipe.SetMSAA(&pipe_ms_state_ci); |
| 8208 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 8209 | |
| 8210 | BeginCommandBuffer(); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 8211 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8212 | // Main thing we care about for this test is that the VkImage obj we're |
| 8213 | // clearing matches Color Attachment of FB |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 8214 | // Also pass down other dummy params to keep driver and paramchecker happy |
Courtney Goeltzenleuchter | c9323e0 | 2015-10-15 16:51:05 -0600 | [diff] [blame] | 8215 | VkClearAttachment color_attachment; |
| 8216 | color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 8217 | color_attachment.clearValue.color.float32[0] = 1.0; |
| 8218 | color_attachment.clearValue.color.float32[1] = 1.0; |
| 8219 | color_attachment.clearValue.color.float32[2] = 1.0; |
| 8220 | color_attachment.clearValue.color.float32[3] = 1.0; |
| 8221 | color_attachment.colorAttachment = 0; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8222 | VkClearRect clear_rect = { |
| 8223 | {{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}}; |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 8224 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8225 | vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, |
| 8226 | &color_attachment, 1, &clear_rect); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8227 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8228 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8229 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8230 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 8231 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8232 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 53eddda | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 8233 | } |
| 8234 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8235 | TEST_F(VkLayerTest, VtxBufferBadIndex) { |
| 8236 | VkResult err; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 8237 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8238 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 8239 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Mark Lobodzinski | dfcd9b6 | 2015-12-14 15:14:10 -0700 | [diff] [blame] | 8240 | "but no vertex buffers are attached to this Pipeline State Object"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8241 | |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 8242 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 8243 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 8244 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8245 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 8246 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8247 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8248 | ds_type_count.descriptorCount = 1; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8249 | |
| 8250 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8251 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 8252 | ds_pool_ci.pNext = NULL; |
| 8253 | ds_pool_ci.maxSets = 1; |
| 8254 | ds_pool_ci.poolSizeCount = 1; |
| 8255 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8256 | |
Courtney Goeltzenleuchter | fe908d3 | 2015-09-16 16:12:45 -0600 | [diff] [blame] | 8257 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8258 | err = |
| 8259 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 8260 | ASSERT_VK_SUCCESS(err); |
| 8261 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8262 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8263 | dsl_binding.binding = 0; |
| 8264 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 8265 | dsl_binding.descriptorCount = 1; |
| 8266 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 8267 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 8268 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8269 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8270 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 8271 | ds_layout_ci.pNext = NULL; |
| 8272 | ds_layout_ci.bindingCount = 1; |
| 8273 | ds_layout_ci.pBindings = &dsl_binding; |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8274 | |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 8275 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8276 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 8277 | &ds_layout); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 8278 | ASSERT_VK_SUCCESS(err); |
| 8279 | |
| 8280 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8281 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 8282 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 8283 | alloc_info.descriptorSetCount = 1; |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 8284 | alloc_info.descriptorPool = ds_pool; |
| 8285 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8286 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 8287 | &descriptorSet); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 8288 | ASSERT_VK_SUCCESS(err); |
| 8289 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8290 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8291 | pipe_ms_state_ci.sType = |
| 8292 | VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 8293 | pipe_ms_state_ci.pNext = NULL; |
| 8294 | pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; |
| 8295 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 8296 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 8297 | pipe_ms_state_ci.pSampleMask = NULL; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 8298 | |
Tony Barbour | eb25490 | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 8299 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8300 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 8301 | pipeline_layout_ci.pNext = NULL; |
| 8302 | pipeline_layout_ci.setLayoutCount = 1; |
| 8303 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 8304 | VkPipelineLayout pipeline_layout; |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 8305 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8306 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, |
| 8307 | &pipeline_layout); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 8308 | ASSERT_VK_SUCCESS(err); |
| 8309 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8310 | VkShaderObj vs(m_device, bindStateVertShaderText, |
| 8311 | VK_SHADER_STAGE_VERTEX_BIT, this); |
| 8312 | VkShaderObj fs(m_device, bindStateFragShaderText, |
| 8313 | VK_SHADER_STAGE_FRAGMENT_BIT, |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 8314 | this); // We shouldn't need a fragment shader |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8315 | // but add it to be able to run on more devices |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 8316 | VkPipelineObj pipe(m_device); |
| 8317 | pipe.AddShader(&vs); |
Tony Barbour | 1c94d37 | 2015-08-06 11:21:08 -0600 | [diff] [blame] | 8318 | pipe.AddShader(&fs); |
Mark Young | c89c631 | 2016-03-31 16:03:20 -0600 | [diff] [blame] | 8319 | pipe.AddColorAttachment(); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 8320 | pipe.SetMSAA(&pipe_ms_state_ci); |
Tobin Ehlis | d332f28 | 2015-10-02 11:00:56 -0600 | [diff] [blame] | 8321 | pipe.SetViewport(m_viewports); |
| 8322 | pipe.SetScissor(m_scissors); |
Tony Barbour | 62e1a5b | 2015-08-06 10:16:07 -0600 | [diff] [blame] | 8323 | pipe.CreateVKPipeline(pipeline_layout, renderPass()); |
Tony Barbour | fe3351b | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 8324 | |
| 8325 | BeginCommandBuffer(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8326 | vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), |
| 8327 | VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle()); |
Tobin Ehlis | f7bf450 | 2015-09-09 15:12:35 -0600 | [diff] [blame] | 8328 | // Don't care about actual data, just need to get to draw to flag error |
| 8329 | static const float vbo_data[3] = {1.f, 0.f, 1.f}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8330 | VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), |
| 8331 | (const void *)&vbo_data); |
Tobin Ehlis | f7bf450 | 2015-09-09 15:12:35 -0600 | [diff] [blame] | 8332 | 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] | 8333 | Draw(1, 0, 0, 0); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 8334 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8335 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | d1c84a5 | 2015-08-18 14:40:24 -0600 | [diff] [blame] | 8336 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8337 | vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL); |
| 8338 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 8339 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | 502480b | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 8340 | } |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 8341 | // INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here) |
| 8342 | TEST_F(VkLayerTest, InvalidImageLayout) { |
| 8343 | TEST_DESCRIPTION("Hit all possible validation checks associated with the " |
| 8344 | "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having" |
| 8345 | "images in the wrong layout when they're copied or transitioned."); |
| 8346 | // 3 in ValidateCmdBufImageLayouts |
| 8347 | // * -1 Attempt to submit cmd buf w/ deleted image |
| 8348 | // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource |
| 8349 | // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource |
| 8350 | m_errorMonitor->SetDesiredFailureMsg( |
| 8351 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 8352 | "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL."); |
| 8353 | |
| 8354 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8355 | // Create src & dst images to use for copy operations |
| 8356 | VkImage src_image; |
| 8357 | VkImage dst_image; |
| 8358 | |
| 8359 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 8360 | const int32_t tex_width = 32; |
| 8361 | const int32_t tex_height = 32; |
| 8362 | |
| 8363 | VkImageCreateInfo image_create_info = {}; |
| 8364 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 8365 | image_create_info.pNext = NULL; |
| 8366 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 8367 | image_create_info.format = tex_format; |
| 8368 | image_create_info.extent.width = tex_width; |
| 8369 | image_create_info.extent.height = tex_height; |
| 8370 | image_create_info.extent.depth = 1; |
| 8371 | image_create_info.mipLevels = 1; |
| 8372 | image_create_info.arrayLayers = 4; |
| 8373 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 8374 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 8375 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 8376 | image_create_info.flags = 0; |
| 8377 | |
| 8378 | VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image); |
| 8379 | ASSERT_VK_SUCCESS(err); |
| 8380 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image); |
| 8381 | ASSERT_VK_SUCCESS(err); |
| 8382 | |
| 8383 | BeginCommandBuffer(); |
| 8384 | VkImageCopy copyRegion; |
| 8385 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 8386 | copyRegion.srcSubresource.mipLevel = 0; |
| 8387 | copyRegion.srcSubresource.baseArrayLayer = 0; |
| 8388 | copyRegion.srcSubresource.layerCount = 1; |
| 8389 | copyRegion.srcOffset.x = 0; |
| 8390 | copyRegion.srcOffset.y = 0; |
| 8391 | copyRegion.srcOffset.z = 0; |
| 8392 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 8393 | copyRegion.dstSubresource.mipLevel = 0; |
| 8394 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 8395 | copyRegion.dstSubresource.layerCount = 1; |
| 8396 | copyRegion.dstOffset.x = 0; |
| 8397 | copyRegion.dstOffset.y = 0; |
| 8398 | copyRegion.dstOffset.z = 0; |
| 8399 | copyRegion.extent.width = 1; |
| 8400 | copyRegion.extent.height = 1; |
| 8401 | copyRegion.extent.depth = 1; |
| 8402 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 8403 | m_errorMonitor->VerifyFound(); |
| 8404 | // Now cause error due to src image layout changing |
| 8405 | m_errorMonitor->SetDesiredFailureMsg( |
| 8406 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8407 | "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL."); |
| 8408 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 8409 | m_errorMonitor->VerifyFound(); |
| 8410 | // Final src error is due to bad layout type |
| 8411 | m_errorMonitor->SetDesiredFailureMsg( |
| 8412 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8413 | "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL."); |
| 8414 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 8415 | m_errorMonitor->VerifyFound(); |
| 8416 | // Now verify same checks for dst |
| 8417 | m_errorMonitor->SetDesiredFailureMsg( |
| 8418 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 8419 | "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL."); |
| 8420 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 8421 | m_errorMonitor->VerifyFound(); |
| 8422 | // Now cause error due to src image layout changing |
| 8423 | m_errorMonitor->SetDesiredFailureMsg( |
| 8424 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8425 | "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout VK_IMAGE_LAYOUT_GENERAL."); |
| 8426 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, ©Region); |
| 8427 | m_errorMonitor->VerifyFound(); |
| 8428 | m_errorMonitor->SetDesiredFailureMsg( |
| 8429 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8430 | "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL."); |
| 8431 | m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_UNDEFINED, 1, ©Region); |
| 8432 | m_errorMonitor->VerifyFound(); |
| 8433 | // Now cause error due to bad image layout transition in PipelineBarrier |
| 8434 | VkImageMemoryBarrier image_barrier[1] = {}; |
| 8435 | image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 8436 | image_barrier[0].image = src_image; |
| 8437 | image_barrier[0].subresourceRange.layerCount = 2; |
| 8438 | image_barrier[0].subresourceRange.levelCount = 2; |
| 8439 | image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 8440 | m_errorMonitor->SetDesiredFailureMsg( |
| 8441 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8442 | "You cannot transition the layout from VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is VK_IMAGE_LAYOUT_GENERAL."); |
| 8443 | vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, NULL, 0, NULL, 1, image_barrier); |
| 8444 | m_errorMonitor->VerifyFound(); |
| 8445 | |
| 8446 | // Finally some layout errors at RenderPass create time |
| 8447 | // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing. |
| 8448 | VkAttachmentReference attach = {}; |
| 8449 | // perf warning for GENERAL layout w/ non-DS input attachment |
| 8450 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 8451 | VkSubpassDescription subpass = {}; |
| 8452 | subpass.inputAttachmentCount = 1; |
| 8453 | subpass.pInputAttachments = &attach; |
| 8454 | VkRenderPassCreateInfo rpci = {}; |
| 8455 | rpci.subpassCount = 1; |
| 8456 | rpci.pSubpasses = &subpass; |
| 8457 | rpci.attachmentCount = 1; |
| 8458 | VkAttachmentDescription attach_desc = {}; |
| 8459 | attach_desc.format = VK_FORMAT_UNDEFINED; |
| 8460 | rpci.pAttachments = &attach_desc; |
Tobin Ehlis | 1efce02 | 2016-05-11 10:40:34 -0600 | [diff] [blame] | 8461 | rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 8462 | VkRenderPass rp; |
| 8463 | m_errorMonitor->SetDesiredFailureMsg( |
| 8464 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 8465 | "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL."); |
| 8466 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 8467 | m_errorMonitor->VerifyFound(); |
| 8468 | // error w/ non-general layout |
| 8469 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 8470 | |
| 8471 | m_errorMonitor->SetDesiredFailureMsg( |
| 8472 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8473 | "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL."); |
| 8474 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 8475 | m_errorMonitor->VerifyFound(); |
| 8476 | subpass.inputAttachmentCount = 0; |
| 8477 | subpass.colorAttachmentCount = 1; |
| 8478 | subpass.pColorAttachments = &attach; |
| 8479 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 8480 | // perf warning for GENERAL layout on color attachment |
| 8481 | m_errorMonitor->SetDesiredFailureMsg( |
| 8482 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 8483 | "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL."); |
| 8484 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 8485 | m_errorMonitor->VerifyFound(); |
| 8486 | // error w/ non-color opt or GENERAL layout for color attachment |
| 8487 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 8488 | m_errorMonitor->SetDesiredFailureMsg( |
| 8489 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8490 | "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL."); |
| 8491 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 8492 | m_errorMonitor->VerifyFound(); |
| 8493 | subpass.colorAttachmentCount = 0; |
| 8494 | subpass.pDepthStencilAttachment = &attach; |
| 8495 | attach.layout = VK_IMAGE_LAYOUT_GENERAL; |
| 8496 | // perf warning for GENERAL layout on DS attachment |
| 8497 | m_errorMonitor->SetDesiredFailureMsg( |
| 8498 | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
| 8499 | "Layout for depth attachment is GENERAL but should be DEPTH_STENCIL_ATTACHMENT_OPTIMAL."); |
| 8500 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 8501 | m_errorMonitor->VerifyFound(); |
| 8502 | // error w/ non-ds opt or GENERAL layout for color attachment |
| 8503 | attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; |
| 8504 | m_errorMonitor->SetDesiredFailureMsg( |
| 8505 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8506 | "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be DEPTH_STENCIL_ATTACHMENT_OPTIMAL or GENERAL."); |
| 8507 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 8508 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | 1efce02 | 2016-05-11 10:40:34 -0600 | [diff] [blame] | 8509 | // For this error we need a valid renderpass so create default one |
| 8510 | attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 8511 | attach.attachment = 0; |
| 8512 | attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 8513 | attach_desc.samples = VK_SAMPLE_COUNT_1_BIT; |
| 8514 | attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE; |
| 8515 | attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 8516 | attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 8517 | // Can't do a CLEAR load on READ_ONLY initialLayout |
| 8518 | attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 8519 | attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; |
| 8520 | attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 8521 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8522 | " with invalid first layout " |
| 8523 | "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_" |
| 8524 | "ONLY_OPTIMAL"); |
| 8525 | vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp); |
| 8526 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | c555a3c | 2016-05-04 14:08:34 -0600 | [diff] [blame] | 8527 | |
| 8528 | vkDestroyImage(m_device->device(), src_image, NULL); |
| 8529 | vkDestroyImage(m_device->device(), dst_image, NULL); |
| 8530 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 8531 | #endif // DRAW_STATE_TESTS |
| 8532 | |
Tobin Ehlis | 0788f52 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 8533 | #if THREADING_TESTS |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 8534 | #if GTEST_IS_THREADSAFE |
| 8535 | struct thread_data_struct { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8536 | VkCommandBuffer commandBuffer; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 8537 | VkEvent event; |
| 8538 | bool bailout; |
| 8539 | }; |
| 8540 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8541 | extern "C" void *AddToCommandBuffer(void *arg) { |
| 8542 | struct thread_data_struct *data = (struct thread_data_struct *)arg; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 8543 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8544 | for (int i = 0; i < 10000; i++) { |
| 8545 | vkCmdSetEvent(data->commandBuffer, data->event, |
| 8546 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 8547 | if (data->bailout) { |
| 8548 | break; |
| 8549 | } |
| 8550 | } |
| 8551 | return NULL; |
| 8552 | } |
| 8553 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8554 | TEST_F(VkLayerTest, ThreadCommandBufferCollision) { |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 8555 | test_platform_thread thread; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 8556 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8557 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8558 | "THREADING ERROR"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8559 | |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 8560 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8561 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 8562 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8563 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8564 | // Calls AllocateCommandBuffers |
| 8565 | VkCommandBufferObj commandBuffer(m_device, m_commandPool); |
Mark Lobodzinski | 5495d13 | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 8566 | |
| 8567 | // Avoid creating RenderPass |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8568 | commandBuffer.BeginCommandBuffer(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 8569 | |
| 8570 | VkEventCreateInfo event_info; |
| 8571 | VkEvent event; |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 8572 | VkResult err; |
| 8573 | |
| 8574 | memset(&event_info, 0, sizeof(event_info)); |
| 8575 | event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 8576 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8577 | err = vkCreateEvent(device(), &event_info, NULL, &event); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 8578 | ASSERT_VK_SUCCESS(err); |
| 8579 | |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 8580 | err = vkResetEvent(device(), event); |
| 8581 | ASSERT_VK_SUCCESS(err); |
| 8582 | |
| 8583 | struct thread_data_struct data; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8584 | data.commandBuffer = commandBuffer.GetBufferHandle(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 8585 | data.event = event; |
| 8586 | data.bailout = false; |
| 8587 | m_errorMonitor->SetBailout(&data.bailout); |
| 8588 | // Add many entries to command buffer from another thread. |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 8589 | test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 8590 | // Add many entries to command buffer from this thread at the same time. |
| 8591 | AddToCommandBuffer(&data); |
Mark Lobodzinski | 5495d13 | 2015-09-30 16:19:16 -0600 | [diff] [blame] | 8592 | |
Mike Stroyan | 4268d1f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 8593 | test_platform_thread_join(thread, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8594 | commandBuffer.EndCommandBuffer(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 8595 | |
Mike Stroyan | 10b8cb7 | 2016-01-22 15:22:03 -0700 | [diff] [blame] | 8596 | m_errorMonitor->SetBailout(NULL); |
| 8597 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8598 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 8599 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8600 | vkDestroyEvent(device(), event, NULL); |
Mike Stroyan | accf769 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 8601 | } |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 8602 | #endif // GTEST_IS_THREADSAFE |
| 8603 | #endif // THREADING_TESTS |
| 8604 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 8605 | #if SHADER_CHECKER_TESTS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8606 | TEST_F(VkLayerTest, InvalidSPIRVCodeSize) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 8607 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 8608 | "Invalid SPIR-V header"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8609 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 8610 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8611 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8612 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 8613 | VkShaderModule module; |
| 8614 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 8615 | struct icd_spv_header spv; |
| 8616 | |
| 8617 | spv.magic = ICD_SPV_MAGIC; |
| 8618 | spv.version = ICD_SPV_VERSION; |
| 8619 | spv.gen_magic = 0; |
| 8620 | |
| 8621 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 8622 | moduleCreateInfo.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8623 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 8624 | moduleCreateInfo.codeSize = 4; |
| 8625 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8626 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 8627 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8628 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 8629 | } |
| 8630 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8631 | TEST_F(VkLayerTest, InvalidSPIRVMagic) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 8632 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 8633 | "Invalid SPIR-V magic number"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8634 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 8635 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8636 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8637 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 8638 | VkShaderModule module; |
| 8639 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 8640 | struct icd_spv_header spv; |
| 8641 | |
| 8642 | spv.magic = ~ICD_SPV_MAGIC; |
| 8643 | spv.version = ICD_SPV_VERSION; |
| 8644 | spv.gen_magic = 0; |
| 8645 | |
| 8646 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 8647 | moduleCreateInfo.pNext = NULL; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8648 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 8649 | moduleCreateInfo.codeSize = sizeof(spv) + 10; |
| 8650 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8651 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 8652 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8653 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 8654 | } |
| 8655 | |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 8656 | #if 0 |
| 8657 | // Not currently covered by SPIRV-Tools validator |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8658 | TEST_F(VkLayerTest, InvalidSPIRVVersion) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 8659 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 8660 | "Invalid SPIR-V header"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8661 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 8662 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8663 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8664 | |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 8665 | VkShaderModule module; |
| 8666 | VkShaderModuleCreateInfo moduleCreateInfo; |
| 8667 | struct icd_spv_header spv; |
| 8668 | |
| 8669 | spv.magic = ICD_SPV_MAGIC; |
| 8670 | spv.version = ~ICD_SPV_VERSION; |
| 8671 | spv.gen_magic = 0; |
| 8672 | |
| 8673 | moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 8674 | moduleCreateInfo.pNext = NULL; |
| 8675 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8676 | moduleCreateInfo.pCode = (const uint32_t *)&spv; |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 8677 | moduleCreateInfo.codeSize = sizeof(spv) + 10; |
| 8678 | moduleCreateInfo.flags = 0; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 8679 | vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 8680 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8681 | m_errorMonitor->VerifyFound(); |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 8682 | } |
Chris Forbes | b4afd0f | 2016-04-04 10:48:35 +1200 | [diff] [blame] | 8683 | #endif |
Courtney Goeltzenleuchter | 00c52b2 | 2015-09-16 12:58:29 -0600 | [diff] [blame] | 8684 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8685 | TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 8686 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8687 | "not consumed by fragment shader"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8688 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 8689 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 8690 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 8691 | |
| 8692 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 8693 | "#version 450\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 8694 | "\n" |
| 8695 | "layout(location=0) out float x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 8696 | "out gl_PerVertex {\n" |
| 8697 | " vec4 gl_Position;\n" |
| 8698 | "};\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 8699 | "void main(){\n" |
| 8700 | " gl_Position = vec4(1);\n" |
| 8701 | " x = 0;\n" |
| 8702 | "}\n"; |
| 8703 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 8704 | "#version 450\n" |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 8705 | "\n" |
| 8706 | "layout(location=0) out vec4 color;\n" |
| 8707 | "void main(){\n" |
| 8708 | " color = vec4(1);\n" |
| 8709 | "}\n"; |
| 8710 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 8711 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 8712 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 8713 | |
| 8714 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 8715 | pipe.AddColorAttachment(); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 8716 | pipe.AddShader(&vs); |
| 8717 | pipe.AddShader(&fs); |
| 8718 | |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 8719 | VkDescriptorSetObj descriptorSet(m_device); |
| 8720 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8721 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 8722 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 8723 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 8724 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8725 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 8726 | } |
Chris Forbes | 9f7ff63 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 8727 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8728 | TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 8729 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8730 | "not written by vertex shader"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8731 | |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 8732 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 8733 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 8734 | |
| 8735 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 8736 | "#version 450\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 8737 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 8738 | "out gl_PerVertex {\n" |
| 8739 | " vec4 gl_Position;\n" |
| 8740 | "};\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 8741 | "void main(){\n" |
| 8742 | " gl_Position = vec4(1);\n" |
| 8743 | "}\n"; |
| 8744 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 8745 | "#version 450\n" |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 8746 | "\n" |
| 8747 | "layout(location=0) in float x;\n" |
| 8748 | "layout(location=0) out vec4 color;\n" |
| 8749 | "void main(){\n" |
| 8750 | " color = vec4(x);\n" |
| 8751 | "}\n"; |
| 8752 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 8753 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 8754 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 8755 | |
| 8756 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 8757 | pipe.AddColorAttachment(); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 8758 | pipe.AddShader(&vs); |
| 8759 | pipe.AddShader(&fs); |
| 8760 | |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 8761 | VkDescriptorSetObj descriptorSet(m_device); |
| 8762 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8763 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 8764 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 8765 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 8766 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8767 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 59cb88d | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 8768 | } |
| 8769 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8770 | TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) { |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 8771 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8772 | "not written by vertex shader"); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 8773 | |
| 8774 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8775 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8776 | |
| 8777 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 8778 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 8779 | "\n" |
| 8780 | "out gl_PerVertex {\n" |
| 8781 | " vec4 gl_Position;\n" |
| 8782 | "};\n" |
| 8783 | "void main(){\n" |
| 8784 | " gl_Position = vec4(1);\n" |
| 8785 | "}\n"; |
| 8786 | char const *fsSource = |
| 8787 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 8788 | "\n" |
| 8789 | "in block { layout(location=0) float x; } ins;\n" |
| 8790 | "layout(location=0) out vec4 color;\n" |
| 8791 | "void main(){\n" |
| 8792 | " color = vec4(ins.x);\n" |
| 8793 | "}\n"; |
| 8794 | |
| 8795 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 8796 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 8797 | |
| 8798 | VkPipelineObj pipe(m_device); |
| 8799 | pipe.AddColorAttachment(); |
| 8800 | pipe.AddShader(&vs); |
| 8801 | pipe.AddShader(&fs); |
| 8802 | |
| 8803 | VkDescriptorSetObj descriptorSet(m_device); |
| 8804 | descriptorSet.AppendDummy(); |
| 8805 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 8806 | |
| 8807 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 8808 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8809 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 8810 | } |
| 8811 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8812 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) { |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 8813 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 8814 | "Type mismatch on location 0.0: 'ptr to " |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8815 | "output arr[2] of float32' vs 'ptr to " |
| 8816 | "input arr[3] of float32'"); |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 8817 | |
| 8818 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8819 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8820 | |
| 8821 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 8822 | "#version 450\n" |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 8823 | "\n" |
| 8824 | "layout(location=0) out float x[2];\n" |
| 8825 | "out gl_PerVertex {\n" |
| 8826 | " vec4 gl_Position;\n" |
| 8827 | "};\n" |
| 8828 | "void main(){\n" |
| 8829 | " x[0] = 0; x[1] = 0;\n" |
| 8830 | " gl_Position = vec4(1);\n" |
| 8831 | "}\n"; |
| 8832 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 8833 | "#version 450\n" |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 8834 | "\n" |
| 8835 | "layout(location=0) in float x[3];\n" |
| 8836 | "layout(location=0) out vec4 color;\n" |
| 8837 | "void main(){\n" |
| 8838 | " color = vec4(x[0] + x[1] + x[2]);\n" |
| 8839 | "}\n"; |
| 8840 | |
| 8841 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 8842 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 8843 | |
| 8844 | VkPipelineObj pipe(m_device); |
| 8845 | pipe.AddColorAttachment(); |
| 8846 | pipe.AddShader(&vs); |
| 8847 | pipe.AddShader(&fs); |
| 8848 | |
| 8849 | VkDescriptorSetObj descriptorSet(m_device); |
| 8850 | descriptorSet.AppendDummy(); |
| 8851 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 8852 | |
| 8853 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 8854 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8855 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 0036fd1 | 2016-01-26 14:19:49 +1300 | [diff] [blame] | 8856 | } |
| 8857 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8858 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 8859 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8860 | "Type mismatch on location 0"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 8861 | |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 8862 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 8863 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 8864 | |
| 8865 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 8866 | "#version 450\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 8867 | "\n" |
| 8868 | "layout(location=0) out int x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 8869 | "out gl_PerVertex {\n" |
| 8870 | " vec4 gl_Position;\n" |
| 8871 | "};\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 8872 | "void main(){\n" |
| 8873 | " x = 0;\n" |
| 8874 | " gl_Position = vec4(1);\n" |
| 8875 | "}\n"; |
| 8876 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 8877 | "#version 450\n" |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 8878 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8879 | "layout(location=0) in float x;\n" /* VS writes int */ |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 8880 | "layout(location=0) out vec4 color;\n" |
| 8881 | "void main(){\n" |
| 8882 | " color = vec4(x);\n" |
| 8883 | "}\n"; |
| 8884 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 8885 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 8886 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 8887 | |
| 8888 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 8889 | pipe.AddColorAttachment(); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 8890 | pipe.AddShader(&vs); |
| 8891 | pipe.AddShader(&fs); |
| 8892 | |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 8893 | VkDescriptorSetObj descriptorSet(m_device); |
| 8894 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 8895 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 8896 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 8897 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 8898 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8899 | m_errorMonitor->VerifyFound(); |
Chris Forbes | b56af56 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 8900 | } |
| 8901 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8902 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) { |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 8903 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8904 | "Type mismatch on location 0"); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 8905 | |
| 8906 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8907 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8908 | |
| 8909 | char const *vsSource = |
| 8910 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 8911 | "\n" |
| 8912 | "out block { layout(location=0) int x; } outs;\n" |
| 8913 | "out gl_PerVertex {\n" |
| 8914 | " vec4 gl_Position;\n" |
| 8915 | "};\n" |
| 8916 | "void main(){\n" |
| 8917 | " outs.x = 0;\n" |
| 8918 | " gl_Position = vec4(1);\n" |
| 8919 | "}\n"; |
| 8920 | char const *fsSource = |
| 8921 | "#version 450\n" |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 8922 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 8923 | "in block { layout(location=0) float x; } ins;\n" /* VS writes int */ |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 8924 | "layout(location=0) out vec4 color;\n" |
| 8925 | "void main(){\n" |
| 8926 | " color = vec4(ins.x);\n" |
| 8927 | "}\n"; |
| 8928 | |
| 8929 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 8930 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 8931 | |
| 8932 | VkPipelineObj pipe(m_device); |
| 8933 | pipe.AddColorAttachment(); |
| 8934 | pipe.AddShader(&vs); |
| 8935 | pipe.AddShader(&fs); |
| 8936 | |
| 8937 | VkDescriptorSetObj descriptorSet(m_device); |
| 8938 | descriptorSet.AppendDummy(); |
| 8939 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 8940 | |
| 8941 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 8942 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8943 | m_errorMonitor->VerifyFound(); |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 8944 | } |
| 8945 | |
| 8946 | TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) { |
| 8947 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8948 | "location 0.0 which is not written by vertex shader"); |
| 8949 | |
| 8950 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8951 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8952 | |
| 8953 | char const *vsSource = |
| 8954 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 8955 | "\n" |
| 8956 | "out block { layout(location=1) float x; } outs;\n" |
| 8957 | "out gl_PerVertex {\n" |
| 8958 | " vec4 gl_Position;\n" |
| 8959 | "};\n" |
| 8960 | "void main(){\n" |
| 8961 | " outs.x = 0;\n" |
| 8962 | " gl_Position = vec4(1);\n" |
| 8963 | "}\n"; |
| 8964 | char const *fsSource = |
| 8965 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 8966 | "\n" |
| 8967 | "in block { layout(location=0) float x; } ins;\n" |
| 8968 | "layout(location=0) out vec4 color;\n" |
| 8969 | "void main(){\n" |
| 8970 | " color = vec4(ins.x);\n" |
| 8971 | "}\n"; |
| 8972 | |
| 8973 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 8974 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 8975 | |
| 8976 | VkPipelineObj pipe(m_device); |
| 8977 | pipe.AddColorAttachment(); |
| 8978 | pipe.AddShader(&vs); |
| 8979 | pipe.AddShader(&fs); |
| 8980 | |
| 8981 | VkDescriptorSetObj descriptorSet(m_device); |
| 8982 | descriptorSet.AppendDummy(); |
| 8983 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 8984 | |
| 8985 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 8986 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 8987 | m_errorMonitor->VerifyFound(); |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 8988 | } |
| 8989 | |
| 8990 | TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) { |
| 8991 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 8992 | "location 0.1 which is not written by vertex shader"); |
| 8993 | |
| 8994 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 8995 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 8996 | |
| 8997 | char const *vsSource = |
| 8998 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 8999 | "\n" |
| 9000 | "out block { layout(location=0, component=0) float x; } outs;\n" |
| 9001 | "out gl_PerVertex {\n" |
| 9002 | " vec4 gl_Position;\n" |
| 9003 | "};\n" |
| 9004 | "void main(){\n" |
| 9005 | " outs.x = 0;\n" |
| 9006 | " gl_Position = vec4(1);\n" |
| 9007 | "}\n"; |
| 9008 | char const *fsSource = |
| 9009 | "#version 450\n" |
Chris Forbes | e992882 | 2016-02-17 14:44:52 +1300 | [diff] [blame] | 9010 | "\n" |
| 9011 | "in block { layout(location=0, component=1) float x; } ins;\n" |
| 9012 | "layout(location=0) out vec4 color;\n" |
| 9013 | "void main(){\n" |
| 9014 | " color = vec4(ins.x);\n" |
| 9015 | "}\n"; |
| 9016 | |
| 9017 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9018 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 9019 | |
| 9020 | VkPipelineObj pipe(m_device); |
| 9021 | pipe.AddColorAttachment(); |
| 9022 | pipe.AddShader(&vs); |
| 9023 | pipe.AddShader(&fs); |
| 9024 | |
| 9025 | VkDescriptorSetObj descriptorSet(m_device); |
| 9026 | descriptorSet.AppendDummy(); |
| 9027 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 9028 | |
| 9029 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 9030 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9031 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a3e85f6 | 2016-01-15 14:53:11 +1300 | [diff] [blame] | 9032 | } |
| 9033 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9034 | TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 9035 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9036 | "location 0 not consumed by VS"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9037 | |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 9038 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 9039 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 9040 | |
| 9041 | VkVertexInputBindingDescription input_binding; |
| 9042 | memset(&input_binding, 0, sizeof(input_binding)); |
| 9043 | |
| 9044 | VkVertexInputAttributeDescription input_attrib; |
| 9045 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 9046 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 9047 | |
| 9048 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9049 | "#version 450\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 9050 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 9051 | "out gl_PerVertex {\n" |
| 9052 | " vec4 gl_Position;\n" |
| 9053 | "};\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 9054 | "void main(){\n" |
| 9055 | " gl_Position = vec4(1);\n" |
| 9056 | "}\n"; |
| 9057 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9058 | "#version 450\n" |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 9059 | "\n" |
| 9060 | "layout(location=0) out vec4 color;\n" |
| 9061 | "void main(){\n" |
| 9062 | " color = vec4(1);\n" |
| 9063 | "}\n"; |
| 9064 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 9065 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9066 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 9067 | |
| 9068 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 9069 | pipe.AddColorAttachment(); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 9070 | pipe.AddShader(&vs); |
| 9071 | pipe.AddShader(&fs); |
| 9072 | |
| 9073 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 9074 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 9075 | |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 9076 | VkDescriptorSetObj descriptorSet(m_device); |
| 9077 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9078 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 9079 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 9080 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 9081 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9082 | m_errorMonitor->VerifyFound(); |
Chris Forbes | de136e0 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 9083 | } |
| 9084 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9085 | TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 9086 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9087 | "location 0 not consumed by VS"); |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 9088 | |
| 9089 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9090 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9091 | |
| 9092 | VkVertexInputBindingDescription input_binding; |
| 9093 | memset(&input_binding, 0, sizeof(input_binding)); |
| 9094 | |
| 9095 | VkVertexInputAttributeDescription input_attrib; |
| 9096 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 9097 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 9098 | |
| 9099 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9100 | "#version 450\n" |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 9101 | "\n" |
| 9102 | "layout(location=1) in float x;\n" |
| 9103 | "out gl_PerVertex {\n" |
| 9104 | " vec4 gl_Position;\n" |
| 9105 | "};\n" |
| 9106 | "void main(){\n" |
| 9107 | " gl_Position = vec4(x);\n" |
| 9108 | "}\n"; |
| 9109 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9110 | "#version 450\n" |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 9111 | "\n" |
| 9112 | "layout(location=0) out vec4 color;\n" |
| 9113 | "void main(){\n" |
| 9114 | " color = vec4(1);\n" |
| 9115 | "}\n"; |
| 9116 | |
| 9117 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9118 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 9119 | |
| 9120 | VkPipelineObj pipe(m_device); |
| 9121 | pipe.AddColorAttachment(); |
| 9122 | pipe.AddShader(&vs); |
| 9123 | pipe.AddShader(&fs); |
| 9124 | |
| 9125 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 9126 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 9127 | |
| 9128 | VkDescriptorSetObj descriptorSet(m_device); |
| 9129 | descriptorSet.AppendDummy(); |
| 9130 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 9131 | |
| 9132 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 9133 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9134 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 7d83cd5 | 2016-01-15 11:32:03 +1300 | [diff] [blame] | 9135 | } |
| 9136 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9137 | TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) { |
| 9138 | m_errorMonitor->SetDesiredFailureMsg( |
| 9139 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9140 | "VS consumes input at location 0 but not provided"); |
| 9141 | |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 9142 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 9143 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 9144 | |
| 9145 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9146 | "#version 450\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 9147 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9148 | "layout(location=0) in vec4 x;\n" /* not provided */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 9149 | "out gl_PerVertex {\n" |
| 9150 | " vec4 gl_Position;\n" |
| 9151 | "};\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 9152 | "void main(){\n" |
| 9153 | " gl_Position = x;\n" |
| 9154 | "}\n"; |
| 9155 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9156 | "#version 450\n" |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 9157 | "\n" |
| 9158 | "layout(location=0) out vec4 color;\n" |
| 9159 | "void main(){\n" |
| 9160 | " color = vec4(1);\n" |
| 9161 | "}\n"; |
| 9162 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 9163 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9164 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 9165 | |
| 9166 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 9167 | pipe.AddColorAttachment(); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 9168 | pipe.AddShader(&vs); |
| 9169 | pipe.AddShader(&fs); |
| 9170 | |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 9171 | VkDescriptorSetObj descriptorSet(m_device); |
| 9172 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9173 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 9174 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 9175 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 9176 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9177 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 62e8e50 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 9178 | } |
| 9179 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9180 | TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) { |
| 9181 | m_errorMonitor->SetDesiredFailureMsg( |
| 9182 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9183 | "location 0 does not match VS input type"); |
| 9184 | |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 9185 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 9186 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 9187 | |
| 9188 | VkVertexInputBindingDescription input_binding; |
| 9189 | memset(&input_binding, 0, sizeof(input_binding)); |
| 9190 | |
| 9191 | VkVertexInputAttributeDescription input_attrib; |
| 9192 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 9193 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 9194 | |
| 9195 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9196 | "#version 450\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 9197 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9198 | "layout(location=0) in int x;\n" /* attrib provided float */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 9199 | "out gl_PerVertex {\n" |
| 9200 | " vec4 gl_Position;\n" |
| 9201 | "};\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 9202 | "void main(){\n" |
| 9203 | " gl_Position = vec4(x);\n" |
| 9204 | "}\n"; |
| 9205 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9206 | "#version 450\n" |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 9207 | "\n" |
| 9208 | "layout(location=0) out vec4 color;\n" |
| 9209 | "void main(){\n" |
| 9210 | " color = vec4(1);\n" |
| 9211 | "}\n"; |
| 9212 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 9213 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9214 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 9215 | |
| 9216 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 9217 | pipe.AddColorAttachment(); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 9218 | pipe.AddShader(&vs); |
| 9219 | pipe.AddShader(&fs); |
| 9220 | |
| 9221 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 9222 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 9223 | |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 9224 | VkDescriptorSetObj descriptorSet(m_device); |
| 9225 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9226 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 9227 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 9228 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 9229 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9230 | m_errorMonitor->VerifyFound(); |
Chris Forbes | c97d98e | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 9231 | } |
| 9232 | |
Chris Forbes | c68b43c | 2016-04-06 11:18:47 +1200 | [diff] [blame] | 9233 | TEST_F(VkLayerTest, CreatePipelineDuplicateStage) { |
| 9234 | m_errorMonitor->SetDesiredFailureMsg( |
| 9235 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9236 | "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT"); |
| 9237 | |
| 9238 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9239 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9240 | |
| 9241 | char const *vsSource = |
| 9242 | "#version 450\n" |
| 9243 | "\n" |
| 9244 | "out gl_PerVertex {\n" |
| 9245 | " vec4 gl_Position;\n" |
| 9246 | "};\n" |
| 9247 | "void main(){\n" |
| 9248 | " gl_Position = vec4(1);\n" |
| 9249 | "}\n"; |
| 9250 | char const *fsSource = |
| 9251 | "#version 450\n" |
| 9252 | "\n" |
| 9253 | "layout(location=0) out vec4 color;\n" |
| 9254 | "void main(){\n" |
| 9255 | " color = vec4(1);\n" |
| 9256 | "}\n"; |
| 9257 | |
| 9258 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9259 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 9260 | |
| 9261 | VkPipelineObj pipe(m_device); |
| 9262 | pipe.AddColorAttachment(); |
| 9263 | pipe.AddShader(&vs); |
| 9264 | pipe.AddShader(&vs); |
| 9265 | pipe.AddShader(&fs); |
| 9266 | |
| 9267 | VkDescriptorSetObj descriptorSet(m_device); |
| 9268 | descriptorSet.AppendDummy(); |
| 9269 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 9270 | |
| 9271 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 9272 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9273 | m_errorMonitor->VerifyFound(); |
Chris Forbes | c68b43c | 2016-04-06 11:18:47 +1200 | [diff] [blame] | 9274 | } |
| 9275 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9276 | TEST_F(VkLayerTest, CreatePipelineAttribMatrixType) { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9277 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 9278 | |
| 9279 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9280 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9281 | |
| 9282 | VkVertexInputBindingDescription input_binding; |
| 9283 | memset(&input_binding, 0, sizeof(input_binding)); |
| 9284 | |
| 9285 | VkVertexInputAttributeDescription input_attribs[2]; |
| 9286 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 9287 | |
| 9288 | for (int i = 0; i < 2; i++) { |
| 9289 | input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 9290 | input_attribs[i].location = i; |
| 9291 | } |
| 9292 | |
| 9293 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9294 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 9295 | "\n" |
| 9296 | "layout(location=0) in mat2x4 x;\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 9297 | "out gl_PerVertex {\n" |
| 9298 | " vec4 gl_Position;\n" |
| 9299 | "};\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 9300 | "void main(){\n" |
| 9301 | " gl_Position = x[0] + x[1];\n" |
| 9302 | "}\n"; |
| 9303 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9304 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 9305 | "\n" |
| 9306 | "layout(location=0) out vec4 color;\n" |
| 9307 | "void main(){\n" |
| 9308 | " color = vec4(1);\n" |
| 9309 | "}\n"; |
| 9310 | |
| 9311 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9312 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 9313 | |
| 9314 | VkPipelineObj pipe(m_device); |
| 9315 | pipe.AddColorAttachment(); |
| 9316 | pipe.AddShader(&vs); |
| 9317 | pipe.AddShader(&fs); |
| 9318 | |
| 9319 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 9320 | pipe.AddVertexInputAttribs(input_attribs, 2); |
| 9321 | |
| 9322 | VkDescriptorSetObj descriptorSet(m_device); |
| 9323 | descriptorSet.AppendDummy(); |
| 9324 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 9325 | |
| 9326 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 9327 | |
| 9328 | /* expect success */ |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9329 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 9330 | } |
| 9331 | |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 9332 | TEST_F(VkLayerTest, CreatePipelineAttribArrayType) |
| 9333 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9334 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 9335 | |
| 9336 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9337 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9338 | |
| 9339 | VkVertexInputBindingDescription input_binding; |
| 9340 | memset(&input_binding, 0, sizeof(input_binding)); |
| 9341 | |
| 9342 | VkVertexInputAttributeDescription input_attribs[2]; |
| 9343 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 9344 | |
| 9345 | for (int i = 0; i < 2; i++) { |
| 9346 | input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT; |
| 9347 | input_attribs[i].location = i; |
| 9348 | } |
| 9349 | |
| 9350 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9351 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 9352 | "\n" |
| 9353 | "layout(location=0) in vec4 x[2];\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 9354 | "out gl_PerVertex {\n" |
| 9355 | " vec4 gl_Position;\n" |
| 9356 | "};\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 9357 | "void main(){\n" |
| 9358 | " gl_Position = x[0] + x[1];\n" |
| 9359 | "}\n"; |
| 9360 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9361 | "#version 450\n" |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 9362 | "\n" |
| 9363 | "layout(location=0) out vec4 color;\n" |
| 9364 | "void main(){\n" |
| 9365 | " color = vec4(1);\n" |
| 9366 | "}\n"; |
| 9367 | |
| 9368 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9369 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 9370 | |
| 9371 | VkPipelineObj pipe(m_device); |
| 9372 | pipe.AddColorAttachment(); |
| 9373 | pipe.AddShader(&vs); |
| 9374 | pipe.AddShader(&fs); |
| 9375 | |
| 9376 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 9377 | pipe.AddVertexInputAttribs(input_attribs, 2); |
| 9378 | |
| 9379 | VkDescriptorSetObj descriptorSet(m_device); |
| 9380 | descriptorSet.AppendDummy(); |
| 9381 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 9382 | |
| 9383 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 9384 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9385 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 9386 | } |
Chris Forbes | 2682b24 | 2015-11-24 11:13:14 +1300 | [diff] [blame] | 9387 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 9388 | TEST_F(VkLayerTest, CreatePipelineSimplePositive) |
| 9389 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9390 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 9391 | |
| 9392 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9393 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9394 | |
| 9395 | char const *vsSource = |
| 9396 | "#version 450\n" |
| 9397 | "out gl_PerVertex {\n" |
| 9398 | " vec4 gl_Position;\n" |
| 9399 | "};\n" |
| 9400 | "void main(){\n" |
| 9401 | " gl_Position = vec4(0);\n" |
| 9402 | "}\n"; |
| 9403 | char const *fsSource = |
| 9404 | "#version 450\n" |
| 9405 | "\n" |
| 9406 | "layout(location=0) out vec4 color;\n" |
| 9407 | "void main(){\n" |
| 9408 | " color = vec4(1);\n" |
| 9409 | "}\n"; |
| 9410 | |
| 9411 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9412 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 9413 | |
| 9414 | VkPipelineObj pipe(m_device); |
| 9415 | pipe.AddColorAttachment(); |
| 9416 | pipe.AddShader(&vs); |
| 9417 | pipe.AddShader(&fs); |
| 9418 | |
| 9419 | VkDescriptorSetObj descriptorSet(m_device); |
| 9420 | descriptorSet.AppendDummy(); |
| 9421 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 9422 | |
| 9423 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 9424 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9425 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 9426 | } |
| 9427 | |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 9428 | TEST_F(VkLayerTest, CreatePipelineRelaxedTypeMatch) |
| 9429 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9430 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 9431 | |
| 9432 | // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block |
| 9433 | |
| 9434 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9435 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9436 | |
| 9437 | char const *vsSource = |
| 9438 | "#version 450\n" |
| 9439 | "out gl_PerVertex {\n" |
| 9440 | " vec4 gl_Position;\n" |
| 9441 | "};\n" |
| 9442 | "layout(location=0) out vec3 x;\n" |
| 9443 | "layout(location=1) out ivec3 y;\n" |
| 9444 | "layout(location=2) out vec3 z;\n" |
| 9445 | "void main(){\n" |
| 9446 | " gl_Position = vec4(0);\n" |
| 9447 | " x = vec3(0); y = ivec3(0); z = vec3(0);\n" |
| 9448 | "}\n"; |
| 9449 | char const *fsSource = |
| 9450 | "#version 450\n" |
| 9451 | "\n" |
| 9452 | "layout(location=0) out vec4 color;\n" |
| 9453 | "layout(location=0) in float x;\n" |
| 9454 | "layout(location=1) flat in int y;\n" |
| 9455 | "layout(location=2) in vec2 z;\n" |
| 9456 | "void main(){\n" |
| 9457 | " color = vec4(1 + x + y + z.x);\n" |
| 9458 | "}\n"; |
| 9459 | |
| 9460 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9461 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 9462 | |
| 9463 | VkPipelineObj pipe(m_device); |
| 9464 | pipe.AddColorAttachment(); |
| 9465 | pipe.AddShader(&vs); |
| 9466 | pipe.AddShader(&fs); |
| 9467 | |
| 9468 | VkDescriptorSetObj descriptorSet(m_device); |
| 9469 | descriptorSet.AppendDummy(); |
| 9470 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 9471 | |
| 9472 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 9473 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9474 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 912c919 | 2016-04-05 17:50:35 +1200 | [diff] [blame] | 9475 | } |
| 9476 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 9477 | TEST_F(VkLayerTest, CreatePipelineTessPerVertex) |
| 9478 | { |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9479 | m_errorMonitor->ExpectSuccess(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 9480 | |
| 9481 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9482 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9483 | |
Chris Forbes | c1e852d | 2016-04-04 19:26:42 +1200 | [diff] [blame] | 9484 | if (!m_device->phy().features().tessellationShader) { |
| 9485 | printf("Device does not support tessellation shaders; skipped.\n"); |
| 9486 | return; |
| 9487 | } |
| 9488 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 9489 | char const *vsSource = |
| 9490 | "#version 450\n" |
| 9491 | "void main(){}\n"; |
| 9492 | char const *tcsSource = |
| 9493 | "#version 450\n" |
| 9494 | "layout(location=0) out int x[];\n" |
| 9495 | "layout(vertices=3) out;\n" |
| 9496 | "void main(){\n" |
| 9497 | " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n" |
| 9498 | " gl_TessLevelInner[0] = 1;\n" |
| 9499 | " x[gl_InvocationID] = gl_InvocationID;\n" |
| 9500 | "}\n"; |
| 9501 | char const *tesSource = |
| 9502 | "#version 450\n" |
| 9503 | "layout(triangles, equal_spacing, cw) in;\n" |
| 9504 | "layout(location=0) in int x[];\n" |
| 9505 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 9506 | "void main(){\n" |
| 9507 | " gl_Position.xyz = gl_TessCoord;\n" |
| 9508 | " gl_Position.w = x[0] + x[1] + x[2];\n" |
| 9509 | "}\n"; |
| 9510 | char const *fsSource = |
| 9511 | "#version 450\n" |
| 9512 | "layout(location=0) out vec4 color;\n" |
| 9513 | "void main(){\n" |
| 9514 | " color = vec4(1);\n" |
| 9515 | "}\n"; |
| 9516 | |
| 9517 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9518 | VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this); |
| 9519 | VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this); |
| 9520 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 9521 | |
| 9522 | VkPipelineInputAssemblyStateCreateInfo iasci{ |
| 9523 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, |
| 9524 | nullptr, |
| 9525 | 0, |
| 9526 | VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, |
| 9527 | VK_FALSE}; |
| 9528 | |
Chris Forbes | b4cacb6 | 2016-04-04 19:15:00 +1200 | [diff] [blame] | 9529 | VkPipelineTessellationStateCreateInfo tsci{ |
| 9530 | VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, |
| 9531 | nullptr, |
| 9532 | 0, |
| 9533 | 3}; |
| 9534 | |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 9535 | VkPipelineObj pipe(m_device); |
| 9536 | pipe.SetInputAssembly(&iasci); |
Chris Forbes | b4cacb6 | 2016-04-04 19:15:00 +1200 | [diff] [blame] | 9537 | pipe.SetTessellation(&tsci); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 9538 | pipe.AddColorAttachment(); |
| 9539 | pipe.AddShader(&vs); |
| 9540 | pipe.AddShader(&tcs); |
| 9541 | pipe.AddShader(&tes); |
| 9542 | pipe.AddShader(&fs); |
| 9543 | |
| 9544 | VkDescriptorSetObj descriptorSet(m_device); |
| 9545 | descriptorSet.AppendDummy(); |
| 9546 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 9547 | |
| 9548 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 9549 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9550 | m_errorMonitor->VerifyNotFound(); |
Chris Forbes | 4ea14fc | 2016-04-04 18:52:54 +1200 | [diff] [blame] | 9551 | } |
| 9552 | |
Chris Forbes | a0ab815 | 2016-04-20 13:34:27 +1200 | [diff] [blame] | 9553 | TEST_F(VkLayerTest, CreatePipelineGeometryInputBlockPositive) |
| 9554 | { |
| 9555 | m_errorMonitor->ExpectSuccess(); |
| 9556 | |
| 9557 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9558 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9559 | |
| 9560 | if (!m_device->phy().features().geometryShader) { |
| 9561 | printf("Device does not support geometry shaders; skipped.\n"); |
| 9562 | return; |
| 9563 | } |
| 9564 | |
| 9565 | char const *vsSource = |
| 9566 | "#version 450\n" |
| 9567 | "layout(location=0) out VertexData { vec4 x; } vs_out;\n" |
| 9568 | "void main(){\n" |
| 9569 | " vs_out.x = vec4(1);\n" |
| 9570 | "}\n"; |
| 9571 | char const *gsSource = |
| 9572 | "#version 450\n" |
| 9573 | "layout(triangles) in;\n" |
| 9574 | "layout(triangle_strip, max_vertices=3) out;\n" |
| 9575 | "layout(location=0) in VertexData { vec4 x; } gs_in[];\n" |
| 9576 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 9577 | "void main() {\n" |
| 9578 | " gl_Position = gs_in[0].x;\n" |
| 9579 | " EmitVertex();\n" |
| 9580 | "}\n"; |
| 9581 | char const *fsSource = |
| 9582 | "#version 450\n" |
| 9583 | "layout(location=0) out vec4 color;\n" |
| 9584 | "void main(){\n" |
| 9585 | " color = vec4(1);\n" |
| 9586 | "}\n"; |
| 9587 | |
| 9588 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9589 | VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this); |
| 9590 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 9591 | |
| 9592 | VkPipelineObj pipe(m_device); |
| 9593 | pipe.AddColorAttachment(); |
| 9594 | pipe.AddShader(&vs); |
| 9595 | pipe.AddShader(&gs); |
| 9596 | pipe.AddShader(&fs); |
| 9597 | |
| 9598 | VkDescriptorSetObj descriptorSet(m_device); |
| 9599 | descriptorSet.AppendDummy(); |
| 9600 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 9601 | |
| 9602 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 9603 | |
| 9604 | m_errorMonitor->VerifyNotFound(); |
| 9605 | } |
| 9606 | |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 9607 | TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) |
| 9608 | { |
| 9609 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9610 | "is per-vertex in tessellation control shader stage " |
| 9611 | "but per-patch in tessellation evaluation shader stage"); |
| 9612 | |
| 9613 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9614 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9615 | |
Chris Forbes | c1e852d | 2016-04-04 19:26:42 +1200 | [diff] [blame] | 9616 | if (!m_device->phy().features().tessellationShader) { |
| 9617 | printf("Device does not support tessellation shaders; skipped.\n"); |
| 9618 | return; |
| 9619 | } |
| 9620 | |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 9621 | char const *vsSource = |
| 9622 | "#version 450\n" |
| 9623 | "void main(){}\n"; |
| 9624 | char const *tcsSource = |
| 9625 | "#version 450\n" |
| 9626 | "layout(location=0) out int x[];\n" |
| 9627 | "layout(vertices=3) out;\n" |
| 9628 | "void main(){\n" |
| 9629 | " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n" |
| 9630 | " gl_TessLevelInner[0] = 1;\n" |
| 9631 | " x[gl_InvocationID] = gl_InvocationID;\n" |
| 9632 | "}\n"; |
| 9633 | char const *tesSource = |
| 9634 | "#version 450\n" |
| 9635 | "layout(triangles, equal_spacing, cw) in;\n" |
| 9636 | "layout(location=0) patch in int x;\n" |
| 9637 | "out gl_PerVertex { vec4 gl_Position; };\n" |
| 9638 | "void main(){\n" |
| 9639 | " gl_Position.xyz = gl_TessCoord;\n" |
| 9640 | " gl_Position.w = x;\n" |
| 9641 | "}\n"; |
| 9642 | char const *fsSource = |
| 9643 | "#version 450\n" |
| 9644 | "layout(location=0) out vec4 color;\n" |
| 9645 | "void main(){\n" |
| 9646 | " color = vec4(1);\n" |
| 9647 | "}\n"; |
| 9648 | |
| 9649 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9650 | VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this); |
| 9651 | VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this); |
| 9652 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 9653 | |
| 9654 | VkPipelineInputAssemblyStateCreateInfo iasci{ |
| 9655 | VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, |
| 9656 | nullptr, |
| 9657 | 0, |
| 9658 | VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, |
| 9659 | VK_FALSE}; |
| 9660 | |
| 9661 | VkPipelineTessellationStateCreateInfo tsci{ |
| 9662 | VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, |
| 9663 | nullptr, |
| 9664 | 0, |
| 9665 | 3}; |
| 9666 | |
| 9667 | VkPipelineObj pipe(m_device); |
| 9668 | pipe.SetInputAssembly(&iasci); |
| 9669 | pipe.SetTessellation(&tsci); |
| 9670 | pipe.AddColorAttachment(); |
| 9671 | pipe.AddShader(&vs); |
| 9672 | pipe.AddShader(&tcs); |
| 9673 | pipe.AddShader(&tes); |
| 9674 | pipe.AddShader(&fs); |
| 9675 | |
| 9676 | VkDescriptorSetObj descriptorSet(m_device); |
| 9677 | descriptorSet.AppendDummy(); |
| 9678 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 9679 | |
| 9680 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 9681 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9682 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a0193bc | 2016-04-04 19:19:47 +1200 | [diff] [blame] | 9683 | } |
| 9684 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9685 | TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) { |
| 9686 | m_errorMonitor->SetDesiredFailureMsg( |
| 9687 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9688 | "Duplicate vertex input binding descriptions for binding 0"); |
| 9689 | |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 9690 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 9691 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 9692 | |
| 9693 | /* Two binding descriptions for binding 0 */ |
| 9694 | VkVertexInputBindingDescription input_bindings[2]; |
| 9695 | memset(input_bindings, 0, sizeof(input_bindings)); |
| 9696 | |
| 9697 | VkVertexInputAttributeDescription input_attrib; |
| 9698 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 9699 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 9700 | |
| 9701 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9702 | "#version 450\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 9703 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9704 | "layout(location=0) in float x;\n" /* attrib provided float */ |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 9705 | "out gl_PerVertex {\n" |
| 9706 | " vec4 gl_Position;\n" |
| 9707 | "};\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 9708 | "void main(){\n" |
| 9709 | " gl_Position = vec4(x);\n" |
| 9710 | "}\n"; |
| 9711 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9712 | "#version 450\n" |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 9713 | "\n" |
| 9714 | "layout(location=0) out vec4 color;\n" |
| 9715 | "void main(){\n" |
| 9716 | " color = vec4(1);\n" |
| 9717 | "}\n"; |
| 9718 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 9719 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9720 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 9721 | |
| 9722 | VkPipelineObj pipe(m_device); |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 9723 | pipe.AddColorAttachment(); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 9724 | pipe.AddShader(&vs); |
| 9725 | pipe.AddShader(&fs); |
| 9726 | |
| 9727 | pipe.AddVertexInputBindings(input_bindings, 2); |
| 9728 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 9729 | |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 9730 | VkDescriptorSetObj descriptorSet(m_device); |
| 9731 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9732 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 9733 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 9734 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 9735 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9736 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 280ba2c | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 9737 | } |
Chris Forbes | 8f68b56 | 2015-05-25 11:13:32 +1200 | [diff] [blame] | 9738 | |
Chris Forbes | 35efec7 | 2016-04-21 14:32:08 +1200 | [diff] [blame] | 9739 | TEST_F(VkLayerTest, CreatePipeline64BitAttributesPositive) { |
| 9740 | m_errorMonitor->ExpectSuccess(); |
| 9741 | |
| 9742 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9743 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9744 | |
| 9745 | if (!m_device->phy().features().tessellationShader) { |
| 9746 | printf("Device does not support 64bit vertex attributes; skipped.\n"); |
| 9747 | return; |
| 9748 | } |
| 9749 | |
| 9750 | VkVertexInputBindingDescription input_bindings[1]; |
| 9751 | memset(input_bindings, 0, sizeof(input_bindings)); |
| 9752 | |
| 9753 | VkVertexInputAttributeDescription input_attribs[4]; |
| 9754 | memset(input_attribs, 0, sizeof(input_attribs)); |
| 9755 | input_attribs[0].location = 0; |
| 9756 | input_attribs[0].offset = 0; |
| 9757 | input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 9758 | input_attribs[1].location = 2; |
| 9759 | input_attribs[1].offset = 32; |
| 9760 | input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 9761 | input_attribs[2].location = 4; |
| 9762 | input_attribs[2].offset = 64; |
| 9763 | input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 9764 | input_attribs[3].location = 6; |
| 9765 | input_attribs[3].offset = 96; |
| 9766 | input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT; |
| 9767 | |
| 9768 | char const *vsSource = |
| 9769 | "#version 450\n" |
| 9770 | "\n" |
| 9771 | "layout(location=0) in dmat4 x;\n" |
| 9772 | "out gl_PerVertex {\n" |
| 9773 | " vec4 gl_Position;\n" |
| 9774 | "};\n" |
| 9775 | "void main(){\n" |
| 9776 | " gl_Position = vec4(x[0][0]);\n" |
| 9777 | "}\n"; |
| 9778 | char const *fsSource = |
| 9779 | "#version 450\n" |
| 9780 | "\n" |
| 9781 | "layout(location=0) out vec4 color;\n" |
| 9782 | "void main(){\n" |
| 9783 | " color = vec4(1);\n" |
| 9784 | "}\n"; |
| 9785 | |
| 9786 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9787 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 9788 | |
| 9789 | VkPipelineObj pipe(m_device); |
| 9790 | pipe.AddColorAttachment(); |
| 9791 | pipe.AddShader(&vs); |
| 9792 | pipe.AddShader(&fs); |
| 9793 | |
| 9794 | pipe.AddVertexInputBindings(input_bindings, 1); |
| 9795 | pipe.AddVertexInputAttribs(input_attribs, 4); |
| 9796 | |
| 9797 | VkDescriptorSetObj descriptorSet(m_device); |
| 9798 | descriptorSet.AppendDummy(); |
| 9799 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 9800 | |
| 9801 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 9802 | |
| 9803 | m_errorMonitor->VerifyNotFound(); |
| 9804 | } |
| 9805 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9806 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9807 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9808 | "Attachment 0 not written by FS"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9809 | |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 9810 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 9811 | |
| 9812 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9813 | "#version 450\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 9814 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 9815 | "out gl_PerVertex {\n" |
| 9816 | " vec4 gl_Position;\n" |
| 9817 | "};\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 9818 | "void main(){\n" |
| 9819 | " gl_Position = vec4(1);\n" |
| 9820 | "}\n"; |
| 9821 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9822 | "#version 450\n" |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 9823 | "\n" |
| 9824 | "void main(){\n" |
| 9825 | "}\n"; |
| 9826 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 9827 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9828 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 9829 | |
| 9830 | VkPipelineObj pipe(m_device); |
| 9831 | pipe.AddShader(&vs); |
| 9832 | pipe.AddShader(&fs); |
| 9833 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 9834 | /* set up CB 0, not written */ |
| 9835 | pipe.AddColorAttachment(); |
| 9836 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 9837 | |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 9838 | VkDescriptorSetObj descriptorSet(m_device); |
| 9839 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9840 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 9841 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 9842 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 9843 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9844 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 4d6d1e5 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 9845 | } |
| 9846 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9847 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9848 | m_errorMonitor->SetDesiredFailureMsg( |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 9849 | VK_DEBUG_REPORT_WARNING_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9850 | "FS writes to output location 1 with no matching attachment"); |
| 9851 | |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 9852 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 9853 | |
| 9854 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9855 | "#version 450\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 9856 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 9857 | "out gl_PerVertex {\n" |
| 9858 | " vec4 gl_Position;\n" |
| 9859 | "};\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 9860 | "void main(){\n" |
| 9861 | " gl_Position = vec4(1);\n" |
| 9862 | "}\n"; |
| 9863 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9864 | "#version 450\n" |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 9865 | "\n" |
| 9866 | "layout(location=0) out vec4 x;\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9867 | "layout(location=1) out vec4 y;\n" /* no matching attachment for this */ |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 9868 | "void main(){\n" |
| 9869 | " x = vec4(1);\n" |
| 9870 | " y = vec4(1);\n" |
| 9871 | "}\n"; |
| 9872 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 9873 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9874 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 9875 | |
| 9876 | VkPipelineObj pipe(m_device); |
| 9877 | pipe.AddShader(&vs); |
| 9878 | pipe.AddShader(&fs); |
| 9879 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 9880 | /* set up CB 0, not written */ |
| 9881 | pipe.AddColorAttachment(); |
| 9882 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 9883 | /* FS writes CB 1, but we don't configure it */ |
| 9884 | |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 9885 | VkDescriptorSetObj descriptorSet(m_device); |
| 9886 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9887 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 9888 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 9889 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 9890 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9891 | m_errorMonitor->VerifyFound(); |
Chris Forbes | f3fffaa | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 9892 | } |
| 9893 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9894 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9895 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9896 | "does not match FS output type"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9897 | |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 9898 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 9899 | |
| 9900 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9901 | "#version 450\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 9902 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 9903 | "out gl_PerVertex {\n" |
| 9904 | " vec4 gl_Position;\n" |
| 9905 | "};\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 9906 | "void main(){\n" |
| 9907 | " gl_Position = vec4(1);\n" |
| 9908 | "}\n"; |
| 9909 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9910 | "#version 450\n" |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 9911 | "\n" |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9912 | "layout(location=0) out ivec4 x;\n" /* not UNORM */ |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 9913 | "void main(){\n" |
| 9914 | " x = ivec4(1);\n" |
| 9915 | "}\n"; |
| 9916 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 9917 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9918 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 9919 | |
| 9920 | VkPipelineObj pipe(m_device); |
| 9921 | pipe.AddShader(&vs); |
| 9922 | pipe.AddShader(&fs); |
| 9923 | |
Chia-I Wu | 08accc6 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 9924 | /* set up CB 0; type is UNORM by default */ |
| 9925 | pipe.AddColorAttachment(); |
| 9926 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 9927 | |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 9928 | VkDescriptorSetObj descriptorSet(m_device); |
| 9929 | descriptorSet.AppendDummy(); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9930 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 9931 | |
Tony Barbour | 5781e8f | 2015-08-04 16:23:11 -0600 | [diff] [blame] | 9932 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 9933 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9934 | m_errorMonitor->VerifyFound(); |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 9935 | } |
Chris Forbes | 7b1b893 | 2015-06-05 14:43:36 +1200 | [diff] [blame] | 9936 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9937 | TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 9938 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9939 | "not declared in pipeline layout"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 9940 | |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 9941 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 9942 | |
| 9943 | char const *vsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9944 | "#version 450\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 9945 | "\n" |
Tony Barbour | e804d20 | 2016-01-05 13:37:45 -0700 | [diff] [blame] | 9946 | "out gl_PerVertex {\n" |
| 9947 | " vec4 gl_Position;\n" |
| 9948 | "};\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 9949 | "void main(){\n" |
| 9950 | " gl_Position = vec4(1);\n" |
| 9951 | "}\n"; |
| 9952 | char const *fsSource = |
Chris Forbes | 3846771 | 2016-04-04 17:28:05 +1200 | [diff] [blame] | 9953 | "#version 450\n" |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 9954 | "\n" |
| 9955 | "layout(location=0) out vec4 x;\n" |
| 9956 | "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n" |
| 9957 | "void main(){\n" |
| 9958 | " x = vec4(bar.y);\n" |
| 9959 | "}\n"; |
| 9960 | |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 9961 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 9962 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 9963 | |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 9964 | VkPipelineObj pipe(m_device); |
| 9965 | pipe.AddShader(&vs); |
| 9966 | pipe.AddShader(&fs); |
| 9967 | |
| 9968 | /* set up CB 0; type is UNORM by default */ |
| 9969 | pipe.AddColorAttachment(); |
| 9970 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 9971 | |
| 9972 | VkDescriptorSetObj descriptorSet(m_device); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 9973 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 9974 | |
| 9975 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 9976 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 9977 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 556c76c | 2015-08-14 12:04:59 +1200 | [diff] [blame] | 9978 | } |
| 9979 | |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 9980 | TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) { |
| 9981 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 9982 | "not declared in layout"); |
| 9983 | |
| 9984 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 9985 | |
| 9986 | char const *vsSource = |
| 9987 | "#version 450\n" |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 9988 | "\n" |
| 9989 | "layout(push_constant, std430) uniform foo { float x; } consts;\n" |
| 9990 | "out gl_PerVertex {\n" |
| 9991 | " vec4 gl_Position;\n" |
| 9992 | "};\n" |
| 9993 | "void main(){\n" |
| 9994 | " gl_Position = vec4(consts.x);\n" |
| 9995 | "}\n"; |
| 9996 | char const *fsSource = |
| 9997 | "#version 450\n" |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 9998 | "\n" |
| 9999 | "layout(location=0) out vec4 x;\n" |
| 10000 | "void main(){\n" |
| 10001 | " x = vec4(1);\n" |
| 10002 | "}\n"; |
| 10003 | |
| 10004 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this); |
| 10005 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this); |
| 10006 | |
| 10007 | VkPipelineObj pipe(m_device); |
| 10008 | pipe.AddShader(&vs); |
| 10009 | pipe.AddShader(&fs); |
| 10010 | |
| 10011 | /* set up CB 0; type is UNORM by default */ |
| 10012 | pipe.AddColorAttachment(); |
| 10013 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10014 | |
| 10015 | VkDescriptorSetObj descriptorSet(m_device); |
| 10016 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10017 | |
| 10018 | pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass()); |
| 10019 | |
| 10020 | /* should have generated an error -- no push constant ranges provided! */ |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10021 | m_errorMonitor->VerifyFound(); |
Chris Forbes | 5c59e90 | 2016-02-26 16:56:09 +1300 | [diff] [blame] | 10022 | } |
| 10023 | |
Chris Forbes | 10eb9ae | 2016-05-31 16:09:42 +1200 | [diff] [blame] | 10024 | TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) { |
| 10025 | m_errorMonitor->SetDesiredFailureMsg( |
| 10026 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10027 | "Shader uses descriptor slot 0.0"); |
| 10028 | |
| 10029 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10030 | |
| 10031 | char const *csSource = |
| 10032 | "#version 450\n" |
| 10033 | "\n" |
| 10034 | "layout(local_size_x=1) in;\n" |
| 10035 | "layout(set=0, binding=0) buffer block { vec4 x; };\n" |
| 10036 | "void main(){\n" |
| 10037 | " x = vec4(1);\n" |
| 10038 | "}\n"; |
| 10039 | |
| 10040 | VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this); |
| 10041 | |
| 10042 | VkDescriptorSetObj descriptorSet(m_device); |
| 10043 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10044 | |
| 10045 | VkComputePipelineCreateInfo cpci = { |
| 10046 | VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, |
| 10047 | nullptr, 0, { |
| 10048 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 10049 | nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, |
| 10050 | cs.handle(), "main", nullptr |
| 10051 | }, |
| 10052 | descriptorSet.GetPipelineLayout(), |
| 10053 | VK_NULL_HANDLE, -1 |
| 10054 | }; |
| 10055 | |
| 10056 | VkPipeline pipe; |
| 10057 | VkResult err = vkCreateComputePipelines( |
| 10058 | m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe); |
| 10059 | |
| 10060 | m_errorMonitor->VerifyFound(); |
| 10061 | |
| 10062 | if (err == VK_SUCCESS) { |
| 10063 | vkDestroyPipeline(m_device->device(), pipe, nullptr); |
| 10064 | } |
| 10065 | } |
| 10066 | |
| 10067 | TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) { |
| 10068 | m_errorMonitor->ExpectSuccess(); |
| 10069 | |
| 10070 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10071 | |
| 10072 | char const *csSource = |
| 10073 | "#version 450\n" |
| 10074 | "\n" |
| 10075 | "layout(local_size_x=1) in;\n" |
| 10076 | "layout(set=0, binding=0) buffer block { vec4 x; };\n" |
| 10077 | "void main(){\n" |
| 10078 | " // x is not used.\n" |
| 10079 | "}\n"; |
| 10080 | |
| 10081 | VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this); |
| 10082 | |
| 10083 | VkDescriptorSetObj descriptorSet(m_device); |
| 10084 | descriptorSet.CreateVKDescriptorSet(m_commandBuffer); |
| 10085 | |
| 10086 | VkComputePipelineCreateInfo cpci = { |
| 10087 | VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, |
| 10088 | nullptr, 0, { |
| 10089 | VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 10090 | nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, |
| 10091 | cs.handle(), "main", nullptr |
| 10092 | }, |
| 10093 | descriptorSet.GetPipelineLayout(), |
| 10094 | VK_NULL_HANDLE, -1 |
| 10095 | }; |
| 10096 | |
| 10097 | VkPipeline pipe; |
| 10098 | VkResult err = vkCreateComputePipelines( |
| 10099 | m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe); |
| 10100 | |
| 10101 | m_errorMonitor->VerifyNotFound(); |
| 10102 | |
| 10103 | if (err == VK_SUCCESS) { |
| 10104 | vkDestroyPipeline(m_device->device(), pipe, nullptr); |
| 10105 | } |
| 10106 | } |
| 10107 | |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 10108 | #endif // SHADER_CHECKER_TESTS |
| 10109 | |
| 10110 | #if DEVICE_LIMITS_TESTS |
Mark Young | c48c4c1 | 2016-04-11 14:26:49 -0600 | [diff] [blame] | 10111 | TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10112 | m_errorMonitor->SetDesiredFailureMsg( |
| 10113 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10114 | "CreateImage extents exceed allowable limits for format"); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 10115 | |
| 10116 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 10117 | |
| 10118 | // Create an image |
| 10119 | VkImage image; |
| 10120 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10121 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 10122 | const int32_t tex_width = 32; |
| 10123 | const int32_t tex_height = 32; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 10124 | |
| 10125 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10126 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 10127 | image_create_info.pNext = NULL; |
| 10128 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 10129 | image_create_info.format = tex_format; |
| 10130 | image_create_info.extent.width = tex_width; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 10131 | image_create_info.extent.height = tex_height; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10132 | image_create_info.extent.depth = 1; |
| 10133 | image_create_info.mipLevels = 1; |
| 10134 | image_create_info.arrayLayers = 1; |
| 10135 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 10136 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 10137 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 10138 | image_create_info.flags = 0; |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 10139 | |
| 10140 | // Introduce error by sending down a bogus width extent |
| 10141 | image_create_info.extent.width = 65536; |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10142 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 10143 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10144 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 6f2274e | 2015-09-22 09:33:21 -0600 | [diff] [blame] | 10145 | } |
| 10146 | |
Mark Young | c48c4c1 | 2016-04-11 14:26:49 -0600 | [diff] [blame] | 10147 | TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) { |
| 10148 | m_errorMonitor->SetDesiredFailureMsg( |
| 10149 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10150 | "CreateImage extents is 0 for at least one required dimension"); |
| 10151 | |
| 10152 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10153 | |
| 10154 | // Create an image |
| 10155 | VkImage image; |
| 10156 | |
| 10157 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 10158 | const int32_t tex_width = 32; |
| 10159 | const int32_t tex_height = 32; |
| 10160 | |
| 10161 | VkImageCreateInfo image_create_info = {}; |
| 10162 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 10163 | image_create_info.pNext = NULL; |
| 10164 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 10165 | image_create_info.format = tex_format; |
| 10166 | image_create_info.extent.width = tex_width; |
| 10167 | image_create_info.extent.height = tex_height; |
| 10168 | image_create_info.extent.depth = 1; |
| 10169 | image_create_info.mipLevels = 1; |
| 10170 | image_create_info.arrayLayers = 1; |
| 10171 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 10172 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 10173 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 10174 | image_create_info.flags = 0; |
| 10175 | |
| 10176 | // Introduce error by sending down a bogus width extent |
| 10177 | image_create_info.extent.width = 0; |
| 10178 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
| 10179 | |
| 10180 | m_errorMonitor->VerifyFound(); |
| 10181 | } |
| 10182 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10183 | TEST_F(VkLayerTest, UpdateBufferAlignment) { |
| 10184 | uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8}; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10185 | |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10186 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10187 | "dstOffset, is not a multiple of 4"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10188 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10189 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10190 | |
| 10191 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 10192 | vk_testing::Buffer buffer; |
| 10193 | buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs); |
| 10194 | |
| 10195 | BeginCommandBuffer(); |
| 10196 | // Introduce failure by using offset that is not multiple of 4 |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10197 | m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10198 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10199 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10200 | // Introduce failure by using size that is not multiple of 4 |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10201 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10202 | "dataSize, is not a multiple of 4"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10203 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10204 | m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10205 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10206 | EndCommandBuffer(); |
| 10207 | } |
| 10208 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10209 | TEST_F(VkLayerTest, FillBufferAlignment) { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10210 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10211 | "dstOffset, is not a multiple of 4"); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10212 | |
| 10213 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10214 | |
| 10215 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 10216 | vk_testing::Buffer buffer; |
| 10217 | buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs); |
| 10218 | |
| 10219 | BeginCommandBuffer(); |
| 10220 | // Introduce failure by using offset that is not multiple of 4 |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10221 | m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111); |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10222 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10223 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10224 | // Introduce failure by using size that is not multiple of 4 |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 10225 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10226 | "size, is not a multiple of 4"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10227 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10228 | m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10229 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10230 | m_errorMonitor->VerifyFound(); |
| 10231 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10232 | EndCommandBuffer(); |
| 10233 | } |
| 10234 | |
Mark Lobodzinski | 209b529 | 2015-09-17 09:44:05 -0600 | [diff] [blame] | 10235 | #endif // DEVICE_LIMITS_TESTS |
Chris Forbes | a36d69e | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 10236 | |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 10237 | #if IMAGE_TESTS |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10238 | TEST_F(VkLayerTest, InvalidImageView) { |
| 10239 | VkResult err; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 10240 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10241 | m_errorMonitor->SetDesiredFailureMsg( |
| 10242 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10243 | "vkCreateImageView called with baseMipLevel 10 "); |
| 10244 | |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 10245 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 10246 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10247 | // Create an image and try to create a view with bad baseMipLevel |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10248 | VkImage image; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 10249 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10250 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 10251 | const int32_t tex_width = 32; |
| 10252 | const int32_t tex_height = 32; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 10253 | |
| 10254 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10255 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 10256 | image_create_info.pNext = NULL; |
| 10257 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 10258 | image_create_info.format = tex_format; |
| 10259 | image_create_info.extent.width = tex_width; |
| 10260 | image_create_info.extent.height = tex_height; |
| 10261 | image_create_info.extent.depth = 1; |
| 10262 | image_create_info.mipLevels = 1; |
| 10263 | image_create_info.arrayLayers = 1; |
| 10264 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 10265 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 10266 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 10267 | image_create_info.flags = 0; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 10268 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10269 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 10270 | ASSERT_VK_SUCCESS(err); |
| 10271 | |
| 10272 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10273 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 10274 | image_view_create_info.image = image; |
| 10275 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 10276 | image_view_create_info.format = tex_format; |
| 10277 | image_view_create_info.subresourceRange.layerCount = 1; |
| 10278 | image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error |
| 10279 | image_view_create_info.subresourceRange.levelCount = 1; |
| 10280 | image_view_create_info.subresourceRange.aspectMask = |
| 10281 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 10282 | |
| 10283 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10284 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 10285 | &view); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 10286 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10287 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 10288 | } |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10289 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10290 | TEST_F(VkLayerTest, InvalidImageViewAspect) { |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 10291 | TEST_DESCRIPTION( |
| 10292 | "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] | 10293 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10294 | "vkCreateImageView: Color image " |
| 10295 | "formats must have ONLY the " |
| 10296 | "VK_IMAGE_ASPECT_COLOR_BIT set"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10297 | |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 10298 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 10299 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10300 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 10301 | VkImageObj image(m_device); |
| 10302 | image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, |
| 10303 | VK_IMAGE_TILING_LINEAR, 0); |
| 10304 | ASSERT_TRUE(image.initialized()); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 10305 | |
| 10306 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10307 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 10308 | image_view_create_info.image = image.handle(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10309 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 10310 | image_view_create_info.format = tex_format; |
| 10311 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 10312 | image_view_create_info.subresourceRange.levelCount = 1; |
| 10313 | // Cause an error by setting an invalid image aspect |
| 10314 | image_view_create_info.subresourceRange.aspectMask = |
| 10315 | VK_IMAGE_ASPECT_METADATA_BIT; |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 10316 | |
| 10317 | VkImageView view; |
Tobin Ehlis | 1f567a2 | 2016-05-25 16:15:18 -0600 | [diff] [blame] | 10318 | vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 10319 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10320 | m_errorMonitor->VerifyFound(); |
Mark Lobodzinski | dc86b85 | 2015-10-23 14:20:31 -0600 | [diff] [blame] | 10321 | } |
| 10322 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 10323 | TEST_F(VkLayerTest, CopyImageLayerCountMismatch) { |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10324 | VkResult err; |
| 10325 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10326 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10327 | m_errorMonitor->SetDesiredFailureMsg( |
| 10328 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 10329 | "vkCmdCopyImage: number of layers in source and destination subresources for pRegions"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10330 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10331 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10332 | |
| 10333 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10334 | VkImage srcImage; |
| 10335 | VkImage dstImage; |
| 10336 | VkDeviceMemory srcMem; |
| 10337 | VkDeviceMemory destMem; |
| 10338 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10339 | |
| 10340 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10341 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 10342 | image_create_info.pNext = NULL; |
| 10343 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 10344 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 10345 | image_create_info.extent.width = 32; |
| 10346 | image_create_info.extent.height = 32; |
| 10347 | image_create_info.extent.depth = 1; |
| 10348 | image_create_info.mipLevels = 1; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 10349 | image_create_info.arrayLayers = 4; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10350 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 10351 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 10352 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 10353 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10354 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10355 | err = |
| 10356 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10357 | ASSERT_VK_SUCCESS(err); |
| 10358 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10359 | err = |
| 10360 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10361 | ASSERT_VK_SUCCESS(err); |
| 10362 | |
| 10363 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10364 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10365 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 10366 | memAlloc.pNext = NULL; |
| 10367 | memAlloc.allocationSize = 0; |
| 10368 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10369 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 10370 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10371 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10372 | pass = |
| 10373 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 10374 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10375 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10376 | ASSERT_VK_SUCCESS(err); |
| 10377 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10378 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10379 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10380 | pass = |
| 10381 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10382 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10383 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10384 | ASSERT_VK_SUCCESS(err); |
| 10385 | |
| 10386 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 10387 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10388 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10389 | ASSERT_VK_SUCCESS(err); |
| 10390 | |
| 10391 | BeginCommandBuffer(); |
| 10392 | VkImageCopy copyRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 10393 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10394 | copyRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 10395 | copyRegion.srcSubresource.baseArrayLayer = 0; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 10396 | copyRegion.srcSubresource.layerCount = 1; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10397 | copyRegion.srcOffset.x = 0; |
| 10398 | copyRegion.srcOffset.y = 0; |
| 10399 | copyRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 10400 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10401 | copyRegion.dstSubresource.mipLevel = 0; |
| 10402 | copyRegion.dstSubresource.baseArrayLayer = 0; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 10403 | // Introduce failure by forcing the dst layerCount to differ from src |
| 10404 | copyRegion.dstSubresource.layerCount = 3; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10405 | copyRegion.dstOffset.x = 0; |
| 10406 | copyRegion.dstOffset.y = 0; |
| 10407 | copyRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10408 | copyRegion.extent.width = 1; |
| 10409 | copyRegion.extent.height = 1; |
| 10410 | copyRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10411 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 10412 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10413 | EndCommandBuffer(); |
| 10414 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10415 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10416 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10417 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10418 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10419 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 10420 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10421 | } |
| 10422 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 10423 | TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) { |
| 10424 | |
| 10425 | TEST_DESCRIPTION("Creating images with unsuported formats "); |
| 10426 | |
| 10427 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10428 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 10429 | VkImageObj image(m_device); |
| 10430 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 10431 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 10432 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 10433 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 10434 | ASSERT_TRUE(image.initialized()); |
| 10435 | |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 10436 | // Create image with unsupported format - Expect FORMAT_UNSUPPORTED |
| 10437 | VkImageCreateInfo image_create_info; |
| 10438 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 10439 | image_create_info.pNext = NULL; |
| 10440 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 10441 | image_create_info.format = VK_FORMAT_UNDEFINED; |
| 10442 | image_create_info.extent.width = 32; |
| 10443 | image_create_info.extent.height = 32; |
| 10444 | image_create_info.extent.depth = 1; |
| 10445 | image_create_info.mipLevels = 1; |
| 10446 | image_create_info.arrayLayers = 1; |
| 10447 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 10448 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 10449 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 10450 | image_create_info.flags = 0; |
| 10451 | |
| 10452 | m_errorMonitor->SetDesiredFailureMsg( |
| 10453 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10454 | "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED"); |
| 10455 | |
| 10456 | VkImage localImage; |
| 10457 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage); |
| 10458 | m_errorMonitor->VerifyFound(); |
| 10459 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 10460 | VkFormat unsupported = VK_FORMAT_UNDEFINED; |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 10461 | // Look for a format that is COMPLETELY unsupported with this hardware |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 10462 | for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) { |
| 10463 | VkFormat format = static_cast<VkFormat>(f); |
| 10464 | VkFormatProperties fProps = m_device->format_properties(format); |
| 10465 | if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && |
| 10466 | fProps.optimalTilingFeatures == 0) { |
| 10467 | unsupported = format; |
| 10468 | break; |
| 10469 | } |
| 10470 | } |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 10471 | |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 10472 | if (unsupported != VK_FORMAT_UNDEFINED) { |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 10473 | image_create_info.format = unsupported; |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 10474 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 10475 | "is an unsupported format"); |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 10476 | |
Mark Lobodzinski | ba5c686 | 2016-05-17 08:14:00 -0600 | [diff] [blame] | 10477 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage); |
Tony Barbour | d667364 | 2016-05-05 14:46:39 -0600 | [diff] [blame] | 10478 | m_errorMonitor->VerifyFound(); |
| 10479 | } |
| 10480 | } |
| 10481 | |
| 10482 | TEST_F(VkLayerTest, ImageLayerViewTests) { |
| 10483 | VkResult ret; |
| 10484 | TEST_DESCRIPTION("Passing bad parameters to CreateImageView"); |
| 10485 | |
| 10486 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10487 | |
| 10488 | VkImageObj image(m_device); |
| 10489 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 10490 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 10491 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 10492 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 10493 | ASSERT_TRUE(image.initialized()); |
| 10494 | |
| 10495 | VkImageView imgView; |
| 10496 | VkImageViewCreateInfo imgViewInfo = {}; |
| 10497 | imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 10498 | imgViewInfo.image = image.handle(); |
| 10499 | imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 10500 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 10501 | imgViewInfo.subresourceRange.layerCount = 1; |
| 10502 | imgViewInfo.subresourceRange.baseMipLevel = 0; |
| 10503 | imgViewInfo.subresourceRange.levelCount = 1; |
| 10504 | imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 10505 | |
| 10506 | m_errorMonitor->SetDesiredFailureMsg( |
| 10507 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10508 | "vkCreateImageView called with baseMipLevel"); |
| 10509 | // View can't have baseMipLevel >= image's mipLevels - Expect |
| 10510 | // VIEW_CREATE_ERROR |
| 10511 | imgViewInfo.subresourceRange.baseMipLevel = 1; |
| 10512 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 10513 | m_errorMonitor->VerifyFound(); |
| 10514 | imgViewInfo.subresourceRange.baseMipLevel = 0; |
| 10515 | |
| 10516 | m_errorMonitor->SetDesiredFailureMsg( |
| 10517 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10518 | "vkCreateImageView called with baseArrayLayer"); |
| 10519 | // View can't have baseArrayLayer >= image's arraySize - Expect |
| 10520 | // VIEW_CREATE_ERROR |
| 10521 | imgViewInfo.subresourceRange.baseArrayLayer = 1; |
| 10522 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 10523 | m_errorMonitor->VerifyFound(); |
| 10524 | imgViewInfo.subresourceRange.baseArrayLayer = 0; |
| 10525 | |
| 10526 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10527 | "vkCreateImageView called with 0 in " |
| 10528 | "pCreateInfo->subresourceRange." |
| 10529 | "levelCount"); |
| 10530 | // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR |
| 10531 | imgViewInfo.subresourceRange.levelCount = 0; |
| 10532 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 10533 | m_errorMonitor->VerifyFound(); |
| 10534 | imgViewInfo.subresourceRange.levelCount = 1; |
| 10535 | |
| 10536 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10537 | "vkCreateImageView called with 0 in " |
| 10538 | "pCreateInfo->subresourceRange." |
| 10539 | "layerCount"); |
| 10540 | // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR |
| 10541 | imgViewInfo.subresourceRange.layerCount = 0; |
| 10542 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 10543 | m_errorMonitor->VerifyFound(); |
| 10544 | imgViewInfo.subresourceRange.layerCount = 1; |
| 10545 | |
| 10546 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10547 | "but both must be color formats"); |
| 10548 | // Can't use depth format for view into color image - Expect INVALID_FORMAT |
| 10549 | imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 10550 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 10551 | m_errorMonitor->VerifyFound(); |
| 10552 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 10553 | |
| 10554 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10555 | "Formats MUST be IDENTICAL unless " |
| 10556 | "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT " |
| 10557 | "was set on image creation."); |
| 10558 | // Same compatibility class but no MUTABLE_FORMAT bit - Expect |
| 10559 | // VIEW_CREATE_ERROR |
| 10560 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT; |
| 10561 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 10562 | m_errorMonitor->VerifyFound(); |
| 10563 | imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 10564 | |
| 10565 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10566 | "can support ImageViews with " |
| 10567 | "differing formats but they must be " |
| 10568 | "in the same compatibility class."); |
| 10569 | // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect |
| 10570 | // VIEW_CREATE_ERROR |
| 10571 | VkImageCreateInfo mutImgInfo = image.create_info(); |
| 10572 | VkImage mutImage; |
| 10573 | mutImgInfo.format = VK_FORMAT_R8_UINT; |
| 10574 | assert( |
| 10575 | m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & |
| 10576 | VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT); |
| 10577 | mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; |
| 10578 | mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 10579 | ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage); |
| 10580 | ASSERT_VK_SUCCESS(ret); |
| 10581 | imgViewInfo.image = mutImage; |
| 10582 | vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView); |
| 10583 | m_errorMonitor->VerifyFound(); |
| 10584 | imgViewInfo.image = image.handle(); |
| 10585 | vkDestroyImage(m_device->handle(), mutImage, NULL); |
| 10586 | } |
| 10587 | |
| 10588 | TEST_F(VkLayerTest, MiscImageLayerTests) { |
| 10589 | |
| 10590 | TEST_DESCRIPTION("Image layer tests that don't belong elsewhare"); |
| 10591 | |
| 10592 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10593 | |
| 10594 | VkImageObj image(m_device); |
| 10595 | image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, |
| 10596 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 10597 | VK_IMAGE_USAGE_TRANSFER_DST_BIT, |
| 10598 | VK_IMAGE_TILING_OPTIMAL, 0); |
| 10599 | ASSERT_TRUE(image.initialized()); |
| 10600 | |
| 10601 | m_errorMonitor->SetDesiredFailureMsg( |
| 10602 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10603 | "number of layers in image subresource is zero"); |
| 10604 | vk_testing::Buffer buffer; |
| 10605 | VkMemoryPropertyFlags reqs = 0; |
| 10606 | buffer.init_as_src(*m_device, 128 * 128 * 4, reqs); |
| 10607 | VkBufferImageCopy region = {}; |
| 10608 | region.bufferRowLength = 128; |
| 10609 | region.bufferImageHeight = 128; |
| 10610 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 10611 | // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT |
| 10612 | region.imageSubresource.layerCount = 0; |
| 10613 | region.imageExtent.height = 4; |
| 10614 | region.imageExtent.width = 4; |
| 10615 | region.imageExtent.depth = 1; |
| 10616 | m_commandBuffer->BeginCommandBuffer(); |
| 10617 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 10618 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 10619 | 1, ®ion); |
| 10620 | m_errorMonitor->VerifyFound(); |
| 10621 | region.imageSubresource.layerCount = 1; |
| 10622 | |
| 10623 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10624 | "aspectMasks for each region must " |
| 10625 | "specify only COLOR or DEPTH or " |
| 10626 | "STENCIL"); |
| 10627 | // Expect MISMATCHED_IMAGE_ASPECT |
| 10628 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT; |
| 10629 | vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), |
| 10630 | image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 10631 | 1, ®ion); |
| 10632 | m_errorMonitor->VerifyFound(); |
| 10633 | region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 10634 | |
| 10635 | m_errorMonitor->SetDesiredFailureMsg( |
| 10636 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10637 | "If the format of srcImage is a depth, stencil, depth stencil or " |
| 10638 | "integer-based format then filter must be VK_FILTER_NEAREST"); |
| 10639 | // Expect INVALID_FILTER |
| 10640 | VkImageObj intImage1(m_device); |
| 10641 | intImage1.init(128, 128, VK_FORMAT_R8_UINT, |
| 10642 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, |
| 10643 | 0); |
| 10644 | VkImageObj intImage2(m_device); |
| 10645 | intImage2.init(128, 128, VK_FORMAT_R8_UINT, |
| 10646 | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, |
| 10647 | 0); |
| 10648 | VkImageBlit blitRegion = {}; |
| 10649 | blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 10650 | blitRegion.srcSubresource.baseArrayLayer = 0; |
| 10651 | blitRegion.srcSubresource.layerCount = 1; |
| 10652 | blitRegion.srcSubresource.mipLevel = 0; |
| 10653 | blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 10654 | blitRegion.dstSubresource.baseArrayLayer = 0; |
| 10655 | blitRegion.dstSubresource.layerCount = 1; |
| 10656 | blitRegion.dstSubresource.mipLevel = 0; |
| 10657 | |
| 10658 | vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), |
| 10659 | intImage1.layout(), intImage2.handle(), intImage2.layout(), |
| 10660 | 16, &blitRegion, VK_FILTER_LINEAR); |
| 10661 | m_errorMonitor->VerifyFound(); |
| 10662 | |
| 10663 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10664 | "called with 0 in ppMemoryBarriers"); |
| 10665 | VkImageMemoryBarrier img_barrier; |
| 10666 | img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 10667 | img_barrier.pNext = NULL; |
| 10668 | img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 10669 | img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; |
| 10670 | img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 10671 | img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 10672 | img_barrier.image = image.handle(); |
| 10673 | img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 10674 | img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 10675 | img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 10676 | img_barrier.subresourceRange.baseArrayLayer = 0; |
| 10677 | img_barrier.subresourceRange.baseMipLevel = 0; |
| 10678 | // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE |
| 10679 | img_barrier.subresourceRange.layerCount = 0; |
| 10680 | img_barrier.subresourceRange.levelCount = 1; |
| 10681 | vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), |
| 10682 | VK_PIPELINE_STAGE_HOST_BIT, |
| 10683 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, |
| 10684 | nullptr, 1, &img_barrier); |
| 10685 | m_errorMonitor->VerifyFound(); |
| 10686 | img_barrier.subresourceRange.layerCount = 1; |
| 10687 | } |
| 10688 | |
| 10689 | TEST_F(VkLayerTest, ImageFormatLimits) { |
| 10690 | |
| 10691 | TEST_DESCRIPTION("Exceed the limits of image format "); |
| 10692 | |
| 10693 | m_errorMonitor->SetDesiredFailureMsg( |
| 10694 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10695 | "CreateImage extents exceed allowable limits for format"); |
| 10696 | VkImageCreateInfo image_create_info = {}; |
| 10697 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 10698 | image_create_info.pNext = NULL; |
| 10699 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 10700 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 10701 | image_create_info.extent.width = 32; |
| 10702 | image_create_info.extent.height = 32; |
| 10703 | image_create_info.extent.depth = 1; |
| 10704 | image_create_info.mipLevels = 1; |
| 10705 | image_create_info.arrayLayers = 1; |
| 10706 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 10707 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 10708 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 10709 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 10710 | image_create_info.flags = 0; |
| 10711 | |
| 10712 | VkImage nullImg; |
| 10713 | VkImageFormatProperties imgFmtProps; |
| 10714 | vkGetPhysicalDeviceImageFormatProperties( |
| 10715 | gpu(), image_create_info.format, image_create_info.imageType, |
| 10716 | image_create_info.tiling, image_create_info.usage, |
| 10717 | image_create_info.flags, &imgFmtProps); |
| 10718 | image_create_info.extent.depth = imgFmtProps.maxExtent.depth + 1; |
| 10719 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 10720 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 10721 | m_errorMonitor->VerifyFound(); |
| 10722 | image_create_info.extent.depth = 1; |
| 10723 | |
| 10724 | m_errorMonitor->SetDesiredFailureMsg( |
| 10725 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10726 | "exceeds allowable maximum supported by format of"); |
| 10727 | image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1; |
| 10728 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 10729 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 10730 | m_errorMonitor->VerifyFound(); |
| 10731 | image_create_info.mipLevels = 1; |
| 10732 | |
| 10733 | m_errorMonitor->SetDesiredFailureMsg( |
| 10734 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10735 | "exceeds allowable maximum supported by format of"); |
| 10736 | image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1; |
| 10737 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 10738 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 10739 | m_errorMonitor->VerifyFound(); |
| 10740 | image_create_info.arrayLayers = 1; |
| 10741 | |
| 10742 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10743 | "is not supported by format"); |
| 10744 | int samples = imgFmtProps.sampleCounts >> 1; |
| 10745 | image_create_info.samples = (VkSampleCountFlagBits)samples; |
| 10746 | // Expect INVALID_FORMAT_LIMITS_VIOLATION |
| 10747 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 10748 | m_errorMonitor->VerifyFound(); |
| 10749 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 10750 | |
| 10751 | m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10752 | "pCreateInfo->initialLayout, must be " |
| 10753 | "VK_IMAGE_LAYOUT_UNDEFINED or " |
| 10754 | "VK_IMAGE_LAYOUT_PREINITIALIZED"); |
| 10755 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 10756 | // Expect INVALID_LAYOUT |
| 10757 | vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg); |
| 10758 | m_errorMonitor->VerifyFound(); |
| 10759 | image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 10760 | } |
| 10761 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10762 | TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) { |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 10763 | VkResult err; |
| 10764 | bool pass; |
| 10765 | |
| 10766 | // Create color images with different format sizes and try to copy between them |
| 10767 | m_errorMonitor->SetDesiredFailureMsg( |
| 10768 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 10769 | "vkCmdCopyImage called with unmatched source and dest image format sizes"); |
| 10770 | |
| 10771 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 10772 | |
| 10773 | // Create two images of different types and try to copy between them |
| 10774 | VkImage srcImage; |
| 10775 | VkImage dstImage; |
| 10776 | VkDeviceMemory srcMem; |
| 10777 | VkDeviceMemory destMem; |
| 10778 | VkMemoryRequirements memReqs; |
| 10779 | |
| 10780 | VkImageCreateInfo image_create_info = {}; |
| 10781 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 10782 | image_create_info.pNext = NULL; |
| 10783 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 10784 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 10785 | image_create_info.extent.width = 32; |
| 10786 | image_create_info.extent.height = 32; |
| 10787 | image_create_info.extent.depth = 1; |
| 10788 | image_create_info.mipLevels = 1; |
| 10789 | image_create_info.arrayLayers = 1; |
| 10790 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 10791 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 10792 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 10793 | image_create_info.flags = 0; |
| 10794 | |
| 10795 | err = |
| 10796 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
| 10797 | ASSERT_VK_SUCCESS(err); |
| 10798 | |
| 10799 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 10800 | // Introduce failure by creating second image with a different-sized format. |
| 10801 | image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16; |
| 10802 | |
| 10803 | err = |
| 10804 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
| 10805 | ASSERT_VK_SUCCESS(err); |
| 10806 | |
| 10807 | // Allocate memory |
| 10808 | VkMemoryAllocateInfo memAlloc = {}; |
| 10809 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 10810 | memAlloc.pNext = NULL; |
| 10811 | memAlloc.allocationSize = 0; |
| 10812 | memAlloc.memoryTypeIndex = 0; |
| 10813 | |
| 10814 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
| 10815 | memAlloc.allocationSize = memReqs.size; |
| 10816 | pass = |
| 10817 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
| 10818 | ASSERT_TRUE(pass); |
| 10819 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
| 10820 | ASSERT_VK_SUCCESS(err); |
| 10821 | |
| 10822 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
| 10823 | memAlloc.allocationSize = memReqs.size; |
| 10824 | pass = |
| 10825 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
| 10826 | ASSERT_TRUE(pass); |
| 10827 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
| 10828 | ASSERT_VK_SUCCESS(err); |
| 10829 | |
| 10830 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 10831 | ASSERT_VK_SUCCESS(err); |
| 10832 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
| 10833 | ASSERT_VK_SUCCESS(err); |
| 10834 | |
| 10835 | BeginCommandBuffer(); |
| 10836 | VkImageCopy copyRegion; |
| 10837 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 10838 | copyRegion.srcSubresource.mipLevel = 0; |
| 10839 | copyRegion.srcSubresource.baseArrayLayer = 0; |
| 10840 | copyRegion.srcSubresource.layerCount = 0; |
| 10841 | copyRegion.srcOffset.x = 0; |
| 10842 | copyRegion.srcOffset.y = 0; |
| 10843 | copyRegion.srcOffset.z = 0; |
| 10844 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 10845 | copyRegion.dstSubresource.mipLevel = 0; |
| 10846 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 10847 | copyRegion.dstSubresource.layerCount = 0; |
| 10848 | copyRegion.dstOffset.x = 0; |
| 10849 | copyRegion.dstOffset.y = 0; |
| 10850 | copyRegion.dstOffset.z = 0; |
| 10851 | copyRegion.extent.width = 1; |
| 10852 | copyRegion.extent.height = 1; |
| 10853 | copyRegion.extent.depth = 1; |
| 10854 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 10855 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
| 10856 | EndCommandBuffer(); |
| 10857 | |
| 10858 | m_errorMonitor->VerifyFound(); |
| 10859 | |
| 10860 | vkDestroyImage(m_device->device(), srcImage, NULL); |
| 10861 | vkDestroyImage(m_device->device(), dstImage, NULL); |
| 10862 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 10863 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10864 | } |
| 10865 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10866 | TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) { |
| 10867 | VkResult err; |
| 10868 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10869 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 10870 | // 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] | 10871 | m_errorMonitor->SetDesiredFailureMsg( |
| 10872 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 10873 | "vkCmdCopyImage called with unmatched source and dest image depth"); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10874 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10875 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10876 | |
| 10877 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10878 | VkImage srcImage; |
| 10879 | VkImage dstImage; |
| 10880 | VkDeviceMemory srcMem; |
| 10881 | VkDeviceMemory destMem; |
| 10882 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10883 | |
| 10884 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10885 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 10886 | image_create_info.pNext = NULL; |
| 10887 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 10888 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 10889 | image_create_info.extent.width = 32; |
| 10890 | image_create_info.extent.height = 32; |
| 10891 | image_create_info.extent.depth = 1; |
| 10892 | image_create_info.mipLevels = 1; |
| 10893 | image_create_info.arrayLayers = 1; |
| 10894 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 10895 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 10896 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 10897 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10898 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10899 | err = |
| 10900 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10901 | ASSERT_VK_SUCCESS(err); |
| 10902 | |
Karl Schultz | bdb7595 | 2016-04-19 11:36:49 -0600 | [diff] [blame] | 10903 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 10904 | |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 10905 | // Introduce failure by creating second image with a depth/stencil format |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10906 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
Mark Lobodzinski | db11763 | 2016-03-31 10:45:56 -0600 | [diff] [blame] | 10907 | image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 10908 | image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10909 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10910 | err = |
| 10911 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10912 | ASSERT_VK_SUCCESS(err); |
| 10913 | |
| 10914 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10915 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10916 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 10917 | memAlloc.pNext = NULL; |
| 10918 | memAlloc.allocationSize = 0; |
| 10919 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10920 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 10921 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10922 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10923 | pass = |
| 10924 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 10925 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10926 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10927 | ASSERT_VK_SUCCESS(err); |
| 10928 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10929 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10930 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10931 | pass = |
| 10932 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 10933 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10934 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10935 | ASSERT_VK_SUCCESS(err); |
| 10936 | |
| 10937 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 10938 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10939 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10940 | ASSERT_VK_SUCCESS(err); |
| 10941 | |
| 10942 | BeginCommandBuffer(); |
| 10943 | VkImageCopy copyRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 10944 | copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10945 | copyRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 10946 | copyRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10947 | copyRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10948 | copyRegion.srcOffset.x = 0; |
| 10949 | copyRegion.srcOffset.y = 0; |
| 10950 | copyRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 10951 | copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10952 | copyRegion.dstSubresource.mipLevel = 0; |
| 10953 | copyRegion.dstSubresource.baseArrayLayer = 0; |
| 10954 | copyRegion.dstSubresource.layerCount = 0; |
| 10955 | copyRegion.dstOffset.x = 0; |
| 10956 | copyRegion.dstOffset.y = 0; |
| 10957 | copyRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10958 | copyRegion.extent.width = 1; |
| 10959 | copyRegion.extent.height = 1; |
| 10960 | copyRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10961 | m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 10962 | VK_IMAGE_LAYOUT_GENERAL, 1, ©Region); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10963 | EndCommandBuffer(); |
| 10964 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 10965 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10966 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10967 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 10968 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 10969 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 10970 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10971 | } |
| 10972 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10973 | TEST_F(VkLayerTest, ResolveImageLowSampleCount) { |
| 10974 | VkResult err; |
| 10975 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10976 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10977 | m_errorMonitor->SetDesiredFailureMsg( |
| 10978 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 10979 | "vkCmdResolveImage called with source sample count less than 2."); |
| 10980 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10981 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10982 | |
| 10983 | // 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] | 10984 | VkImage srcImage; |
| 10985 | VkImage dstImage; |
| 10986 | VkDeviceMemory srcMem; |
| 10987 | VkDeviceMemory destMem; |
| 10988 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 10989 | |
| 10990 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 10991 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 10992 | image_create_info.pNext = NULL; |
| 10993 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 10994 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 10995 | image_create_info.extent.width = 32; |
| 10996 | image_create_info.extent.height = 1; |
| 10997 | image_create_info.extent.depth = 1; |
| 10998 | image_create_info.mipLevels = 1; |
| 10999 | image_create_info.arrayLayers = 1; |
| 11000 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11001 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 11002 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 11003 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11004 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11005 | err = |
| 11006 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11007 | ASSERT_VK_SUCCESS(err); |
| 11008 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11009 | image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11010 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11011 | err = |
| 11012 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11013 | ASSERT_VK_SUCCESS(err); |
| 11014 | |
| 11015 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11016 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11017 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 11018 | memAlloc.pNext = NULL; |
| 11019 | memAlloc.allocationSize = 0; |
| 11020 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11021 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 11022 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11023 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11024 | pass = |
| 11025 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 11026 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11027 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11028 | ASSERT_VK_SUCCESS(err); |
| 11029 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11030 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11031 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11032 | pass = |
| 11033 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 11034 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11035 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11036 | ASSERT_VK_SUCCESS(err); |
| 11037 | |
| 11038 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 11039 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11040 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11041 | ASSERT_VK_SUCCESS(err); |
| 11042 | |
| 11043 | BeginCommandBuffer(); |
| 11044 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11045 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 11046 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11047 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11048 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11049 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 11050 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11051 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11052 | resolveRegion.srcOffset.x = 0; |
| 11053 | resolveRegion.srcOffset.y = 0; |
| 11054 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11055 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11056 | resolveRegion.dstSubresource.mipLevel = 0; |
| 11057 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 11058 | resolveRegion.dstSubresource.layerCount = 0; |
| 11059 | resolveRegion.dstOffset.x = 0; |
| 11060 | resolveRegion.dstOffset.y = 0; |
| 11061 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11062 | resolveRegion.extent.width = 1; |
| 11063 | resolveRegion.extent.height = 1; |
| 11064 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11065 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 11066 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11067 | EndCommandBuffer(); |
| 11068 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11069 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11070 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11071 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11072 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11073 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 11074 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11075 | } |
| 11076 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11077 | TEST_F(VkLayerTest, ResolveImageHighSampleCount) { |
| 11078 | VkResult err; |
| 11079 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11080 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11081 | m_errorMonitor->SetDesiredFailureMsg( |
| 11082 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11083 | "vkCmdResolveImage called with dest sample count greater than 1."); |
| 11084 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11085 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11086 | |
Chris Forbes | a753069 | 2016-05-08 12:35:39 +1200 | [diff] [blame] | 11087 | // 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] | 11088 | VkImage srcImage; |
| 11089 | VkImage dstImage; |
| 11090 | VkDeviceMemory srcMem; |
| 11091 | VkDeviceMemory destMem; |
| 11092 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11093 | |
| 11094 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11095 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11096 | image_create_info.pNext = NULL; |
| 11097 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11098 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11099 | image_create_info.extent.width = 32; |
| 11100 | image_create_info.extent.height = 1; |
| 11101 | image_create_info.extent.depth = 1; |
| 11102 | image_create_info.mipLevels = 1; |
| 11103 | image_create_info.arrayLayers = 1; |
Chris Forbes | a753069 | 2016-05-08 12:35:39 +1200 | [diff] [blame] | 11104 | image_create_info.samples = VK_SAMPLE_COUNT_4_BIT; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11105 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 11106 | // Note: Some implementations expect color attachment usage for any |
| 11107 | // multisample surface |
| 11108 | image_create_info.usage = |
| 11109 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 11110 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11111 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11112 | err = |
| 11113 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11114 | ASSERT_VK_SUCCESS(err); |
| 11115 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11116 | // Note: Some implementations expect color attachment usage for any |
| 11117 | // multisample surface |
| 11118 | image_create_info.usage = |
| 11119 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11120 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11121 | err = |
| 11122 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11123 | ASSERT_VK_SUCCESS(err); |
| 11124 | |
| 11125 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11126 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11127 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 11128 | memAlloc.pNext = NULL; |
| 11129 | memAlloc.allocationSize = 0; |
| 11130 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11131 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 11132 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11133 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11134 | pass = |
| 11135 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 11136 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11137 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11138 | ASSERT_VK_SUCCESS(err); |
| 11139 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11140 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11141 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11142 | pass = |
| 11143 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 11144 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11145 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11146 | ASSERT_VK_SUCCESS(err); |
| 11147 | |
| 11148 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 11149 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11150 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11151 | ASSERT_VK_SUCCESS(err); |
| 11152 | |
| 11153 | BeginCommandBuffer(); |
| 11154 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11155 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 11156 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11157 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11158 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11159 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 11160 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11161 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11162 | resolveRegion.srcOffset.x = 0; |
| 11163 | resolveRegion.srcOffset.y = 0; |
| 11164 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11165 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11166 | resolveRegion.dstSubresource.mipLevel = 0; |
| 11167 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 11168 | resolveRegion.dstSubresource.layerCount = 0; |
| 11169 | resolveRegion.dstOffset.x = 0; |
| 11170 | resolveRegion.dstOffset.y = 0; |
| 11171 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11172 | resolveRegion.extent.width = 1; |
| 11173 | resolveRegion.extent.height = 1; |
| 11174 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11175 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 11176 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11177 | EndCommandBuffer(); |
| 11178 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11179 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11180 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11181 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11182 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11183 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 11184 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11185 | } |
| 11186 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11187 | TEST_F(VkLayerTest, ResolveImageFormatMismatch) { |
| 11188 | VkResult err; |
| 11189 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11190 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11191 | m_errorMonitor->SetDesiredFailureMsg( |
| 11192 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11193 | "vkCmdResolveImage called with unmatched source and dest formats."); |
| 11194 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11195 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11196 | |
| 11197 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11198 | VkImage srcImage; |
| 11199 | VkImage dstImage; |
| 11200 | VkDeviceMemory srcMem; |
| 11201 | VkDeviceMemory destMem; |
| 11202 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11203 | |
| 11204 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11205 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11206 | image_create_info.pNext = NULL; |
| 11207 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11208 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11209 | image_create_info.extent.width = 32; |
| 11210 | image_create_info.extent.height = 1; |
| 11211 | image_create_info.extent.depth = 1; |
| 11212 | image_create_info.mipLevels = 1; |
| 11213 | image_create_info.arrayLayers = 1; |
| 11214 | image_create_info.samples = VK_SAMPLE_COUNT_2_BIT; |
| 11215 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 11216 | // Note: Some implementations expect color attachment usage for any |
| 11217 | // multisample surface |
| 11218 | image_create_info.usage = |
| 11219 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 11220 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11221 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11222 | err = |
| 11223 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11224 | ASSERT_VK_SUCCESS(err); |
| 11225 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11226 | // Set format to something other than source image |
| 11227 | image_create_info.format = VK_FORMAT_R32_SFLOAT; |
| 11228 | // Note: Some implementations expect color attachment usage for any |
| 11229 | // multisample surface |
| 11230 | image_create_info.usage = |
| 11231 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 11232 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11233 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11234 | err = |
| 11235 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11236 | ASSERT_VK_SUCCESS(err); |
| 11237 | |
| 11238 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11239 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11240 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 11241 | memAlloc.pNext = NULL; |
| 11242 | memAlloc.allocationSize = 0; |
| 11243 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11244 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 11245 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11246 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11247 | pass = |
| 11248 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 11249 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11250 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11251 | ASSERT_VK_SUCCESS(err); |
| 11252 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11253 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11254 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11255 | pass = |
| 11256 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 11257 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11258 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11259 | ASSERT_VK_SUCCESS(err); |
| 11260 | |
| 11261 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 11262 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11263 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11264 | ASSERT_VK_SUCCESS(err); |
| 11265 | |
| 11266 | BeginCommandBuffer(); |
| 11267 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11268 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 11269 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11270 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11271 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11272 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 11273 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11274 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11275 | resolveRegion.srcOffset.x = 0; |
| 11276 | resolveRegion.srcOffset.y = 0; |
| 11277 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11278 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11279 | resolveRegion.dstSubresource.mipLevel = 0; |
| 11280 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 11281 | resolveRegion.dstSubresource.layerCount = 0; |
| 11282 | resolveRegion.dstOffset.x = 0; |
| 11283 | resolveRegion.dstOffset.y = 0; |
| 11284 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11285 | resolveRegion.extent.width = 1; |
| 11286 | resolveRegion.extent.height = 1; |
| 11287 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11288 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 11289 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11290 | EndCommandBuffer(); |
| 11291 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11292 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11293 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11294 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11295 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11296 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 11297 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11298 | } |
| 11299 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11300 | TEST_F(VkLayerTest, ResolveImageTypeMismatch) { |
| 11301 | VkResult err; |
| 11302 | bool pass; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11303 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11304 | m_errorMonitor->SetDesiredFailureMsg( |
| 11305 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11306 | "vkCmdResolveImage called with unmatched source and dest image types."); |
| 11307 | |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11308 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11309 | |
| 11310 | // Create two images of different types and try to copy between them |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11311 | VkImage srcImage; |
| 11312 | VkImage dstImage; |
| 11313 | VkDeviceMemory srcMem; |
| 11314 | VkDeviceMemory destMem; |
| 11315 | VkMemoryRequirements memReqs; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11316 | |
| 11317 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11318 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11319 | image_create_info.pNext = NULL; |
| 11320 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11321 | image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11322 | image_create_info.extent.width = 32; |
| 11323 | image_create_info.extent.height = 1; |
| 11324 | image_create_info.extent.depth = 1; |
| 11325 | image_create_info.mipLevels = 1; |
| 11326 | image_create_info.arrayLayers = 1; |
| 11327 | image_create_info.samples = VK_SAMPLE_COUNT_2_BIT; |
| 11328 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 11329 | // Note: Some implementations expect color attachment usage for any |
| 11330 | // multisample surface |
| 11331 | image_create_info.usage = |
| 11332 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 11333 | image_create_info.flags = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11334 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11335 | err = |
| 11336 | vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11337 | ASSERT_VK_SUCCESS(err); |
| 11338 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11339 | image_create_info.imageType = VK_IMAGE_TYPE_1D; |
| 11340 | // Note: Some implementations expect color attachment usage for any |
| 11341 | // multisample surface |
| 11342 | image_create_info.usage = |
| 11343 | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 11344 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11345 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11346 | err = |
| 11347 | vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11348 | ASSERT_VK_SUCCESS(err); |
| 11349 | |
| 11350 | // Allocate memory |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11351 | VkMemoryAllocateInfo memAlloc = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11352 | memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; |
| 11353 | memAlloc.pNext = NULL; |
| 11354 | memAlloc.allocationSize = 0; |
| 11355 | memAlloc.memoryTypeIndex = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11356 | |
Courtney Goeltzenleuchter | 06d8947 | 2015-10-20 16:40:38 -0600 | [diff] [blame] | 11357 | vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11358 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11359 | pass = |
| 11360 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 11361 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11362 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11363 | ASSERT_VK_SUCCESS(err); |
| 11364 | |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11365 | vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11366 | memAlloc.allocationSize = memReqs.size; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11367 | pass = |
| 11368 | m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0); |
Courtney Goeltzenleuchter | 1d2f0dd | 2015-10-22 11:03:31 -0600 | [diff] [blame] | 11369 | ASSERT_TRUE(pass); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11370 | err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11371 | ASSERT_VK_SUCCESS(err); |
| 11372 | |
| 11373 | err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0); |
| 11374 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11375 | err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11376 | ASSERT_VK_SUCCESS(err); |
| 11377 | |
| 11378 | BeginCommandBuffer(); |
| 11379 | // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest? |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11380 | // VK_IMAGE_LAYOUT_UNDEFINED = 0, |
| 11381 | // VK_IMAGE_LAYOUT_GENERAL = 1, |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11382 | VkImageResolve resolveRegion; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11383 | resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11384 | resolveRegion.srcSubresource.mipLevel = 0; |
Courtney Goeltzenleuchter | 8367ce0 | 2015-10-16 09:46:00 -0600 | [diff] [blame] | 11385 | resolveRegion.srcSubresource.baseArrayLayer = 0; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11386 | resolveRegion.srcSubresource.layerCount = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11387 | resolveRegion.srcOffset.x = 0; |
| 11388 | resolveRegion.srcOffset.y = 0; |
| 11389 | resolveRegion.srcOffset.z = 0; |
Chia-I Wu | ab83a0e | 2015-10-27 19:00:15 +0800 | [diff] [blame] | 11390 | resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11391 | resolveRegion.dstSubresource.mipLevel = 0; |
| 11392 | resolveRegion.dstSubresource.baseArrayLayer = 0; |
| 11393 | resolveRegion.dstSubresource.layerCount = 0; |
| 11394 | resolveRegion.dstOffset.x = 0; |
| 11395 | resolveRegion.dstOffset.y = 0; |
| 11396 | resolveRegion.dstOffset.z = 0; |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11397 | resolveRegion.extent.width = 1; |
| 11398 | resolveRegion.extent.height = 1; |
| 11399 | resolveRegion.extent.depth = 1; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11400 | m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, |
| 11401 | VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11402 | EndCommandBuffer(); |
| 11403 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11404 | m_errorMonitor->VerifyFound(); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11405 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11406 | vkDestroyImage(m_device->device(), srcImage, NULL); |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11407 | vkDestroyImage(m_device->device(), dstImage, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11408 | vkFreeMemory(m_device->device(), srcMem, NULL); |
| 11409 | vkFreeMemory(m_device->device(), destMem, NULL); |
Mike Stroyan | a308243 | 2015-09-25 13:39:21 -0600 | [diff] [blame] | 11410 | } |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 11411 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11412 | TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) { |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 11413 | // 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] | 11414 | // to using a DS format, then cause it to hit error due to COLOR_BIT not |
| 11415 | // set in aspect |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 11416 | // The image format check comes 2nd in validation so we trigger it first, |
| 11417 | // 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] | 11418 | VkResult err; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 11419 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11420 | m_errorMonitor->SetDesiredFailureMsg( |
| 11421 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11422 | "Combination depth/stencil image formats can have only the "); |
| 11423 | |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 11424 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11425 | |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 11426 | VkDescriptorPoolSize ds_type_count = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11427 | ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 11428 | ds_type_count.descriptorCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 11429 | |
| 11430 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11431 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 11432 | ds_pool_ci.pNext = NULL; |
| 11433 | ds_pool_ci.maxSets = 1; |
| 11434 | ds_pool_ci.poolSizeCount = 1; |
| 11435 | ds_pool_ci.pPoolSizes = &ds_type_count; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 11436 | |
| 11437 | VkDescriptorPool ds_pool; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11438 | err = |
| 11439 | vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 11440 | ASSERT_VK_SUCCESS(err); |
| 11441 | |
| 11442 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11443 | dsl_binding.binding = 0; |
| 11444 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; |
| 11445 | dsl_binding.descriptorCount = 1; |
| 11446 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 11447 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 11448 | |
| 11449 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11450 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 11451 | ds_layout_ci.pNext = NULL; |
| 11452 | ds_layout_ci.bindingCount = 1; |
| 11453 | ds_layout_ci.pBindings = &dsl_binding; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 11454 | VkDescriptorSetLayout ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11455 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, |
| 11456 | &ds_layout); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 11457 | ASSERT_VK_SUCCESS(err); |
| 11458 | |
| 11459 | VkDescriptorSet descriptorSet; |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 11460 | VkDescriptorSetAllocateInfo alloc_info = {}; |
Chia-I Wu | 00ce540 | 2015-11-10 16:21:09 +0800 | [diff] [blame] | 11461 | alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 11462 | alloc_info.descriptorSetCount = 1; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 11463 | alloc_info.descriptorPool = ds_pool; |
| 11464 | alloc_info.pSetLayouts = &ds_layout; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11465 | err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, |
| 11466 | &descriptorSet); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 11467 | ASSERT_VK_SUCCESS(err); |
| 11468 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11469 | VkImage image_bad; |
| 11470 | VkImage image_good; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 11471 | // One bad format and one good format for Color attachment |
Tobin Ehlis | 269f032 | 2016-05-25 16:24:21 -0600 | [diff] [blame] | 11472 | const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 11473 | const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11474 | const int32_t tex_width = 32; |
| 11475 | const int32_t tex_height = 32; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 11476 | |
| 11477 | VkImageCreateInfo image_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11478 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11479 | image_create_info.pNext = NULL; |
| 11480 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11481 | image_create_info.format = tex_format_bad; |
| 11482 | image_create_info.extent.width = tex_width; |
| 11483 | image_create_info.extent.height = tex_height; |
| 11484 | image_create_info.extent.depth = 1; |
| 11485 | image_create_info.mipLevels = 1; |
| 11486 | image_create_info.arrayLayers = 1; |
| 11487 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11488 | image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 11489 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | |
| 11490 | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 11491 | image_create_info.flags = 0; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 11492 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11493 | err = |
| 11494 | vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 11495 | ASSERT_VK_SUCCESS(err); |
| 11496 | image_create_info.format = tex_format_good; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11497 | image_create_info.usage = |
| 11498 | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 11499 | err = vkCreateImage(m_device->device(), &image_create_info, NULL, |
| 11500 | &image_good); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 11501 | ASSERT_VK_SUCCESS(err); |
| 11502 | |
| 11503 | VkImageViewCreateInfo image_view_create_info = {}; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11504 | image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11505 | image_view_create_info.image = image_bad; |
| 11506 | image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; |
| 11507 | image_view_create_info.format = tex_format_bad; |
| 11508 | image_view_create_info.subresourceRange.baseArrayLayer = 0; |
| 11509 | image_view_create_info.subresourceRange.baseMipLevel = 0; |
| 11510 | image_view_create_info.subresourceRange.layerCount = 1; |
| 11511 | image_view_create_info.subresourceRange.levelCount = 1; |
| 11512 | image_view_create_info.subresourceRange.aspectMask = |
| 11513 | VK_IMAGE_ASPECT_COLOR_BIT; |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 11514 | |
| 11515 | VkImageView view; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11516 | err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, |
| 11517 | &view); |
Mark Lobodzinski | 8507f2f | 2015-10-29 09:02:49 -0600 | [diff] [blame] | 11518 | |
Chris Forbes | 8f36a8a | 2016-04-07 13:21:07 +1200 | [diff] [blame] | 11519 | m_errorMonitor->VerifyFound(); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 11520 | |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11521 | vkDestroyImage(m_device->device(), image_bad, NULL); |
| 11522 | vkDestroyImage(m_device->device(), image_good, NULL); |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 11523 | vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL); |
| 11524 | vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL); |
Tobin Ehlis | a1c2856 | 2015-10-23 16:00:08 -0600 | [diff] [blame] | 11525 | } |
Tobin Ehlis | 6e23d77 | 2016-05-19 11:08:34 -0600 | [diff] [blame] | 11526 | |
| 11527 | TEST_F(VkLayerTest, ClearImageErrors) { |
| 11528 | TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and " |
| 11529 | "ClearDepthStencilImage with a color image."); |
| 11530 | |
| 11531 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 11532 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 11533 | |
| 11534 | // Renderpass is started here so end it as Clear cmds can't be in renderpass |
| 11535 | BeginCommandBuffer(); |
| 11536 | m_commandBuffer->EndRenderPass(); |
| 11537 | |
| 11538 | // Color image |
| 11539 | VkClearColorValue clear_color; |
| 11540 | memset(clear_color.uint32, 0, sizeof(uint32_t) * 4); |
| 11541 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 11542 | const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 11543 | const int32_t img_width = 32; |
| 11544 | const int32_t img_height = 32; |
| 11545 | VkImageCreateInfo image_create_info = {}; |
| 11546 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 11547 | image_create_info.pNext = NULL; |
| 11548 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11549 | image_create_info.format = color_format; |
| 11550 | image_create_info.extent.width = img_width; |
| 11551 | image_create_info.extent.height = img_height; |
| 11552 | image_create_info.extent.depth = 1; |
| 11553 | image_create_info.mipLevels = 1; |
| 11554 | image_create_info.arrayLayers = 1; |
| 11555 | image_create_info.samples = VK_SAMPLE_COUNT_1_BIT; |
| 11556 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 11557 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 11558 | |
| 11559 | vk_testing::Image color_image; |
| 11560 | color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, |
| 11561 | reqs); |
| 11562 | |
| 11563 | const VkImageSubresourceRange color_range = |
| 11564 | vk_testing::Image::subresource_range(image_create_info, |
| 11565 | VK_IMAGE_ASPECT_COLOR_BIT); |
| 11566 | |
| 11567 | // Depth/Stencil image |
| 11568 | VkClearDepthStencilValue clear_value = {0}; |
| 11569 | reqs = 0; // don't need HOST_VISIBLE DS image |
| 11570 | VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info(); |
| 11571 | ds_image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 11572 | ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT; |
| 11573 | ds_image_create_info.extent.width = 64; |
| 11574 | ds_image_create_info.extent.height = 64; |
| 11575 | ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 11576 | ds_image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 11577 | |
| 11578 | vk_testing::Image ds_image; |
| 11579 | ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, |
| 11580 | reqs); |
| 11581 | |
| 11582 | const VkImageSubresourceRange ds_range = |
| 11583 | vk_testing::Image::subresource_range(ds_image_create_info, |
| 11584 | VK_IMAGE_ASPECT_DEPTH_BIT); |
| 11585 | |
| 11586 | m_errorMonitor->SetDesiredFailureMsg( |
| 11587 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11588 | "vkCmdClearColorImage called with depth/stencil image."); |
| 11589 | |
| 11590 | vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), |
| 11591 | VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, |
| 11592 | &color_range); |
| 11593 | |
| 11594 | m_errorMonitor->VerifyFound(); |
| 11595 | |
| 11596 | // Call CmdClearDepthStencilImage with color image |
| 11597 | m_errorMonitor->SetDesiredFailureMsg( |
| 11598 | VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 11599 | "vkCmdClearDepthStencilImage called without a depth/stencil image."); |
| 11600 | |
| 11601 | vkCmdClearDepthStencilImage( |
| 11602 | m_commandBuffer->GetBufferHandle(), color_image.handle(), |
| 11603 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, &clear_value, 1, |
| 11604 | &ds_range); |
| 11605 | |
| 11606 | m_errorMonitor->VerifyFound(); |
| 11607 | } |
Tobin Ehlis | cde0889 | 2015-09-22 10:11:37 -0600 | [diff] [blame] | 11608 | #endif // IMAGE_TESTS |
| 11609 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 11610 | int main(int argc, char **argv) { |
| 11611 | int result; |
| 11612 | |
Cody Northrop | 8e54a40 | 2016-03-08 22:25:52 -0700 | [diff] [blame] | 11613 | #ifdef ANDROID |
| 11614 | int vulkanSupport = InitVulkan(); |
| 11615 | if (vulkanSupport == 0) |
| 11616 | return 1; |
| 11617 | #endif |
| 11618 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 11619 | ::testing::InitGoogleTest(&argc, argv); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 11620 | VkTestFramework::InitArgs(&argc, argv); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 11621 | |
| 11622 | ::testing::AddGlobalTestEnvironment(new TestEnvironment); |
| 11623 | |
| 11624 | result = RUN_ALL_TESTS(); |
| 11625 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 11626 | VkTestFramework::Finish(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 11627 | return result; |
| 11628 | } |