Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1 | #include <vulkan.h> |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2 | #include "vk_debug_report_lunarg.h" |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 3 | #include "gtest-1.7.0/include/gtest/gtest.h" |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 4 | #include "vkrenderframework.h" |
Tobin Ehlis | 56d204a | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 5 | #include "vk_layer_config.h" |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 6 | |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 7 | #define GLM_FORCE_RADIANS |
| 8 | #include "glm/glm.hpp" |
| 9 | #include <glm/gtc/matrix_transform.hpp> |
| 10 | |
Tobin Ehlis | 57e6a61 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 11 | #define MEM_TRACKER_TESTS 1 |
| 12 | #define OBJ_TRACKER_TESTS 1 |
| 13 | #define DRAW_STATE_TESTS 1 |
| 14 | #define THREADING_TESTS 1 |
Chris Forbes | 5af3bf2 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 15 | #define SHADER_CHECKER_TESTS 1 |
Tobin Ehlis | 57e6a61 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 16 | |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 17 | //-------------------------------------------------------------------------------------- |
| 18 | // Mesh and VertexFormat Data |
| 19 | //-------------------------------------------------------------------------------------- |
| 20 | struct Vertex |
| 21 | { |
| 22 | float posX, posY, posZ, posW; // Position data |
| 23 | float r, g, b, a; // Color |
| 24 | }; |
| 25 | |
| 26 | #define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f |
| 27 | |
| 28 | typedef enum _BsoFailSelect { |
| 29 | BsoFailNone = 0x00000000, |
| 30 | BsoFailRaster = 0x00000001, |
| 31 | BsoFailViewport = 0x00000002, |
| 32 | BsoFailColorBlend = 0x00000004, |
| 33 | BsoFailDepthStencil = 0x00000008, |
| 34 | } BsoFailSelect; |
| 35 | |
| 36 | struct vktriangle_vs_uniform { |
| 37 | // Must start with MVP |
| 38 | float mvp[4][4]; |
| 39 | float position[3][4]; |
| 40 | float color[3][4]; |
| 41 | }; |
| 42 | |
Mark Lobodzinski | 6bbdff1 | 2015-06-02 09:41:30 -0500 | [diff] [blame] | 43 | static const char bindStateVertShaderText[] = |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 44 | "#version 130\n" |
| 45 | "vec2 vertices[3];\n" |
| 46 | "void main() {\n" |
| 47 | " vertices[0] = vec2(-1.0, -1.0);\n" |
| 48 | " vertices[1] = vec2( 1.0, -1.0);\n" |
| 49 | " vertices[2] = vec2( 0.0, 1.0);\n" |
| 50 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 51 | "}\n"; |
| 52 | |
Mark Lobodzinski | 6bbdff1 | 2015-06-02 09:41:30 -0500 | [diff] [blame] | 53 | static const char bindStateFragShaderText[] = |
Cody Northrop | 74a2d2c | 2015-06-16 17:32:04 -0600 | [diff] [blame] | 54 | "#version 140\n" |
| 55 | "#extension GL_ARB_separate_shader_objects: require\n" |
| 56 | "#extension GL_ARB_shading_language_420pack: require\n" |
| 57 | "\n" |
| 58 | "layout(location = 0) out vec4 uFragColor;\n" |
| 59 | "void main(){\n" |
| 60 | " uFragColor = vec4(0,1,0,1);\n" |
| 61 | "}\n"; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 62 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 63 | static void myDbgFunc( |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 64 | VkFlags msgFlags, |
| 65 | VkDbgObjectType objType, |
| 66 | uint64_t srcObject, |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 67 | size_t location, |
| 68 | int32_t msgCode, |
| 69 | const char* pLayerPrefix, |
| 70 | const char* pMsg, |
| 71 | void* pUserData); |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 72 | |
| 73 | class ErrorMonitor { |
| 74 | public: |
Tony Barbour | 0c1bdc6 | 2015-04-29 17:34:29 -0600 | [diff] [blame] | 75 | ErrorMonitor() |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 76 | { |
Mike Stroyan | 7016f4f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 77 | test_platform_thread_create_mutex(&m_mutex); |
| 78 | test_platform_thread_lock_mutex(&m_mutex); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 79 | m_msgFlags = VK_DBG_REPORT_INFO_BIT; |
Mike Stroyan | 09aae81 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 80 | m_bailout = NULL; |
Mike Stroyan | 7016f4f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 81 | test_platform_thread_unlock_mutex(&m_mutex); |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 82 | } |
| 83 | void ClearState() |
| 84 | { |
Mike Stroyan | 7016f4f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 85 | test_platform_thread_lock_mutex(&m_mutex); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 86 | m_msgFlags = VK_DBG_REPORT_INFO_BIT; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 87 | m_msgString.clear(); |
Mike Stroyan | 7016f4f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 88 | test_platform_thread_unlock_mutex(&m_mutex); |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 89 | } |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 90 | VkFlags GetState(std::string *msgString) |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 91 | { |
Mike Stroyan | 7016f4f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 92 | test_platform_thread_lock_mutex(&m_mutex); |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 93 | *msgString = m_msgString; |
Mike Stroyan | 7016f4f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 94 | test_platform_thread_unlock_mutex(&m_mutex); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 95 | return m_msgFlags; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 96 | } |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 97 | void SetState(VkFlags msgFlags, const char *msgString) |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 98 | { |
Mike Stroyan | 7016f4f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 99 | test_platform_thread_lock_mutex(&m_mutex); |
Mike Stroyan | 09aae81 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 100 | if (m_bailout != NULL) { |
| 101 | *m_bailout = true; |
| 102 | } |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 103 | m_msgFlags = msgFlags; |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 104 | m_msgString.reserve(strlen(msgString)); |
| 105 | m_msgString = msgString; |
Mike Stroyan | 7016f4f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 106 | test_platform_thread_unlock_mutex(&m_mutex); |
Mike Stroyan | 09aae81 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 107 | } |
| 108 | void SetBailout(bool *bailout) |
| 109 | { |
| 110 | m_bailout = bailout; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | private: |
Mike Stroyan | 7016f4f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 114 | VkFlags m_msgFlags; |
| 115 | std::string m_msgString; |
| 116 | test_platform_thread_mutex m_mutex; |
| 117 | bool* m_bailout; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 118 | }; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 119 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 120 | static void myDbgFunc( |
| 121 | VkFlags msgFlags, |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 122 | VkDbgObjectType objType, |
| 123 | uint64_t srcObject, |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 124 | size_t location, |
| 125 | int32_t msgCode, |
| 126 | const char* pLayerPrefix, |
| 127 | const char* pMsg, |
| 128 | void* pUserData) |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 129 | { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 130 | if (msgFlags & (VK_DBG_REPORT_WARN_BIT | VK_DBG_REPORT_ERROR_BIT)) { |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 131 | ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 132 | errMonitor->SetState(msgFlags, pMsg); |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 133 | } |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 134 | } |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 135 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 136 | class VkLayerTest : public VkRenderFramework |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 137 | { |
| 138 | public: |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 139 | VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer); |
| 140 | VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 141 | void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask); |
| 142 | void GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask); |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 143 | void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) |
| 144 | { GenericDrawPreparation(m_cmdBuffer, pipelineobj, descriptorSet, failMask); } |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 145 | |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 146 | /* Convenience functions that use built-in command buffer */ |
| 147 | VkResult BeginCommandBuffer() { return BeginCommandBuffer(*m_cmdBuffer); } |
| 148 | VkResult EndCommandBuffer() { return EndCommandBuffer(*m_cmdBuffer); } |
| 149 | void Draw(uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount) |
| 150 | { m_cmdBuffer->Draw(firstVertex, vertexCount, firstInstance, instanceCount); } |
| 151 | void DrawIndexed(uint32_t firstVertex, uint32_t vertexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount) |
| 152 | { m_cmdBuffer->DrawIndexed(firstVertex, vertexCount, vertexOffset,firstInstance, instanceCount); } |
| 153 | void QueueCommandBuffer() { m_cmdBuffer->QueueCommandBuffer(); } |
| 154 | void QueueCommandBuffer(const VkFence& fence) { m_cmdBuffer->QueueCommandBuffer(fence); } |
| 155 | void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) |
| 156 | { m_cmdBuffer->BindVertexBuffer(vertexBuffer, offset, binding); } |
| 157 | void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) |
| 158 | { m_cmdBuffer->BindIndexBuffer(indexBuffer, offset); } |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 159 | protected: |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 160 | ErrorMonitor *m_errorMonitor; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 161 | |
| 162 | virtual void SetUp() { |
Courtney Goeltzenleuchter | f5c6195 | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 163 | std::vector<const char *> instance_layer_names; |
| 164 | std::vector<const char *> device_layer_names; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 165 | std::vector<const char *> instance_extension_names; |
| 166 | std::vector<const char *> device_extension_names; |
Tony Barbour | 950ebc0 | 2015-04-23 12:55:36 -0600 | [diff] [blame] | 167 | |
Courtney Goeltzenleuchter | 846298c | 2015-07-30 11:32:46 -0600 | [diff] [blame] | 168 | instance_extension_names.push_back(VK_DEBUG_REPORT_EXTENSION_NAME); |
Courtney Goeltzenleuchter | de53c5b | 2015-06-16 15:59:11 -0600 | [diff] [blame] | 169 | /* |
| 170 | * Since CreateDbgMsgCallback is an instance level extension call |
| 171 | * any extension / layer that utilizes that feature also needs |
| 172 | * to be enabled at create instance time. |
| 173 | */ |
Mike Stroyan | ed25457 | 2015-06-17 16:32:06 -0600 | [diff] [blame] | 174 | // Use Threading layer first to protect others from ThreadCmdBufferCollision test |
Courtney Goeltzenleuchter | f5c6195 | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 175 | instance_layer_names.push_back("Threading"); |
| 176 | instance_layer_names.push_back("ObjectTracker"); |
| 177 | instance_layer_names.push_back("MemTracker"); |
| 178 | instance_layer_names.push_back("DrawState"); |
| 179 | instance_layer_names.push_back("ShaderChecker"); |
Courtney Goeltzenleuchter | 23b5f8d | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 180 | |
Courtney Goeltzenleuchter | f5c6195 | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 181 | device_layer_names.push_back("Threading"); |
| 182 | device_layer_names.push_back("ObjectTracker"); |
| 183 | device_layer_names.push_back("MemTracker"); |
| 184 | device_layer_names.push_back("DrawState"); |
| 185 | device_layer_names.push_back("ShaderChecker"); |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 186 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 187 | this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 188 | this->app_info.pNext = NULL; |
| 189 | this->app_info.pAppName = "layer_tests"; |
| 190 | this->app_info.appVersion = 1; |
| 191 | this->app_info.pEngineName = "unittest"; |
| 192 | this->app_info.engineVersion = 1; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 193 | this->app_info.apiVersion = VK_API_VERSION; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 194 | |
Tony Barbour | 0c1bdc6 | 2015-04-29 17:34:29 -0600 | [diff] [blame] | 195 | m_errorMonitor = new ErrorMonitor; |
Courtney Goeltzenleuchter | f5c6195 | 2015-07-06 09:10:47 -0600 | [diff] [blame] | 196 | InitFramework(instance_layer_names, device_layer_names, |
| 197 | instance_extension_names, device_extension_names, |
| 198 | myDbgFunc, m_errorMonitor); |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | virtual void TearDown() { |
| 202 | // Clean up resources before we reset |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 203 | ShutdownFramework(); |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 204 | delete m_errorMonitor; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 205 | } |
| 206 | }; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 207 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 208 | VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer) |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 209 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 210 | VkResult result; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 211 | |
| 212 | result = cmdBuffer.BeginCommandBuffer(); |
| 213 | |
| 214 | /* |
| 215 | * For render test all drawing happens in a single render pass |
| 216 | * on a single command buffer. |
| 217 | */ |
Chris Forbes | fe133ef | 2015-06-16 14:05:59 +1200 | [diff] [blame] | 218 | if (VK_SUCCESS == result && renderPass()) { |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 219 | cmdBuffer.BeginRenderPass(renderPassBeginInfo()); |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | return result; |
| 223 | } |
| 224 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 225 | VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer) |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 226 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 227 | VkResult result; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 228 | |
Chris Forbes | fe133ef | 2015-06-16 14:05:59 +1200 | [diff] [blame] | 229 | if (renderPass()) { |
Chia-I Wu | 88eaa3b | 2015-06-26 15:34:39 +0800 | [diff] [blame] | 230 | cmdBuffer.EndRenderPass(); |
Chris Forbes | fe133ef | 2015-06-16 14:05:59 +1200 | [diff] [blame] | 231 | } |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 232 | |
| 233 | result = cmdBuffer.EndCommandBuffer(); |
| 234 | |
| 235 | return result; |
| 236 | } |
| 237 | |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 238 | void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) |
| 239 | { |
| 240 | // Create identity matrix |
| 241 | int i; |
| 242 | struct vktriangle_vs_uniform data; |
| 243 | |
| 244 | glm::mat4 Projection = glm::mat4(1.0f); |
| 245 | glm::mat4 View = glm::mat4(1.0f); |
| 246 | glm::mat4 Model = glm::mat4(1.0f); |
| 247 | glm::mat4 MVP = Projection * View * Model; |
| 248 | const int matrixSize = sizeof(MVP); |
| 249 | const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float); |
| 250 | |
| 251 | memcpy(&data.mvp, &MVP[0][0], matrixSize); |
| 252 | |
| 253 | static const Vertex tri_data[] = |
| 254 | { |
| 255 | { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 256 | { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 257 | { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 258 | }; |
| 259 | |
| 260 | for (i=0; i<3; i++) { |
| 261 | data.position[i][0] = tri_data[i].posX; |
| 262 | data.position[i][1] = tri_data[i].posY; |
| 263 | data.position[i][2] = tri_data[i].posZ; |
| 264 | data.position[i][3] = tri_data[i].posW; |
| 265 | data.color[i][0] = tri_data[i].r; |
| 266 | data.color[i][1] = tri_data[i].g; |
| 267 | data.color[i][2] = tri_data[i].b; |
| 268 | data.color[i][3] = tri_data[i].a; |
| 269 | } |
| 270 | |
| 271 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 272 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 273 | |
| 274 | VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data); |
| 275 | |
| 276 | VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this); |
| 277 | VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this); |
| 278 | |
| 279 | VkPipelineObj pipelineobj(m_device); |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 280 | pipelineobj.AddColorAttachment(); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 281 | pipelineobj.AddShader(&vs); |
| 282 | pipelineobj.AddShader(&ps); |
| 283 | |
| 284 | VkDescriptorSetObj descriptorSet(m_device); |
| 285 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer); |
| 286 | |
| 287 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 288 | ASSERT_VK_SUCCESS(BeginCommandBuffer()); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 289 | |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 290 | GenericDrawPreparation(pipelineobj, descriptorSet, failMask); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 291 | |
| 292 | // render triangle |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 293 | Draw(0, 3, 0, 1); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 294 | |
| 295 | // finalize recording of the command buffer |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 296 | EndCommandBuffer(); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 297 | |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 298 | QueueCommandBuffer(); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) |
| 302 | { |
| 303 | if (m_depthStencil->Initialized()) { |
| 304 | cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil); |
| 305 | } else { |
| 306 | cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL); |
| 307 | } |
| 308 | |
| 309 | cmdBuffer->PrepareAttachments(); |
| 310 | if ((failMask & BsoFailRaster) != BsoFailRaster) { |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 311 | cmdBuffer->BindDynamicRasterState(m_stateRaster); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 312 | } |
| 313 | if ((failMask & BsoFailViewport) != BsoFailViewport) { |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 314 | cmdBuffer->BindDynamicViewportState(m_stateViewport); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 315 | } |
| 316 | if ((failMask & BsoFailColorBlend) != BsoFailColorBlend) { |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 317 | cmdBuffer->BindDynamicColorBlendState(m_colorBlend); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 318 | } |
| 319 | if ((failMask & BsoFailDepthStencil) != BsoFailDepthStencil) { |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 320 | cmdBuffer->BindDynamicDepthStencilState(m_stateDepthStencil); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 321 | } |
Tobin Ehlis | 40e9f52 | 2015-06-25 11:58:41 -0600 | [diff] [blame] | 322 | // Make sure depthWriteEnable is set so that DepthStencil fail test will work correctly |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 323 | VkStencilOpState stencil = {}; |
| 324 | stencil.stencilFailOp = VK_STENCIL_OP_KEEP; |
| 325 | stencil.stencilPassOp = VK_STENCIL_OP_KEEP; |
| 326 | stencil.stencilDepthFailOp = VK_STENCIL_OP_KEEP; |
| 327 | stencil.stencilCompareOp = VK_COMPARE_OP_NEVER; |
| 328 | |
| 329 | VkPipelineDepthStencilStateCreateInfo ds_ci = {}; |
| 330 | ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; |
| 331 | ds_ci.pNext = NULL; |
| 332 | ds_ci.depthTestEnable = VK_FALSE; |
| 333 | ds_ci.depthWriteEnable = VK_TRUE; |
| 334 | ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER; |
| 335 | ds_ci.depthBoundsEnable = VK_FALSE; |
| 336 | ds_ci.stencilTestEnable = VK_FALSE; |
| 337 | ds_ci.front = stencil; |
| 338 | ds_ci.back = stencil; |
| 339 | |
Tobin Ehlis | 40e9f52 | 2015-06-25 11:58:41 -0600 | [diff] [blame] | 340 | pipelineobj.SetDepthStencil(&ds_ci); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 341 | descriptorSet.CreateVKDescriptorSet(cmdBuffer); |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 342 | pipelineobj.CreateVKPipeline(descriptorSet, renderPass()); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 343 | cmdBuffer->BindPipeline(pipelineobj); |
| 344 | cmdBuffer->BindDescriptorSet(descriptorSet); |
| 345 | } |
| 346 | |
| 347 | // ******************************************************************************************************************** |
| 348 | // ******************************************************************************************************************** |
| 349 | // ******************************************************************************************************************** |
| 350 | // ******************************************************************************************************************** |
Tobin Ehlis | 57e6a61 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 351 | #if MEM_TRACKER_TESTS |
Mark Lobodzinski | 8107819 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 352 | TEST_F(VkLayerTest, CallResetCmdBufferBeforeCompletion) |
| 353 | { |
| 354 | vk_testing::Fence testFence; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 355 | VkFlags msgFlags; |
Mark Lobodzinski | 8107819 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 356 | std::string msgString; |
| 357 | |
| 358 | VkFenceCreateInfo fenceInfo = {}; |
| 359 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 360 | fenceInfo.pNext = NULL; |
| 361 | fenceInfo.flags = 0; |
| 362 | |
| 363 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Tony Barbour | e389b88 | 2015-07-20 13:00:10 -0600 | [diff] [blame] | 364 | |
| 365 | VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 366 | vk_testing::Buffer buffer; |
| 367 | buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs); |
Mark Lobodzinski | 8107819 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 368 | |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 369 | BeginCommandBuffer(); |
| 370 | m_cmdBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111); |
| 371 | EndCommandBuffer(); |
Mark Lobodzinski | 8107819 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 372 | |
| 373 | testFence.init(*m_device, fenceInfo); |
| 374 | |
| 375 | // Bypass framework since it does the waits automatically |
| 376 | VkResult err = VK_SUCCESS; |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 377 | err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle()); |
Mark Lobodzinski | 8107819 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 378 | ASSERT_VK_SUCCESS( err ); |
| 379 | |
| 380 | m_errorMonitor->ClearState(); |
| 381 | // Introduce failure by calling begin again before checking fence |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 382 | vkResetCommandBuffer(m_cmdBuffer->handle(), 0); |
Mark Lobodzinski | 8107819 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 383 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 384 | msgFlags = m_errorMonitor->GetState(&msgString); |
| 385 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an err after calling ResetCommandBuffer on an active Command Buffer"; |
Mark Lobodzinski | 8107819 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 386 | if (!strstr(msgString.c_str(),"Resetting CB")) { |
| 387 | FAIL() << "Error received was not 'Resetting CB (0xaddress) before it has completed. You must check CB flag before'"; |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | TEST_F(VkLayerTest, CallBeginCmdBufferBeforeCompletion) |
| 392 | { |
| 393 | vk_testing::Fence testFence; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 394 | VkFlags msgFlags; |
Mark Lobodzinski | 8107819 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 395 | std::string msgString; |
| 396 | |
| 397 | VkFenceCreateInfo fenceInfo = {}; |
| 398 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 399 | fenceInfo.pNext = NULL; |
| 400 | fenceInfo.flags = 0; |
| 401 | |
| 402 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 403 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 404 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 405 | |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 406 | BeginCommandBuffer(); |
| 407 | m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL); |
| 408 | EndCommandBuffer(); |
Mark Lobodzinski | 8107819 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 409 | |
| 410 | testFence.init(*m_device, fenceInfo); |
| 411 | |
| 412 | // Bypass framework since it does the waits automatically |
| 413 | VkResult err = VK_SUCCESS; |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 414 | err = vkQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer->handle(), testFence.handle()); |
Mark Lobodzinski | 8107819 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 415 | ASSERT_VK_SUCCESS( err ); |
| 416 | |
| 417 | m_errorMonitor->ClearState(); |
| 418 | // Introduce failure by calling begin again before checking fence |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 419 | BeginCommandBuffer(); |
Mark Lobodzinski | 8107819 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 420 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 421 | msgFlags = m_errorMonitor->GetState(&msgString); |
| 422 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an err after calling BeginCommandBuffer on an active Command Buffer"; |
Mark Lobodzinski | 8107819 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 423 | if (!strstr(msgString.c_str(),"Calling vkBeginCommandBuffer() on active CB")) { |
| 424 | FAIL() << "Error received was not 'Calling vkBeginCommandBuffer() on an active CB (0xaddress) before it has completed'"; |
| 425 | } |
| 426 | } |
| 427 | |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 428 | TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) |
| 429 | { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 430 | VkFlags msgFlags; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 431 | std::string msgString; |
| 432 | VkResult err; |
| 433 | |
| 434 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 435 | m_errorMonitor->ClearState(); |
| 436 | |
| 437 | // Create an image, allocate memory, free it, and then try to bind it |
| 438 | VkImage image; |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 439 | VkDeviceMemory mem; |
| 440 | VkMemoryRequirements mem_reqs; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 441 | |
| 442 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 443 | const int32_t tex_width = 32; |
| 444 | const int32_t tex_height = 32; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 445 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 446 | VkImageCreateInfo image_create_info = {}; |
| 447 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 448 | image_create_info.pNext = NULL; |
| 449 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 450 | image_create_info.format = tex_format; |
| 451 | image_create_info.extent.width = tex_width; |
| 452 | image_create_info.extent.height = tex_height; |
| 453 | image_create_info.extent.depth = 1; |
| 454 | image_create_info.mipLevels = 1; |
| 455 | image_create_info.arraySize = 1; |
| 456 | image_create_info.samples = 1; |
| 457 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 458 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 459 | image_create_info.flags = 0; |
| 460 | |
| 461 | VkMemoryAllocInfo mem_alloc = {}; |
| 462 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 463 | mem_alloc.pNext = NULL; |
| 464 | mem_alloc.allocationSize = 0; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 465 | // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 466 | mem_alloc.memoryTypeIndex = 1; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 467 | |
| 468 | err = vkCreateImage(m_device->device(), &image_create_info, &image); |
| 469 | ASSERT_VK_SUCCESS(err); |
| 470 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 471 | err = vkGetImageMemoryRequirements(m_device->device(), |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 472 | image, |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 473 | &mem_reqs); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 474 | ASSERT_VK_SUCCESS(err); |
| 475 | |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 476 | mem_alloc.allocationSize = mem_reqs.size; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 477 | |
| 478 | // allocate memory |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 479 | err = vkAllocMemory(m_device->device(), &mem_alloc, &mem); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 480 | ASSERT_VK_SUCCESS(err); |
| 481 | |
| 482 | // Try to bind free memory that has been freed |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 483 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 484 | ASSERT_VK_SUCCESS(err); |
| 485 | |
| 486 | // Map memory as if to initialize the image |
| 487 | void *mappedAddress = NULL; |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 488 | err = vkMapMemory(m_device->device(), mem, 0, 0, 0, &mappedAddress); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 489 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 490 | msgFlags = m_errorMonitor->GetState(&msgString); |
| 491 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an error while tring to map memory not visible to CPU"; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 492 | if (!strstr(msgString.c_str(),"Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT")) { |
| 493 | FAIL() << "Error received did not match expected error message from vkMapMemory in MemTracker"; |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | TEST_F(VkLayerTest, BindInvalidMemory) |
| 498 | { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 499 | VkFlags msgFlags; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 500 | std::string msgString; |
| 501 | VkResult err; |
| 502 | |
| 503 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 504 | m_errorMonitor->ClearState(); |
| 505 | |
| 506 | // Create an image, allocate memory, free it, and then try to bind it |
| 507 | VkImage image; |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 508 | VkDeviceMemory mem; |
| 509 | VkMemoryRequirements mem_reqs; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 510 | |
| 511 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 512 | const int32_t tex_width = 32; |
| 513 | const int32_t tex_height = 32; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 514 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 515 | VkImageCreateInfo image_create_info = {}; |
| 516 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 517 | image_create_info.pNext = NULL; |
| 518 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 519 | image_create_info.format = tex_format; |
| 520 | image_create_info.extent.width = tex_width; |
| 521 | image_create_info.extent.height = tex_height; |
| 522 | image_create_info.extent.depth = 1; |
| 523 | image_create_info.mipLevels = 1; |
| 524 | image_create_info.arraySize = 1; |
| 525 | image_create_info.samples = 1; |
| 526 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 527 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 528 | image_create_info.flags = 0; |
| 529 | |
| 530 | VkMemoryAllocInfo mem_alloc = {}; |
| 531 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 532 | mem_alloc.pNext = NULL; |
| 533 | mem_alloc.allocationSize = 0; |
| 534 | mem_alloc.memoryTypeIndex = 0; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 535 | |
| 536 | err = vkCreateImage(m_device->device(), &image_create_info, &image); |
| 537 | ASSERT_VK_SUCCESS(err); |
| 538 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 539 | err = vkGetImageMemoryRequirements(m_device->device(), |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 540 | image, |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 541 | &mem_reqs); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 542 | ASSERT_VK_SUCCESS(err); |
| 543 | |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 544 | mem_alloc.allocationSize = mem_reqs.size; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 545 | |
Chia-I Wu | f5fb109 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 546 | err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Mark Lobodzinski | 7234629 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 547 | ASSERT_VK_SUCCESS(err); |
| 548 | |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 549 | // allocate memory |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 550 | err = vkAllocMemory(m_device->device(), &mem_alloc, &mem); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 551 | ASSERT_VK_SUCCESS(err); |
| 552 | |
| 553 | // Introduce validation failure, free memory before binding |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 554 | vkFreeMemory(m_device->device(), mem); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 555 | ASSERT_VK_SUCCESS(err); |
| 556 | |
| 557 | // Try to bind free memory that has been freed |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 558 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 559 | ASSERT_VK_SUCCESS(err); |
| 560 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 561 | msgFlags = m_errorMonitor->GetState(&msgString); |
| 562 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an error while tring to bind a freed memory object"; |
Mark Lobodzinski | c66c671 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 563 | if (!strstr(msgString.c_str(),"couldn't find info for mem obj")) { |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 564 | FAIL() << "Error received did not match expected error message from BindObjectMemory in MemTracker"; |
| 565 | } |
| 566 | } |
| 567 | |
Tobin Ehlis | 33ce8fd | 2015-07-10 18:25:07 -0600 | [diff] [blame] | 568 | // TODO : Is this test still valid. Not sure it is with updates to memory binding model |
| 569 | // Verify and delete the test of fix the check |
| 570 | //TEST_F(VkLayerTest, FreeBoundMemory) |
| 571 | //{ |
| 572 | // VkFlags msgFlags; |
| 573 | // std::string msgString; |
| 574 | // VkResult err; |
| 575 | // |
| 576 | // ASSERT_NO_FATAL_FAILURE(InitState()); |
| 577 | // m_errorMonitor->ClearState(); |
| 578 | // |
| 579 | // // Create an image, allocate memory, free it, and then try to bind it |
| 580 | // VkImage image; |
| 581 | // VkDeviceMemory mem; |
| 582 | // VkMemoryRequirements mem_reqs; |
| 583 | // |
| 584 | // const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 585 | // const int32_t tex_width = 32; |
| 586 | // const int32_t tex_height = 32; |
| 587 | // |
| 588 | // const VkImageCreateInfo image_create_info = { |
| 589 | // .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, |
| 590 | // .pNext = NULL, |
| 591 | // .imageType = VK_IMAGE_TYPE_2D, |
| 592 | // .format = tex_format, |
| 593 | // .extent = { tex_width, tex_height, 1 }, |
| 594 | // .mipLevels = 1, |
| 595 | // .arraySize = 1, |
| 596 | // .samples = 1, |
| 597 | // .tiling = VK_IMAGE_TILING_LINEAR, |
| 598 | // .usage = VK_IMAGE_USAGE_SAMPLED_BIT, |
| 599 | // .flags = 0, |
| 600 | // }; |
| 601 | // VkMemoryAllocInfo mem_alloc = { |
| 602 | // .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO, |
| 603 | // .pNext = NULL, |
| 604 | // .allocationSize = 0, |
| 605 | // .memoryTypeIndex = 0, |
| 606 | // }; |
| 607 | // |
| 608 | // err = vkCreateImage(m_device->device(), &image_create_info, &image); |
| 609 | // ASSERT_VK_SUCCESS(err); |
| 610 | // |
| 611 | // err = vkGetImageMemoryRequirements(m_device->device(), |
| 612 | // image, |
| 613 | // &mem_reqs); |
| 614 | // ASSERT_VK_SUCCESS(err); |
| 615 | // |
| 616 | // mem_alloc.allocationSize = mem_reqs.size; |
| 617 | // |
| 618 | // err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
| 619 | // ASSERT_VK_SUCCESS(err); |
| 620 | // |
| 621 | // // allocate memory |
| 622 | // err = vkAllocMemory(m_device->device(), &mem_alloc, &mem); |
| 623 | // ASSERT_VK_SUCCESS(err); |
| 624 | // |
| 625 | // // Bind memory to Image object |
| 626 | // err = vkBindImageMemory(m_device->device(), image, mem, 0); |
| 627 | // ASSERT_VK_SUCCESS(err); |
| 628 | // |
| 629 | // // Introduce validation failure, free memory while still bound to object |
| 630 | // vkFreeMemory(m_device->device(), mem); |
| 631 | // ASSERT_VK_SUCCESS(err); |
| 632 | // |
| 633 | // msgFlags = m_errorMonitor->GetState(&msgString); |
| 634 | // ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an warning while tring to free bound memory"; |
| 635 | // if (!strstr(msgString.c_str(),"Freeing memory object while it still has references")) { |
| 636 | // FAIL() << "Warning received did not match expected message from freeMemObjInfo in MemTracker"; |
| 637 | // } |
| 638 | //} |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 639 | |
Mark Lobodzinski | c66c671 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 640 | TEST_F(VkLayerTest, RebindMemory) |
| 641 | { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 642 | VkFlags msgFlags; |
Mark Lobodzinski | c66c671 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 643 | std::string msgString; |
| 644 | VkResult err; |
| 645 | |
| 646 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 647 | m_errorMonitor->ClearState(); |
| 648 | |
| 649 | // Create an image, allocate memory, free it, and then try to bind it |
| 650 | VkImage image; |
| 651 | VkDeviceMemory mem1; |
| 652 | VkDeviceMemory mem2; |
| 653 | VkMemoryRequirements mem_reqs; |
| 654 | |
| 655 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 656 | const int32_t tex_width = 32; |
| 657 | const int32_t tex_height = 32; |
Mark Lobodzinski | c66c671 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 658 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 659 | VkImageCreateInfo image_create_info = {}; |
| 660 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 661 | image_create_info.pNext = NULL; |
| 662 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 663 | image_create_info.format = tex_format; |
| 664 | image_create_info.extent.width = tex_width; |
| 665 | image_create_info.extent.height = tex_height; |
| 666 | image_create_info.extent.depth = 1; |
| 667 | image_create_info.mipLevels = 1; |
| 668 | image_create_info.arraySize = 1; |
| 669 | image_create_info.samples = 1; |
| 670 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 671 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 672 | image_create_info.flags = 0; |
Mark Lobodzinski | c66c671 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 673 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 674 | VkMemoryAllocInfo mem_alloc = {}; |
| 675 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 676 | mem_alloc.pNext = NULL; |
| 677 | mem_alloc.allocationSize = 0; |
| 678 | mem_alloc.memoryTypeIndex = 0; |
| 679 | |
| 680 | // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
| 681 | mem_alloc.memoryTypeIndex = 1; |
Mark Lobodzinski | c66c671 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 682 | err = vkCreateImage(m_device->device(), &image_create_info, &image); |
| 683 | ASSERT_VK_SUCCESS(err); |
| 684 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 685 | err = vkGetImageMemoryRequirements(m_device->device(), |
Mark Lobodzinski | c66c671 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 686 | image, |
Mark Lobodzinski | c66c671 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 687 | &mem_reqs); |
| 688 | ASSERT_VK_SUCCESS(err); |
| 689 | |
| 690 | mem_alloc.allocationSize = mem_reqs.size; |
Chia-I Wu | f5fb109 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 691 | err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Mark Lobodzinski | 7234629 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 692 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | c66c671 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 693 | |
| 694 | // allocate 2 memory objects |
| 695 | err = vkAllocMemory(m_device->device(), &mem_alloc, &mem1); |
| 696 | ASSERT_VK_SUCCESS(err); |
| 697 | err = vkAllocMemory(m_device->device(), &mem_alloc, &mem2); |
| 698 | ASSERT_VK_SUCCESS(err); |
| 699 | |
| 700 | // Bind first memory object to Image object |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 701 | err = vkBindImageMemory(m_device->device(), image, mem1, 0); |
Mark Lobodzinski | c66c671 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 702 | ASSERT_VK_SUCCESS(err); |
| 703 | |
| 704 | // Introduce validation failure, try to bind a different memory object to the same image object |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 705 | err = vkBindImageMemory(m_device->device(), image, mem2, 0); |
Mark Lobodzinski | c66c671 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 706 | ASSERT_VK_SUCCESS(err); |
| 707 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 708 | msgFlags = m_errorMonitor->GetState(&msgString); |
| 709 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an error while tring to rebind an object"; |
Mark Lobodzinski | c66c671 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 710 | if (!strstr(msgString.c_str(),"which has already been bound to mem object")) { |
| 711 | FAIL() << "Error received did not match expected message when rebinding memory to an object"; |
| 712 | } |
| 713 | } |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 714 | |
| 715 | TEST_F(VkLayerTest, BindMemoryToDestroyedObject) |
| 716 | { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 717 | VkFlags msgFlags; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 718 | std::string msgString; |
| 719 | VkResult err; |
| 720 | |
| 721 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 722 | m_errorMonitor->ClearState(); |
| 723 | |
| 724 | // Create an image object, allocate memory, destroy the object and then try to bind it |
| 725 | VkImage image; |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 726 | VkDeviceMemory mem; |
| 727 | VkMemoryRequirements mem_reqs; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 728 | |
| 729 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 730 | const int32_t tex_width = 32; |
| 731 | const int32_t tex_height = 32; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 732 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 733 | VkImageCreateInfo image_create_info = {}; |
| 734 | image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 735 | image_create_info.pNext = NULL; |
| 736 | image_create_info.imageType = VK_IMAGE_TYPE_2D; |
| 737 | image_create_info.format = tex_format; |
| 738 | image_create_info.extent.width = tex_width; |
| 739 | image_create_info.extent.height = tex_height; |
| 740 | image_create_info.extent.depth = 1; |
| 741 | image_create_info.mipLevels = 1; |
| 742 | image_create_info.arraySize = 1; |
| 743 | image_create_info.samples = 1; |
| 744 | image_create_info.tiling = VK_IMAGE_TILING_LINEAR; |
| 745 | image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 746 | image_create_info.flags = 0; |
| 747 | |
| 748 | VkMemoryAllocInfo mem_alloc = {}; |
| 749 | mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 750 | mem_alloc.pNext = NULL; |
| 751 | mem_alloc.allocationSize = 0; |
| 752 | mem_alloc.memoryTypeIndex = 0; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 753 | |
| 754 | err = vkCreateImage(m_device->device(), &image_create_info, &image); |
| 755 | ASSERT_VK_SUCCESS(err); |
| 756 | |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 757 | err = vkGetImageMemoryRequirements(m_device->device(), |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 758 | image, |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 759 | &mem_reqs); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 760 | ASSERT_VK_SUCCESS(err); |
| 761 | |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 762 | mem_alloc.allocationSize = mem_reqs.size; |
Chia-I Wu | f5fb109 | 2015-07-03 10:32:05 +0800 | [diff] [blame] | 763 | err = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0); |
Mark Lobodzinski | 7234629 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 764 | ASSERT_VK_SUCCESS(err); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 765 | |
| 766 | // Allocate memory |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 767 | err = vkAllocMemory(m_device->device(), &mem_alloc, &mem); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 768 | ASSERT_VK_SUCCESS(err); |
| 769 | |
| 770 | // Introduce validation failure, destroy Image object before binding |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 771 | vkDestroyImage(m_device->device(), image); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 772 | ASSERT_VK_SUCCESS(err); |
| 773 | |
| 774 | // Now Try to bind memory to this destroyted object |
Tony Barbour | e84a8d6 | 2015-07-10 14:10:27 -0600 | [diff] [blame] | 775 | err = vkBindImageMemory(m_device->device(), image, mem, 0); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 776 | ASSERT_VK_SUCCESS(err); |
| 777 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 778 | msgFlags = m_errorMonitor->GetState(&msgString); |
| 779 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an error while binding memory to a destroyed object"; |
Mark Lobodzinski | c66c671 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 780 | if (!strstr(msgString.c_str(),"that's not in global list")) { |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 781 | FAIL() << "Error received did not match expected error message from updateObjectBinding in MemTracker"; |
| 782 | } |
| 783 | } |
| 784 | |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 785 | TEST_F(VkLayerTest, SubmitSignaledFence) |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 786 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 787 | vk_testing::Fence testFence; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 788 | VkFlags msgFlags; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 789 | std::string msgString; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 790 | |
| 791 | VkFenceCreateInfo fenceInfo = {}; |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 792 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 793 | fenceInfo.pNext = NULL; |
| 794 | fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 795 | |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 796 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 797 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 798 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 799 | |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 800 | BeginCommandBuffer(); |
| 801 | m_cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL); |
| 802 | EndCommandBuffer(); |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 803 | |
| 804 | testFence.init(*m_device, fenceInfo); |
| 805 | m_errorMonitor->ClearState(); |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 806 | QueueCommandBuffer(testFence.handle()); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 807 | msgFlags = m_errorMonitor->GetState(&msgString); |
| 808 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an err from using a fence in SIGNALED state in call to vkQueueSubmit"; |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 809 | if (!strstr(msgString.c_str(),"submitted in SIGNALED state. Fences must be reset before being submitted")) { |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 810 | FAIL() << "Error received was not 'VkQueueSubmit with fence in SIGNALED_STATE'"; |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | } |
| 814 | |
| 815 | TEST_F(VkLayerTest, ResetUnsignaledFence) |
| 816 | { |
| 817 | vk_testing::Fence testFence; |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 818 | VkFlags msgFlags; |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 819 | std::string msgString; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 820 | VkFenceCreateInfo fenceInfo = {}; |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 821 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 822 | fenceInfo.pNext = NULL; |
| 823 | |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 824 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 825 | testFence.init(*m_device, fenceInfo); |
| 826 | m_errorMonitor->ClearState(); |
Chia-I Wu | a499234 | 2015-07-03 11:45:55 +0800 | [diff] [blame] | 827 | VkFence fences[1] = {testFence.handle()}; |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 828 | vkResetFences(m_device->device(), 1, fences); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 829 | msgFlags = m_errorMonitor->GetState(&msgString); |
| 830 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an error from submitting fence with UNSIGNALED state to vkResetFences"; |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 831 | if (!strstr(msgString.c_str(),"submitted to VkResetFences in UNSIGNALED STATE")) { |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 832 | FAIL() << "Error received was not 'VkResetFences with fence in UNSIGNALED_STATE'"; |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 833 | } |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 834 | |
| 835 | } |
Tobin Ehlis | d94ba72 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 836 | |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 837 | /* TODO: Update for changes due to bug-14075 tiling across render passes */ |
| 838 | #if 0 |
Tobin Ehlis | d94ba72 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 839 | TEST_F(VkLayerTest, InvalidUsageBits) |
| 840 | { |
| 841 | // Initiate Draw w/o a PSO bound |
| 842 | VkFlags msgFlags; |
| 843 | std::string msgString; |
| 844 | |
| 845 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 846 | m_errorMonitor->ClearState(); |
| 847 | VkCommandBufferObj cmdBuffer(m_device); |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 848 | BeginCommandBuffer(); |
Tobin Ehlis | d94ba72 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 849 | |
| 850 | const VkExtent3D e3d = { |
| 851 | .width = 128, |
| 852 | .height = 128, |
| 853 | .depth = 1, |
| 854 | }; |
| 855 | const VkImageCreateInfo ici = { |
| 856 | .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, |
| 857 | .pNext = NULL, |
| 858 | .imageType = VK_IMAGE_TYPE_2D, |
| 859 | .format = VK_FORMAT_D32_SFLOAT_S8_UINT, |
| 860 | .extent = e3d, |
| 861 | .mipLevels = 1, |
| 862 | .arraySize = 1, |
| 863 | .samples = 1, |
| 864 | .tiling = VK_IMAGE_TILING_LINEAR, |
| 865 | .usage = 0, // Not setting VK_IMAGE_USAGE_DEPTH_STENCIL_BIT |
| 866 | .flags = 0, |
| 867 | }; |
| 868 | |
| 869 | VkImage dsi; |
| 870 | vkCreateImage(m_device->device(), &ici, &dsi); |
| 871 | VkDepthStencilView dsv; |
| 872 | const VkDepthStencilViewCreateInfo dsvci = { |
| 873 | .sType = VK_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO, |
| 874 | .pNext = NULL, |
| 875 | .image = dsi, |
| 876 | .mipLevel = 0, |
| 877 | .baseArraySlice = 0, |
| 878 | .arraySize = 1, |
| 879 | .flags = 0, |
| 880 | }; |
| 881 | vkCreateDepthStencilView(m_device->device(), &dsvci, &dsv); |
| 882 | msgFlags = m_errorMonitor->GetState(&msgString); |
| 883 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after attempting to create DSView w/ image lacking USAGE_DS_BIT flag"; |
| 884 | if (!strstr(msgString.c_str(),"Invalid usage flag for image ")) { |
| 885 | FAIL() << "Error received was not 'Invalid usage flag for image...'"; |
| 886 | } |
| 887 | } |
Tobin Ehlis | 57e6a61 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 888 | #endif |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 889 | #endif |
Tobin Ehlis | 40e9f52 | 2015-06-25 11:58:41 -0600 | [diff] [blame] | 890 | #if OBJ_TRACKER_TESTS |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 891 | TEST_F(VkLayerTest, RasterStateNotBound) |
| 892 | { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 893 | VkFlags msgFlags; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 894 | std::string msgString; |
Tobin Ehlis | 254eca0 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 895 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 896 | m_errorMonitor->ClearState(); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 897 | TEST_DESCRIPTION("Simple Draw Call that validates failure when a raster state object is not bound beforehand"); |
| 898 | |
| 899 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailRaster); |
| 900 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 901 | msgFlags = m_errorMonitor->GetState(&msgString); |
Tobin Ehlis | 40e9f52 | 2015-06-25 11:58:41 -0600 | [diff] [blame] | 902 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an error from Not Binding a Raster State Object"; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 903 | if (!strstr(msgString.c_str(),"Raster object not bound to this command buffer")) { |
| 904 | FAIL() << "Error received was not 'Raster object not bound to this command buffer'"; |
| 905 | } |
| 906 | } |
| 907 | |
| 908 | TEST_F(VkLayerTest, ViewportStateNotBound) |
| 909 | { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 910 | VkFlags msgFlags; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 911 | std::string msgString; |
Tobin Ehlis | 254eca0 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 912 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 913 | m_errorMonitor->ClearState(); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 914 | TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand"); |
| 915 | |
| 916 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport); |
| 917 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 918 | msgFlags = m_errorMonitor->GetState(&msgString); |
Tobin Ehlis | 40e9f52 | 2015-06-25 11:58:41 -0600 | [diff] [blame] | 919 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an error from Not Binding a Viewport State Object"; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 920 | if (!strstr(msgString.c_str(),"Viewport object not bound to this command buffer")) { |
| 921 | FAIL() << "Error received was not 'Viewport object not bound to this command buffer'"; |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | TEST_F(VkLayerTest, ColorBlendStateNotBound) |
| 926 | { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 927 | VkFlags msgFlags; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 928 | std::string msgString; |
Tobin Ehlis | 254eca0 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 929 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 930 | m_errorMonitor->ClearState(); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 931 | TEST_DESCRIPTION("Simple Draw Call that validates failure when a color-blend state object is not bound beforehand"); |
| 932 | |
| 933 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailColorBlend); |
| 934 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 935 | msgFlags = m_errorMonitor->GetState(&msgString); |
Tobin Ehlis | 40e9f52 | 2015-06-25 11:58:41 -0600 | [diff] [blame] | 936 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an error from Not Binding a ColorBlend State Object"; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 937 | if (!strstr(msgString.c_str(),"Color-blend object not bound to this command buffer")) { |
| 938 | FAIL() << "Error received was not 'Color-blend object not bound to this command buffer'"; |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | TEST_F(VkLayerTest, DepthStencilStateNotBound) |
| 943 | { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 944 | VkFlags msgFlags; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 945 | std::string msgString; |
Tobin Ehlis | 254eca0 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 946 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 947 | m_errorMonitor->ClearState(); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 948 | TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth-stencil state object is not bound beforehand"); |
| 949 | |
| 950 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthStencil); |
| 951 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 952 | msgFlags = m_errorMonitor->GetState(&msgString); |
Tobin Ehlis | 40e9f52 | 2015-06-25 11:58:41 -0600 | [diff] [blame] | 953 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an error from Not Binding a DepthStencil State Object"; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 954 | if (!strstr(msgString.c_str(),"Depth-stencil object not bound to this command buffer")) { |
| 955 | FAIL() << "Error received was not 'Depth-stencil object not bound to this command buffer'"; |
| 956 | } |
Tony Barbour | db68662 | 2015-05-06 09:35:56 -0600 | [diff] [blame] | 957 | } |
Tobin Ehlis | 57e6a61 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 958 | #endif |
| 959 | #if DRAW_STATE_TESTS |
Tobin Ehlis | e407678 | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 960 | TEST_F(VkLayerTest, BindPipelineNoRenderPass) |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 961 | { |
| 962 | // Initiate Draw w/o a PSO bound |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 963 | VkFlags msgFlags; |
Tobin Ehlis | 6bdfa37 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 964 | std::string msgString; |
| 965 | |
| 966 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 967 | m_errorMonitor->ClearState(); |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 968 | BeginCommandBuffer(); |
Tobin Ehlis | 6bdfa37 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 969 | VkPipeline badPipeline = (VkPipeline)0xbaadb1be; |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 970 | vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 971 | msgFlags = m_errorMonitor->GetState(&msgString); |
Tobin Ehlis | e407678 | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 972 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding pipeline to CmdBuffer w/o active RenderPass"; |
| 973 | if (!strstr(msgString.c_str(),"Incorrectly binding graphics pipeline ")) { |
| 974 | FAIL() << "Error received was not 'Incorrectly binding graphics pipeline (0xbaadb1be) without an active RenderPass'"; |
Tobin Ehlis | 6bdfa37 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 975 | } |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | TEST_F(VkLayerTest, InvalidDescriptorPool) |
| 979 | { |
| 980 | // TODO : Simple check for bad object should be added to ObjectTracker to catch this case |
| 981 | // The DS check for this is after driver has been called to validate DS internal data struct |
| 982 | // Attempt to clear DS Pool with bad object |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 983 | /* VkFlags msgFlags; |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 984 | std::string msgString; |
| 985 | VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001; |
| 986 | vkResetDescriptorPool(device(), badPool); |
| 987 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 988 | msgFlags = m_errorMonitor->GetState(&msgString); |
Tobin Ehlis | 40e9f52 | 2015-06-25 11:58:41 -0600 | [diff] [blame] | 989 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an error from Resetting an invalid DescriptorPool Object"; |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 990 | if (!strstr(msgString.c_str(),"Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call")) { |
| 991 | FAIL() << "Error received was note 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'"; |
| 992 | }*/ |
| 993 | } |
| 994 | |
| 995 | TEST_F(VkLayerTest, InvalidDescriptorSet) |
| 996 | { |
Tobin Ehlis | 6bdfa37 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 997 | // TODO : Simple check for bad object should be added to ObjectTracker to catch this case |
| 998 | // The DS check for this is after driver has been called to validate DS internal data struct |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 999 | // Create a valid cmd buffer |
| 1000 | // call vkCmdBindDescriptorSets w/ false DS |
| 1001 | } |
| 1002 | |
| 1003 | TEST_F(VkLayerTest, InvalidDescriptorSetLayout) |
| 1004 | { |
| 1005 | // TODO : Simple check for bad object should be added to ObjectTracker to catch this case |
| 1006 | // The DS check for this is after driver has been called to validate DS internal data struct |
| 1007 | } |
| 1008 | |
| 1009 | TEST_F(VkLayerTest, InvalidPipeline) |
| 1010 | { |
Tobin Ehlis | 6bdfa37 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 1011 | // TODO : Simple check for bad object should be added to ObjectTracker to catch this case |
| 1012 | // The DS check for this is after driver has been called to validate DS internal data struct |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 1013 | // Create a valid cmd buffer |
| 1014 | // call vkCmdBindPipeline w/ false Pipeline |
Tobin Ehlis | e407678 | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 1015 | // VkFlags msgFlags; |
| 1016 | // std::string msgString; |
| 1017 | // |
| 1018 | // ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1019 | // m_errorMonitor->ClearState(); |
| 1020 | // VkCommandBufferObj cmdBuffer(m_device); |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1021 | // BeginCommandBuffer(); |
Tobin Ehlis | e407678 | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 1022 | // VkPipeline badPipeline = (VkPipeline)0xbaadb1be; |
| 1023 | // vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline); |
| 1024 | // msgFlags = m_errorMonitor->GetState(&msgString); |
| 1025 | // ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding invalid pipeline to CmdBuffer"; |
| 1026 | // if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) { |
| 1027 | // FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'"; |
| 1028 | // } |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 1029 | } |
| 1030 | |
Tobin Ehlis | 254eca0 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 1031 | TEST_F(VkLayerTest, DescriptorSetNotUpdated) |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 1032 | { |
Tobin Ehlis | 6bdfa37 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 1033 | // Create and update CmdBuffer then call QueueSubmit w/o calling End on CmdBuffer |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1034 | VkFlags msgFlags; |
Tobin Ehlis | 6bdfa37 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 1035 | std::string msgString; |
| 1036 | VkResult err; |
| 1037 | |
| 1038 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1039 | m_errorMonitor->ClearState(); |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1040 | VkDescriptorTypeCount ds_type_count = {}; |
| 1041 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 1042 | ds_type_count.count = 1; |
| 1043 | |
| 1044 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 1045 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 1046 | ds_pool_ci.pNext = NULL; |
| 1047 | ds_pool_ci.count = 1; |
| 1048 | ds_pool_ci.pTypeCount = &ds_type_count; |
| 1049 | |
Tobin Ehlis | 6bdfa37 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 1050 | VkDescriptorPool ds_pool; |
| 1051 | err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool); |
| 1052 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 6bdfa37 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 1053 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1054 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 1055 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 1056 | dsl_binding.arraySize = 1; |
| 1057 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 1058 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 6bdfa37 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 1059 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1060 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 1061 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 1062 | ds_layout_ci.pNext = NULL; |
| 1063 | ds_layout_ci.count = 1; |
| 1064 | ds_layout_ci.pBinding = &dsl_binding; |
Tobin Ehlis | 6bdfa37 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 1065 | VkDescriptorSetLayout ds_layout; |
| 1066 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout); |
| 1067 | ASSERT_VK_SUCCESS(err); |
| 1068 | |
| 1069 | VkDescriptorSet descriptorSet; |
Cody Northrop | c8aa4a5 | 2015-08-03 12:47:29 -0600 | [diff] [blame] | 1070 | err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet); |
Tobin Ehlis | 6bdfa37 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 1071 | ASSERT_VK_SUCCESS(err); |
| 1072 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1073 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 1074 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 1075 | pipeline_layout_ci.pNext = NULL; |
| 1076 | pipeline_layout_ci.descriptorSetCount = 1; |
| 1077 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 6bdfa37 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 1078 | |
| 1079 | VkPipelineLayout pipeline_layout; |
| 1080 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout); |
| 1081 | ASSERT_VK_SUCCESS(err); |
| 1082 | |
Courtney Goeltzenleuchter | 2d034fd | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 1083 | VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this); |
Tobin Ehlis | 6bdfa37 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 1084 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1085 | VkPipelineShaderStageCreateInfo pipe_vs_ci = {}; |
| 1086 | pipe_vs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 1087 | pipe_vs_ci.pNext = NULL; |
| 1088 | pipe_vs_ci.stage = VK_SHADER_STAGE_VERTEX; |
| 1089 | pipe_vs_ci.shader = vs.handle(); |
| 1090 | pipe_vs_ci.pSpecializationInfo = NULL; |
| 1091 | |
| 1092 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 1093 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 1094 | gp_ci.pNext = NULL; |
| 1095 | gp_ci.stageCount = 1; |
| 1096 | gp_ci.pStages = &pipe_vs_ci; |
| 1097 | gp_ci.pVertexInputState = NULL; |
| 1098 | gp_ci.pInputAssemblyState = NULL; |
| 1099 | gp_ci.pTessellationState = NULL; |
| 1100 | gp_ci.pViewportState = NULL; |
| 1101 | gp_ci.pRasterState = NULL; |
| 1102 | gp_ci.pMultisampleState = NULL; |
| 1103 | gp_ci.pDepthStencilState = NULL; |
| 1104 | gp_ci.pColorBlendState = NULL; |
| 1105 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 1106 | gp_ci.layout = pipeline_layout; |
| 1107 | |
| 1108 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 1109 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 1110 | pc_ci.pNext = NULL; |
| 1111 | pc_ci.initialSize = 0; |
| 1112 | pc_ci.initialData = 0; |
| 1113 | pc_ci.maxSize = 0; |
Tobin Ehlis | 6bdfa37 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 1114 | |
| 1115 | VkPipeline pipeline; |
Jon Ashburn | 0d60d27 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 1116 | VkPipelineCache pipelineCache; |
| 1117 | |
| 1118 | err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache); |
| 1119 | ASSERT_VK_SUCCESS(err); |
| 1120 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline); |
Tobin Ehlis | 6bdfa37 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 1121 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 254eca0 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 1122 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1123 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1124 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1125 | |
| 1126 | BeginCommandBuffer(); |
| 1127 | vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 1128 | vkCmdBindDescriptorSets(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL); |
Tobin Ehlis | 6bdfa37 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 1129 | |
Tobin Ehlis | 254eca0 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 1130 | msgFlags = m_errorMonitor->GetState(&msgString); |
| 1131 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT) << "Did not warn after binding a DescriptorSet that was never updated."; |
| 1132 | if (!strstr(msgString.c_str()," bound but it was never updated. ")) { |
| 1133 | FAIL() << "Error received was not 'DS <blah> bound but it was never updated. You may want to either update it or not bind it.'"; |
| 1134 | } |
| 1135 | } |
| 1136 | |
| 1137 | TEST_F(VkLayerTest, NoBeginCmdBuffer) |
| 1138 | { |
| 1139 | VkFlags msgFlags; |
| 1140 | std::string msgString; |
| 1141 | |
| 1142 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1143 | m_errorMonitor->ClearState(); |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1144 | VkCommandBufferObj cmdBuffer(m_device, m_cmdPool); |
Tobin Ehlis | 254eca0 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 1145 | // Call EndCommandBuffer() w/o calling BeginCommandBuffer() |
| 1146 | vkEndCommandBuffer(cmdBuffer.GetBufferHandle()); |
| 1147 | msgFlags = m_errorMonitor->GetState(&msgString); |
| 1148 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after ending a CmdBuffer w/o calling BeginCommandBuffer()"; |
| 1149 | if (!strstr(msgString.c_str(),"You must call vkBeginCommandBuffer() before this call to ")) { |
| 1150 | FAIL() << "Error received was not 'You must call vkBeginCommandBuffer() before this call to vkEndCommandBuffer()'"; |
| 1151 | } |
| 1152 | } |
| 1153 | |
Mark Lobodzinski | 90bf5b0 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 1154 | TEST_F(VkLayerTest, PrimaryCmdBufferFramebufferAndRenderpass) |
| 1155 | { |
| 1156 | VkFlags msgFlags; |
| 1157 | std::string msgString; |
| 1158 | |
| 1159 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1160 | m_errorMonitor->ClearState(); |
| 1161 | |
| 1162 | // Calls CreateCommandBuffer |
| 1163 | VkCommandBufferObj cmdBuffer(m_device, m_cmdPool); |
| 1164 | |
| 1165 | // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data |
Cody Northrop | 10d8f98 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 1166 | VkCmdBufferBeginInfo cmd_buf_info = {}; |
| 1167 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO; |
| 1168 | cmd_buf_info.pNext = NULL; |
| 1169 | cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT | |
| 1170 | VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT; |
| 1171 | cmd_buf_info.renderPass = (VkRenderPass)0xcadecade; |
| 1172 | cmd_buf_info.framebuffer = (VkFramebuffer)0xcadecade; |
| 1173 | |
Mark Lobodzinski | 90bf5b0 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 1174 | |
| 1175 | // The error should be caught by validation of the BeginCommandBuffer call |
| 1176 | vkBeginCommandBuffer(cmdBuffer.GetBufferHandle(), &cmd_buf_info); |
| 1177 | |
| 1178 | msgFlags = m_errorMonitor->GetState(&msgString); |
| 1179 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error passing a non-NULL Framebuffer and Renderpass to BeginCommandBuffer()"; |
| 1180 | if (!strstr(msgString.c_str(),"may not specify framebuffer or renderpass parameters")) { |
| 1181 | FAIL() << "Error received was not 'vkCreateCommandBuffer(): Primary Command Buffer may not specify framebuffer or renderpass parameters'"; |
| 1182 | } |
| 1183 | } |
| 1184 | |
| 1185 | TEST_F(VkLayerTest, SecondaryCmdBufferFramebufferAndRenderpass) |
| 1186 | { |
| 1187 | VkFlags msgFlags; |
| 1188 | std::string msgString; |
| 1189 | VkResult err; |
| 1190 | VkCmdBuffer draw_cmd; |
| 1191 | VkCmdPool cmd_pool; |
| 1192 | |
| 1193 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1194 | m_errorMonitor->ClearState(); |
| 1195 | |
Cody Northrop | 10d8f98 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 1196 | VkCmdBufferCreateInfo cmd = {}; |
| 1197 | cmd.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO; |
| 1198 | cmd.pNext = NULL; |
| 1199 | cmd.cmdPool = m_cmdPool; |
| 1200 | cmd.level = VK_CMD_BUFFER_LEVEL_SECONDARY; |
| 1201 | cmd.flags = 0; |
| 1202 | |
Mark Lobodzinski | 90bf5b0 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 1203 | err = vkCreateCommandBuffer(m_device->device(), &cmd, &draw_cmd); |
| 1204 | assert(!err); |
| 1205 | |
| 1206 | // Force the failure by not setting the Renderpass and Framebuffer fields |
Cody Northrop | 10d8f98 | 2015-08-04 17:35:57 -0600 | [diff] [blame] | 1207 | VkCmdBufferBeginInfo cmd_buf_info = {}; |
| 1208 | cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO; |
| 1209 | cmd_buf_info.pNext = NULL; |
| 1210 | cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT | |
| 1211 | VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT; |
Mark Lobodzinski | 90bf5b0 | 2015-08-04 16:24:20 -0600 | [diff] [blame] | 1212 | |
| 1213 | // The error should be caught by validation of the BeginCommandBuffer call |
| 1214 | vkBeginCommandBuffer(draw_cmd, &cmd_buf_info); |
| 1215 | |
| 1216 | msgFlags = m_errorMonitor->GetState(&msgString); |
| 1217 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error passing NULL Framebuffer/Renderpass to BeginCommandBuffer()"; |
| 1218 | if (!strstr(msgString.c_str(),"must specify framebuffer and renderpass parameters")) { |
| 1219 | FAIL() << "Error received was not 'vkCreateCommandBuffer(): Secondary Command Buffer must specify framebuffer and renderpass parameters'"; |
| 1220 | } |
| 1221 | } |
| 1222 | |
Tobin Ehlis | 254eca0 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 1223 | TEST_F(VkLayerTest, InvalidPipelineCreateState) |
| 1224 | { |
| 1225 | // Attempt to Create Gfx Pipeline w/o a VS |
| 1226 | VkFlags msgFlags; |
| 1227 | std::string msgString; |
| 1228 | VkResult err; |
| 1229 | |
| 1230 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1231 | m_errorMonitor->ClearState(); |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1232 | |
| 1233 | VkDescriptorTypeCount ds_type_count = {}; |
| 1234 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 1235 | ds_type_count.count = 1; |
| 1236 | |
| 1237 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 1238 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 1239 | ds_pool_ci.pNext = NULL; |
| 1240 | ds_pool_ci.count = 1; |
| 1241 | ds_pool_ci.pTypeCount = &ds_type_count; |
| 1242 | |
Tobin Ehlis | 254eca0 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 1243 | VkDescriptorPool ds_pool; |
| 1244 | err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool); |
| 1245 | ASSERT_VK_SUCCESS(err); |
| 1246 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1247 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 1248 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 1249 | dsl_binding.arraySize = 1; |
| 1250 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 1251 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 254eca0 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 1252 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1253 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 1254 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 1255 | ds_layout_ci.pNext = NULL; |
| 1256 | ds_layout_ci.count = 1; |
| 1257 | ds_layout_ci.pBinding = &dsl_binding; |
| 1258 | |
Tobin Ehlis | 254eca0 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 1259 | VkDescriptorSetLayout ds_layout; |
| 1260 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout); |
| 1261 | ASSERT_VK_SUCCESS(err); |
| 1262 | |
| 1263 | VkDescriptorSet descriptorSet; |
Cody Northrop | c8aa4a5 | 2015-08-03 12:47:29 -0600 | [diff] [blame] | 1264 | err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet); |
Tobin Ehlis | 254eca0 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 1265 | ASSERT_VK_SUCCESS(err); |
| 1266 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1267 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 1268 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 1269 | pipeline_layout_ci.pNext = NULL; |
| 1270 | pipeline_layout_ci.descriptorSetCount = 1; |
| 1271 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 254eca0 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 1272 | |
| 1273 | VkPipelineLayout pipeline_layout; |
| 1274 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout); |
| 1275 | ASSERT_VK_SUCCESS(err); |
| 1276 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1277 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 1278 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 1279 | gp_ci.pNext = NULL; |
| 1280 | gp_ci.stageCount = 0; |
| 1281 | gp_ci.pStages = NULL; |
| 1282 | gp_ci.pVertexInputState = NULL; |
| 1283 | gp_ci.pInputAssemblyState = NULL; |
| 1284 | gp_ci.pTessellationState = NULL; |
| 1285 | gp_ci.pViewportState = NULL; |
| 1286 | gp_ci.pRasterState = NULL; |
| 1287 | gp_ci.pMultisampleState = NULL; |
| 1288 | gp_ci.pDepthStencilState = NULL; |
| 1289 | gp_ci.pColorBlendState = NULL; |
| 1290 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 1291 | gp_ci.layout = pipeline_layout; |
| 1292 | |
| 1293 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 1294 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 1295 | pc_ci.pNext = NULL; |
| 1296 | pc_ci.initialSize = 0; |
| 1297 | pc_ci.initialData = 0; |
| 1298 | pc_ci.maxSize = 0; |
Tobin Ehlis | 254eca0 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 1299 | |
| 1300 | VkPipeline pipeline; |
Jon Ashburn | 0d60d27 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 1301 | VkPipelineCache pipelineCache; |
| 1302 | |
| 1303 | err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache); |
| 1304 | ASSERT_VK_SUCCESS(err); |
| 1305 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline); |
Tobin Ehlis | 6bdfa37 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 1306 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1307 | msgFlags = m_errorMonitor->GetState(&msgString); |
Tobin Ehlis | 254eca0 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 1308 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after creating Gfx Pipeline w/o VS."; |
| 1309 | if (!strstr(msgString.c_str(),"Invalid Pipeline CreateInfo State: Vtx Shader required")) { |
| 1310 | FAIL() << "Error received was not 'Invalid Pipeline CreateInfo State: Vtx Shader required'"; |
| 1311 | } |
| 1312 | } |
| 1313 | |
Tobin Ehlis | b8b06b5 | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 1314 | TEST_F(VkLayerTest, NullRenderPass) |
| 1315 | { |
| 1316 | // Bind a NULL RenderPass |
| 1317 | VkFlags msgFlags; |
| 1318 | std::string msgString; |
| 1319 | |
| 1320 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1321 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 1322 | m_errorMonitor->ClearState(); |
Tobin Ehlis | b8b06b5 | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 1323 | |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1324 | BeginCommandBuffer(); |
Tobin Ehlis | b8b06b5 | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 1325 | // Don't care about RenderPass handle b/c error should be flagged before that |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1326 | vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), NULL, VK_RENDER_PASS_CONTENTS_INLINE); |
Tobin Ehlis | b8b06b5 | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 1327 | |
| 1328 | msgFlags = m_errorMonitor->GetState(&msgString); |
| 1329 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding NULL RenderPass."; |
| 1330 | if (!strstr(msgString.c_str(),"You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()")) { |
| 1331 | FAIL() << "Error received was not 'You cannot use a NULL RenderPass object in vkCmdBeginRenderPass()'"; |
| 1332 | } |
| 1333 | } |
| 1334 | |
Tobin Ehlis | 254eca0 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 1335 | TEST_F(VkLayerTest, RenderPassWithinRenderPass) |
| 1336 | { |
| 1337 | // Bind a BeginRenderPass within an active RenderPass |
| 1338 | VkFlags msgFlags; |
| 1339 | std::string msgString; |
| 1340 | |
| 1341 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1342 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 1343 | m_errorMonitor->ClearState(); |
Tobin Ehlis | 254eca0 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 1344 | |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1345 | BeginCommandBuffer(); |
Tobin Ehlis | b8b06b5 | 2015-06-25 16:27:19 -0600 | [diff] [blame] | 1346 | // Just create a dummy Renderpass that's non-NULL so we can get to the proper error |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1347 | VkRenderPassBeginInfo rp_begin = {}; |
| 1348 | rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; |
| 1349 | rp_begin.pNext = NULL; |
| 1350 | rp_begin.renderPass = (VkRenderPass)0xc001d00d; |
| 1351 | rp_begin.framebuffer = 0; |
| 1352 | |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1353 | vkCmdBeginRenderPass(m_cmdBuffer->GetBufferHandle(), &rp_begin, VK_RENDER_PASS_CONTENTS_INLINE); |
Tobin Ehlis | 254eca0 | 2015-06-25 15:46:59 -0600 | [diff] [blame] | 1354 | |
| 1355 | msgFlags = m_errorMonitor->GetState(&msgString); |
| 1356 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding RenderPass w/i an active RenderPass."; |
| 1357 | if (!strstr(msgString.c_str(),"Cannot call vkCmdBeginRenderPass() during an active RenderPass ")) { |
| 1358 | FAIL() << "Error received was not 'Cannot call vkCmdBeginRenderPass() during an active RenderPass...'"; |
Tobin Ehlis | 6bdfa37 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 1359 | } |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 1360 | } |
| 1361 | |
| 1362 | TEST_F(VkLayerTest, InvalidDynamicStateObject) |
| 1363 | { |
| 1364 | // Create a valid cmd buffer |
| 1365 | // call vkCmdBindDynamicStateObject w/ false DS Obj |
Tobin Ehlis | 6bdfa37 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 1366 | // TODO : Simple check for bad object should be added to ObjectTracker to catch this case |
| 1367 | // The DS check for this is after driver has been called to validate DS internal data struct |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 1368 | } |
Tobin Ehlis | 201b1ba | 2015-05-27 14:55:35 -0600 | [diff] [blame] | 1369 | |
Tobin Ehlis | e407678 | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 1370 | TEST_F(VkLayerTest, VtxBufferNoRenderPass) |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 1371 | { |
| 1372 | // Bind VBO out-of-bounds for given PSO |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1373 | VkFlags msgFlags; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1374 | std::string msgString; |
| 1375 | VkResult err; |
| 1376 | |
| 1377 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1378 | m_errorMonitor->ClearState(); |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1379 | |
| 1380 | VkDescriptorTypeCount ds_type_count = {}; |
| 1381 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 1382 | ds_type_count.count = 1; |
| 1383 | |
| 1384 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 1385 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 1386 | ds_pool_ci.pNext = NULL; |
| 1387 | ds_pool_ci.count = 1; |
| 1388 | ds_pool_ci.pTypeCount = &ds_type_count; |
| 1389 | |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1390 | VkDescriptorPool ds_pool; |
| 1391 | err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool); |
| 1392 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1393 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1394 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 1395 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 1396 | dsl_binding.arraySize = 1; |
| 1397 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 1398 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1399 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1400 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 1401 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 1402 | ds_layout_ci.pNext = NULL; |
| 1403 | ds_layout_ci.count = 1; |
| 1404 | ds_layout_ci.pBinding = &dsl_binding; |
| 1405 | |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1406 | VkDescriptorSetLayout ds_layout; |
| 1407 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout); |
| 1408 | ASSERT_VK_SUCCESS(err); |
| 1409 | |
| 1410 | VkDescriptorSet descriptorSet; |
Cody Northrop | c8aa4a5 | 2015-08-03 12:47:29 -0600 | [diff] [blame] | 1411 | err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet); |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1412 | ASSERT_VK_SUCCESS(err); |
| 1413 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1414 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 1415 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 1416 | pipeline_layout_ci.pNext = NULL; |
| 1417 | pipeline_layout_ci.descriptorSetCount = 1; |
| 1418 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1419 | |
| 1420 | VkPipelineLayout pipeline_layout; |
| 1421 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout); |
| 1422 | ASSERT_VK_SUCCESS(err); |
| 1423 | |
Courtney Goeltzenleuchter | 2d034fd | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 1424 | VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this); |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1425 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1426 | VkPipelineShaderStageCreateInfo pipe_vs_ci = {}; |
| 1427 | pipe_vs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 1428 | pipe_vs_ci.pNext = NULL; |
| 1429 | pipe_vs_ci.stage = VK_SHADER_STAGE_VERTEX; |
| 1430 | pipe_vs_ci.shader = vs.handle(); |
| 1431 | pipe_vs_ci.pSpecializationInfo = NULL; |
| 1432 | |
| 1433 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 1434 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 1435 | gp_ci.pNext = NULL; |
| 1436 | gp_ci.stageCount = 1; |
| 1437 | gp_ci.pStages = &pipe_vs_ci; |
| 1438 | gp_ci.pVertexInputState = NULL; |
| 1439 | gp_ci.pInputAssemblyState = NULL; |
| 1440 | gp_ci.pTessellationState = NULL; |
| 1441 | gp_ci.pViewportState = NULL; |
| 1442 | gp_ci.pRasterState = NULL; |
| 1443 | gp_ci.pMultisampleState = NULL; |
| 1444 | gp_ci.pDepthStencilState = NULL; |
| 1445 | gp_ci.pColorBlendState = NULL; |
| 1446 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 1447 | gp_ci.layout = pipeline_layout; |
| 1448 | |
| 1449 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 1450 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 1451 | pc_ci.pNext = NULL; |
| 1452 | pc_ci.initialSize = 0; |
| 1453 | pc_ci.initialData = 0; |
| 1454 | pc_ci.maxSize = 0; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1455 | |
| 1456 | VkPipeline pipeline; |
Jon Ashburn | 0d60d27 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 1457 | VkPipelineCache pipelineCache; |
| 1458 | |
| 1459 | err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache); |
| 1460 | ASSERT_VK_SUCCESS(err); |
| 1461 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline); |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1462 | ASSERT_VK_SUCCESS(err); |
| 1463 | |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1464 | BeginCommandBuffer(); |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1465 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1466 | vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1467 | // Should error before calling to driver so don't care about actual data |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1468 | vkCmdBindVertexBuffers(m_cmdBuffer->GetBufferHandle(), 0, 1, NULL, NULL); |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1469 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1470 | msgFlags = m_errorMonitor->GetState(&msgString); |
Tobin Ehlis | e407678 | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 1471 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after vkCmdBindVertexBuffers() w/o active RenderPass."; |
| 1472 | if (!strstr(msgString.c_str(),"Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.")) { |
| 1473 | FAIL() << "Error received was not 'Incorrect call to vkCmdBindVertexBuffers() without an active RenderPass.'"; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1474 | } |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 1475 | } |
| 1476 | |
| 1477 | TEST_F(VkLayerTest, DSTypeMismatch) |
| 1478 | { |
| 1479 | // Create DS w/ layout of one type and attempt Update w/ mis-matched type |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1480 | VkFlags msgFlags; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1481 | std::string msgString; |
| 1482 | VkResult err; |
| 1483 | |
| 1484 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1485 | m_errorMonitor->ClearState(); |
| 1486 | //VkDescriptorSetObj descriptorSet(m_device); |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1487 | VkDescriptorTypeCount ds_type_count = {}; |
| 1488 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 1489 | ds_type_count.count = 1; |
| 1490 | |
| 1491 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 1492 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 1493 | ds_pool_ci.pNext = NULL; |
| 1494 | ds_pool_ci.count = 1; |
| 1495 | ds_pool_ci.pTypeCount = &ds_type_count; |
| 1496 | |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1497 | VkDescriptorPool ds_pool; |
| 1498 | err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool); |
| 1499 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1500 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 1501 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 1502 | dsl_binding.arraySize = 1; |
| 1503 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 1504 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1505 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1506 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 1507 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 1508 | ds_layout_ci.pNext = NULL; |
| 1509 | ds_layout_ci.count = 1; |
| 1510 | ds_layout_ci.pBinding = &dsl_binding; |
| 1511 | |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1512 | VkDescriptorSetLayout ds_layout; |
| 1513 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout); |
| 1514 | ASSERT_VK_SUCCESS(err); |
| 1515 | |
| 1516 | VkDescriptorSet descriptorSet; |
Cody Northrop | c8aa4a5 | 2015-08-03 12:47:29 -0600 | [diff] [blame] | 1517 | err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet); |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1518 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1519 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1520 | VkSamplerCreateInfo sampler_ci = {}; |
| 1521 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 1522 | sampler_ci.pNext = NULL; |
| 1523 | sampler_ci.magFilter = VK_TEX_FILTER_NEAREST; |
| 1524 | sampler_ci.minFilter = VK_TEX_FILTER_NEAREST; |
| 1525 | sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE; |
| 1526 | sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP; |
| 1527 | sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP; |
| 1528 | sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP; |
| 1529 | sampler_ci.mipLodBias = 1.0; |
| 1530 | sampler_ci.maxAnisotropy = 1; |
| 1531 | sampler_ci.compareEnable = VK_FALSE; |
| 1532 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 1533 | sampler_ci.minLod = 1.0; |
| 1534 | sampler_ci.maxLod = 1.0; |
| 1535 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 1536 | |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1537 | VkSampler sampler; |
| 1538 | err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler); |
| 1539 | ASSERT_VK_SUCCESS(err); |
| 1540 | |
Chia-I Wu | 8cd8ecd | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 1541 | VkDescriptorInfo descriptor_info; |
| 1542 | memset(&descriptor_info, 0, sizeof(descriptor_info)); |
| 1543 | descriptor_info.sampler = sampler; |
| 1544 | |
| 1545 | VkWriteDescriptorSet descriptor_write; |
| 1546 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 1547 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 1548 | descriptor_write.destSet = descriptorSet; |
| 1549 | descriptor_write.count = 1; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1550 | // This is a mismatched type for the layout which expects BUFFER |
Chia-I Wu | 8cd8ecd | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 1551 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 1552 | descriptor_write.pDescriptors = &descriptor_info; |
| 1553 | |
| 1554 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 1555 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1556 | msgFlags = m_errorMonitor->GetState(&msgString); |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1557 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after updating BUFFER Descriptor w/ incorrect type of SAMPLER."; |
Chia-I Wu | 8cd8ecd | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 1558 | if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET does not match ")) { |
| 1559 | FAIL() << "Error received was not 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET does not match overlapping binding type!'"; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1560 | } |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 1561 | } |
| 1562 | |
| 1563 | TEST_F(VkLayerTest, DSUpdateOutOfBounds) |
| 1564 | { |
| 1565 | // For overlapping Update, have arrayIndex exceed that of layout |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1566 | VkFlags msgFlags; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1567 | std::string msgString; |
| 1568 | VkResult err; |
| 1569 | |
| 1570 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1571 | m_errorMonitor->ClearState(); |
| 1572 | //VkDescriptorSetObj descriptorSet(m_device); |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1573 | VkDescriptorTypeCount ds_type_count = {}; |
| 1574 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 1575 | ds_type_count.count = 1; |
| 1576 | |
| 1577 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 1578 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 1579 | ds_pool_ci.pNext = NULL; |
| 1580 | ds_pool_ci.count = 1; |
| 1581 | ds_pool_ci.pTypeCount = &ds_type_count; |
| 1582 | |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1583 | VkDescriptorPool ds_pool; |
| 1584 | err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool); |
| 1585 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1586 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1587 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 1588 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 1589 | dsl_binding.arraySize = 1; |
| 1590 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 1591 | dsl_binding.pImmutableSamplers = NULL; |
| 1592 | |
| 1593 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 1594 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 1595 | ds_layout_ci.pNext = NULL; |
| 1596 | ds_layout_ci.count = 1; |
| 1597 | ds_layout_ci.pBinding = &dsl_binding; |
| 1598 | |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1599 | VkDescriptorSetLayout ds_layout; |
| 1600 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout); |
| 1601 | ASSERT_VK_SUCCESS(err); |
| 1602 | |
| 1603 | VkDescriptorSet descriptorSet; |
Cody Northrop | c8aa4a5 | 2015-08-03 12:47:29 -0600 | [diff] [blame] | 1604 | err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet); |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1605 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1606 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1607 | VkSamplerCreateInfo sampler_ci = {}; |
| 1608 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 1609 | sampler_ci.pNext = NULL; |
| 1610 | sampler_ci.magFilter = VK_TEX_FILTER_NEAREST; |
| 1611 | sampler_ci.minFilter = VK_TEX_FILTER_NEAREST; |
| 1612 | sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE; |
| 1613 | sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP; |
| 1614 | sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP; |
| 1615 | sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP; |
| 1616 | sampler_ci.mipLodBias = 1.0; |
| 1617 | sampler_ci.maxAnisotropy = 1; |
| 1618 | sampler_ci.compareEnable = VK_FALSE; |
| 1619 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 1620 | sampler_ci.minLod = 1.0; |
| 1621 | sampler_ci.maxLod = 1.0; |
| 1622 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 1623 | |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1624 | VkSampler sampler; |
| 1625 | err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler); |
| 1626 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 8cd8ecd | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 1627 | |
| 1628 | VkDescriptorInfo descriptor_info; |
| 1629 | memset(&descriptor_info, 0, sizeof(descriptor_info)); |
| 1630 | descriptor_info.sampler = sampler; |
| 1631 | |
| 1632 | VkWriteDescriptorSet descriptor_write; |
| 1633 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 1634 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 1635 | descriptor_write.destSet = descriptorSet; |
| 1636 | descriptor_write.destArrayElement = 1; /* This index out of bounds for the update */ |
| 1637 | descriptor_write.count = 1; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1638 | // This is the wrong type, but out of bounds will be flagged first |
Chia-I Wu | 8cd8ecd | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 1639 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 1640 | descriptor_write.pDescriptors = &descriptor_info; |
| 1641 | |
| 1642 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 1643 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1644 | msgFlags = m_errorMonitor->GetState(&msgString); |
| 1645 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after updating Descriptor w/ index out of bounds."; |
Chia-I Wu | 8cd8ecd | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 1646 | if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) { |
| 1647 | FAIL() << "Error received was not 'Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding...'"; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1648 | } |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 1649 | } |
| 1650 | |
| 1651 | TEST_F(VkLayerTest, InvalidDSUpdateIndex) |
| 1652 | { |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1653 | // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2 |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1654 | VkFlags msgFlags; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1655 | std::string msgString; |
| 1656 | VkResult err; |
| 1657 | |
| 1658 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1659 | m_errorMonitor->ClearState(); |
| 1660 | //VkDescriptorSetObj descriptorSet(m_device); |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1661 | VkDescriptorTypeCount ds_type_count = {}; |
| 1662 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 1663 | ds_type_count.count = 1; |
| 1664 | |
| 1665 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 1666 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 1667 | ds_pool_ci.pNext = NULL; |
| 1668 | ds_pool_ci.count = 1; |
| 1669 | ds_pool_ci.pTypeCount = &ds_type_count; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1670 | VkDescriptorPool ds_pool; |
| 1671 | err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool); |
| 1672 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1673 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1674 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 1675 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 1676 | dsl_binding.arraySize = 1; |
| 1677 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 1678 | dsl_binding.pImmutableSamplers = NULL; |
| 1679 | |
| 1680 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 1681 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 1682 | ds_layout_ci.pNext = NULL; |
| 1683 | ds_layout_ci.count = 1; |
| 1684 | ds_layout_ci.pBinding = &dsl_binding; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1685 | VkDescriptorSetLayout ds_layout; |
| 1686 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout); |
| 1687 | ASSERT_VK_SUCCESS(err); |
| 1688 | |
| 1689 | VkDescriptorSet descriptorSet; |
Cody Northrop | c8aa4a5 | 2015-08-03 12:47:29 -0600 | [diff] [blame] | 1690 | err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet); |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1691 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1692 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1693 | VkSamplerCreateInfo sampler_ci = {}; |
| 1694 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 1695 | sampler_ci.pNext = NULL; |
| 1696 | sampler_ci.magFilter = VK_TEX_FILTER_NEAREST; |
| 1697 | sampler_ci.minFilter = VK_TEX_FILTER_NEAREST; |
| 1698 | sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE; |
| 1699 | sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP; |
| 1700 | sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP; |
| 1701 | sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP; |
| 1702 | sampler_ci.mipLodBias = 1.0; |
| 1703 | sampler_ci.maxAnisotropy = 1; |
| 1704 | sampler_ci.compareEnable = VK_FALSE; |
| 1705 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 1706 | sampler_ci.minLod = 1.0; |
| 1707 | sampler_ci.maxLod = 1.0; |
| 1708 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
| 1709 | |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1710 | VkSampler sampler; |
| 1711 | err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler); |
| 1712 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 8cd8ecd | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 1713 | |
| 1714 | VkDescriptorInfo descriptor_info; |
| 1715 | memset(&descriptor_info, 0, sizeof(descriptor_info)); |
| 1716 | descriptor_info.sampler = sampler; |
| 1717 | |
| 1718 | VkWriteDescriptorSet descriptor_write; |
| 1719 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 1720 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 1721 | descriptor_write.destSet = descriptorSet; |
| 1722 | descriptor_write.destBinding = 2; |
| 1723 | descriptor_write.count = 1; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1724 | // This is the wrong type, but out of bounds will be flagged first |
Chia-I Wu | 8cd8ecd | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 1725 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 1726 | descriptor_write.pDescriptors = &descriptor_info; |
| 1727 | |
| 1728 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 1729 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1730 | msgFlags = m_errorMonitor->GetState(&msgString); |
| 1731 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after updating Descriptor w/ count too large for layout."; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1732 | if (!strstr(msgString.c_str()," does not have binding to match update binding ")) { |
| 1733 | FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '"; |
| 1734 | } |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 1735 | } |
| 1736 | |
| 1737 | TEST_F(VkLayerTest, InvalidDSUpdateStruct) |
| 1738 | { |
| 1739 | // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1740 | VkFlags msgFlags; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1741 | std::string msgString; |
| 1742 | VkResult err; |
| 1743 | |
| 1744 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1745 | m_errorMonitor->ClearState(); |
| 1746 | //VkDescriptorSetObj descriptorSet(m_device); |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1747 | |
| 1748 | VkDescriptorTypeCount ds_type_count = {}; |
| 1749 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 1750 | ds_type_count.count = 1; |
| 1751 | |
| 1752 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 1753 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 1754 | ds_pool_ci.pNext = NULL; |
| 1755 | ds_pool_ci.count = 1; |
| 1756 | ds_pool_ci.pTypeCount = &ds_type_count; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1757 | VkDescriptorPool ds_pool; |
| 1758 | err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool); |
| 1759 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1760 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 1761 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 1762 | dsl_binding.arraySize = 1; |
| 1763 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 1764 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1765 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1766 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 1767 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 1768 | ds_layout_ci.pNext = NULL; |
| 1769 | ds_layout_ci.count = 1; |
| 1770 | ds_layout_ci.pBinding = &dsl_binding; |
| 1771 | |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1772 | VkDescriptorSetLayout ds_layout; |
| 1773 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout); |
| 1774 | ASSERT_VK_SUCCESS(err); |
| 1775 | |
| 1776 | VkDescriptorSet descriptorSet; |
Cody Northrop | c8aa4a5 | 2015-08-03 12:47:29 -0600 | [diff] [blame] | 1777 | err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet); |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1778 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1779 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1780 | VkSamplerCreateInfo sampler_ci = {}; |
| 1781 | sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 1782 | sampler_ci.pNext = NULL; |
| 1783 | sampler_ci.magFilter = VK_TEX_FILTER_NEAREST; |
| 1784 | sampler_ci.minFilter = VK_TEX_FILTER_NEAREST; |
| 1785 | sampler_ci.mipMode = VK_TEX_MIPMAP_MODE_BASE; |
| 1786 | sampler_ci.addressU = VK_TEX_ADDRESS_CLAMP; |
| 1787 | sampler_ci.addressV = VK_TEX_ADDRESS_CLAMP; |
| 1788 | sampler_ci.addressW = VK_TEX_ADDRESS_CLAMP; |
| 1789 | sampler_ci.mipLodBias = 1.0; |
| 1790 | sampler_ci.maxAnisotropy = 1; |
| 1791 | sampler_ci.compareEnable = VK_FALSE; |
| 1792 | sampler_ci.compareOp = VK_COMPARE_OP_NEVER; |
| 1793 | sampler_ci.minLod = 1.0; |
| 1794 | sampler_ci.maxLod = 1.0; |
| 1795 | sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1796 | VkSampler sampler; |
| 1797 | err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler); |
| 1798 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 8cd8ecd | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 1799 | |
| 1800 | |
| 1801 | VkDescriptorInfo descriptor_info; |
| 1802 | memset(&descriptor_info, 0, sizeof(descriptor_info)); |
| 1803 | descriptor_info.sampler = sampler; |
| 1804 | |
| 1805 | VkWriteDescriptorSet descriptor_write; |
| 1806 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 1807 | descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */ |
| 1808 | descriptor_write.destSet = descriptorSet; |
| 1809 | descriptor_write.count = 1; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1810 | // This is the wrong type, but out of bounds will be flagged first |
Chia-I Wu | 8cd8ecd | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 1811 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 1812 | descriptor_write.pDescriptors = &descriptor_info; |
| 1813 | |
| 1814 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 1815 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1816 | msgFlags = m_errorMonitor->GetState(&msgString); |
| 1817 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after updating Descriptor w/ invalid struct type."; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1818 | if (!strstr(msgString.c_str(),"Unexpected UPDATE struct of type ")) { |
| 1819 | FAIL() << "Error received was not 'Unexpected UPDATE struct of type '"; |
| 1820 | } |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 1821 | } |
| 1822 | |
| 1823 | TEST_F(VkLayerTest, NumSamplesMismatch) |
| 1824 | { |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1825 | // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1826 | VkFlags msgFlags; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1827 | std::string msgString; |
| 1828 | VkResult err; |
| 1829 | |
| 1830 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1831 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 1832 | m_errorMonitor->ClearState(); |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1833 | VkDescriptorTypeCount ds_type_count = {}; |
| 1834 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 1835 | ds_type_count.count = 1; |
| 1836 | |
| 1837 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 1838 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 1839 | ds_pool_ci.pNext = NULL; |
| 1840 | ds_pool_ci.count = 1; |
| 1841 | ds_pool_ci.pTypeCount = &ds_type_count; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1842 | VkDescriptorPool ds_pool; |
| 1843 | err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool); |
| 1844 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1845 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1846 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 1847 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 1848 | dsl_binding.arraySize = 1; |
| 1849 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 1850 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1851 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1852 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 1853 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 1854 | ds_layout_ci.pNext = NULL; |
| 1855 | ds_layout_ci.count = 1; |
| 1856 | ds_layout_ci.pBinding = &dsl_binding; |
| 1857 | |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1858 | VkDescriptorSetLayout ds_layout; |
| 1859 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout); |
| 1860 | ASSERT_VK_SUCCESS(err); |
| 1861 | |
| 1862 | VkDescriptorSet descriptorSet; |
Cody Northrop | c8aa4a5 | 2015-08-03 12:47:29 -0600 | [diff] [blame] | 1863 | err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet); |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1864 | ASSERT_VK_SUCCESS(err); |
| 1865 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1866 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
| 1867 | pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 1868 | pipe_ms_state_ci.pNext = NULL; |
| 1869 | pipe_ms_state_ci.rasterSamples = 4; |
| 1870 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 1871 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 1872 | pipe_ms_state_ci.sampleMask = 15; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1873 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1874 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 1875 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 1876 | pipeline_layout_ci.pNext = NULL; |
| 1877 | pipeline_layout_ci.descriptorSetCount = 1; |
| 1878 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1879 | |
| 1880 | VkPipelineLayout pipeline_layout; |
| 1881 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout); |
| 1882 | ASSERT_VK_SUCCESS(err); |
| 1883 | |
Courtney Goeltzenleuchter | 2d034fd | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 1884 | VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this); |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1885 | VkPipelineShaderStageCreateInfo pipe_vs_ci = {}; |
| 1886 | pipe_vs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 1887 | pipe_vs_ci.pNext = NULL; |
| 1888 | pipe_vs_ci.stage = VK_SHADER_STAGE_VERTEX; |
| 1889 | pipe_vs_ci.shader = vs.handle(); |
| 1890 | pipe_vs_ci.pSpecializationInfo = NULL; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1891 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1892 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 1893 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 1894 | gp_ci.pNext = NULL; |
| 1895 | gp_ci.stageCount = 1; |
| 1896 | gp_ci.pStages = &pipe_vs_ci; |
| 1897 | gp_ci.pVertexInputState = NULL; |
| 1898 | gp_ci.pInputAssemblyState = NULL; |
| 1899 | gp_ci.pTessellationState = NULL; |
| 1900 | gp_ci.pViewportState = NULL; |
| 1901 | gp_ci.pRasterState = NULL; |
| 1902 | gp_ci.pMultisampleState = &pipe_ms_state_ci; |
| 1903 | gp_ci.pDepthStencilState = NULL; |
| 1904 | gp_ci.pColorBlendState = NULL; |
| 1905 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 1906 | gp_ci.layout = pipeline_layout; |
| 1907 | |
| 1908 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 1909 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 1910 | pc_ci.pNext = NULL; |
| 1911 | pc_ci.initialSize = 0; |
| 1912 | pc_ci.initialData = 0; |
| 1913 | pc_ci.maxSize = 0; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1914 | |
| 1915 | VkPipeline pipeline; |
Jon Ashburn | 0d60d27 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 1916 | VkPipelineCache pipelineCache; |
| 1917 | |
| 1918 | err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache); |
| 1919 | ASSERT_VK_SUCCESS(err); |
| 1920 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline); |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1921 | ASSERT_VK_SUCCESS(err); |
| 1922 | |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1923 | BeginCommandBuffer(); |
| 1924 | vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1925 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1926 | msgFlags = m_errorMonitor->GetState(&msgString); |
| 1927 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding RenderPass w/ mismatched MSAA from PSO."; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1928 | if (!strstr(msgString.c_str(),"Num samples mismatch! ")) { |
| 1929 | FAIL() << "Error received was not 'Num samples mismatch!...'"; |
| 1930 | } |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 1931 | } |
Tobin Ehlis | 8cd650e | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 1932 | |
Tobin Ehlis | e407678 | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 1933 | TEST_F(VkLayerTest, PipelineNotBound) |
| 1934 | { |
| 1935 | VkFlags msgFlags; |
| 1936 | std::string msgString; |
| 1937 | VkResult err; |
| 1938 | |
| 1939 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1940 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 1941 | m_errorMonitor->ClearState(); |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1942 | |
| 1943 | VkDescriptorTypeCount ds_type_count = {}; |
| 1944 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 1945 | ds_type_count.count = 1; |
| 1946 | |
| 1947 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 1948 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 1949 | ds_pool_ci.pNext = NULL; |
| 1950 | ds_pool_ci.count = 1; |
| 1951 | ds_pool_ci.pTypeCount = &ds_type_count; |
| 1952 | |
Tobin Ehlis | e407678 | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 1953 | VkDescriptorPool ds_pool; |
| 1954 | err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool); |
| 1955 | ASSERT_VK_SUCCESS(err); |
| 1956 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1957 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 1958 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 1959 | dsl_binding.arraySize = 1; |
| 1960 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 1961 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | e407678 | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 1962 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1963 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 1964 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 1965 | ds_layout_ci.pNext = NULL; |
| 1966 | ds_layout_ci.count = 1; |
| 1967 | ds_layout_ci.pBinding = &dsl_binding; |
| 1968 | |
Tobin Ehlis | e407678 | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 1969 | VkDescriptorSetLayout ds_layout; |
| 1970 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout); |
| 1971 | ASSERT_VK_SUCCESS(err); |
| 1972 | |
| 1973 | VkDescriptorSet descriptorSet; |
Cody Northrop | c8aa4a5 | 2015-08-03 12:47:29 -0600 | [diff] [blame] | 1974 | err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet); |
Tobin Ehlis | e407678 | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 1975 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 1976 | |
| 1977 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 1978 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 1979 | pipeline_layout_ci.pNext = NULL; |
| 1980 | pipeline_layout_ci.descriptorSetCount = 1; |
| 1981 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | e407678 | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 1982 | |
| 1983 | VkPipelineLayout pipeline_layout; |
| 1984 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout); |
| 1985 | ASSERT_VK_SUCCESS(err); |
| 1986 | |
Tobin Ehlis | e407678 | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 1987 | VkPipeline badPipeline = (VkPipeline)0xbaadb1be; |
| 1988 | //err = vkCreateGraphicsPipeline(m_device->device(), &gp_ci, &pipeline); |
| 1989 | ASSERT_VK_SUCCESS(err); |
| 1990 | |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 1991 | |
| 1992 | BeginCommandBuffer(); |
| 1993 | vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline); |
Tobin Ehlis | e407678 | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 1994 | |
| 1995 | msgFlags = m_errorMonitor->GetState(&msgString); |
| 1996 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding invalid pipeline to CmdBuffer"; |
| 1997 | if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) { |
| 1998 | FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'"; |
| 1999 | } |
| 2000 | } |
Tobin Ehlis | 8cd650e | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 2001 | |
| 2002 | TEST_F(VkLayerTest, ClearCmdNoDraw) |
| 2003 | { |
| 2004 | // Create CmdBuffer where we add ClearCmd for FB Color attachment prior to issuing a Draw |
| 2005 | VkFlags msgFlags; |
| 2006 | std::string msgString; |
| 2007 | VkResult err; |
| 2008 | |
| 2009 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2010 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 2011 | m_errorMonitor->ClearState(); |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2012 | |
| 2013 | VkDescriptorTypeCount ds_type_count = {}; |
| 2014 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 2015 | ds_type_count.count = 1; |
| 2016 | |
| 2017 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 2018 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 2019 | ds_pool_ci.pNext = NULL; |
| 2020 | ds_pool_ci.count = 1; |
| 2021 | ds_pool_ci.pTypeCount = &ds_type_count; |
| 2022 | |
Tobin Ehlis | 8cd650e | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 2023 | VkDescriptorPool ds_pool; |
| 2024 | err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool); |
| 2025 | ASSERT_VK_SUCCESS(err); |
| 2026 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2027 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 2028 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 2029 | dsl_binding.arraySize = 1; |
| 2030 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 2031 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | 8cd650e | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 2032 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2033 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 2034 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 2035 | ds_layout_ci.pNext = NULL; |
| 2036 | ds_layout_ci.count = 1; |
| 2037 | ds_layout_ci.pBinding = &dsl_binding; |
| 2038 | |
Tobin Ehlis | 8cd650e | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 2039 | VkDescriptorSetLayout ds_layout; |
| 2040 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout); |
| 2041 | ASSERT_VK_SUCCESS(err); |
| 2042 | |
| 2043 | VkDescriptorSet descriptorSet; |
Cody Northrop | c8aa4a5 | 2015-08-03 12:47:29 -0600 | [diff] [blame] | 2044 | err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet); |
Tobin Ehlis | 8cd650e | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 2045 | ASSERT_VK_SUCCESS(err); |
| 2046 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2047 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
| 2048 | pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 2049 | pipe_ms_state_ci.pNext = NULL; |
| 2050 | pipe_ms_state_ci.rasterSamples = 4; |
| 2051 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 2052 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 2053 | pipe_ms_state_ci.sampleMask = 15; |
Tobin Ehlis | 8cd650e | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 2054 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2055 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 2056 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 2057 | pipeline_layout_ci.pNext = NULL; |
| 2058 | pipeline_layout_ci.descriptorSetCount = 1; |
| 2059 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
Tobin Ehlis | 8cd650e | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 2060 | |
| 2061 | VkPipelineLayout pipeline_layout; |
| 2062 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout); |
| 2063 | ASSERT_VK_SUCCESS(err); |
| 2064 | |
| 2065 | size_t shader_len = strlen(bindStateVertShaderText); |
| 2066 | size_t codeSize = 3 * sizeof(uint32_t) + shader_len + 1; |
| 2067 | void* pCode = malloc(codeSize); |
| 2068 | |
| 2069 | /* try version 0 first: VkShaderStage followed by GLSL */ |
| 2070 | ((uint32_t *) pCode)[0] = ICD_SPV_MAGIC; |
| 2071 | ((uint32_t *) pCode)[1] = 0; |
| 2072 | ((uint32_t *) pCode)[2] = VK_SHADER_STAGE_VERTEX; |
| 2073 | memcpy(((uint32_t *) pCode + 3), bindStateVertShaderText, shader_len + 1); |
| 2074 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2075 | VkShaderModuleCreateInfo smci = {}; |
| 2076 | smci.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| 2077 | smci.pNext = NULL; |
| 2078 | smci.codeSize = codeSize; |
| 2079 | smci.pCode = pCode; |
| 2080 | smci.flags = 0; |
| 2081 | |
Tobin Ehlis | 8cd650e | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 2082 | VkShaderModule vksm; |
| 2083 | err = vkCreateShaderModule(m_device->device(), &smci, &vksm); |
| 2084 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2085 | VkShaderCreateInfo vs_ci = {}; |
| 2086 | vs_ci.sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO; |
| 2087 | vs_ci.pNext = NULL; |
| 2088 | vs_ci.module = vksm; |
| 2089 | vs_ci.pName = "main"; |
| 2090 | vs_ci.flags = 0; |
| 2091 | |
Tobin Ehlis | 8cd650e | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 2092 | VkShader vs; |
| 2093 | err = vkCreateShader(m_device->device(), &vs_ci, &vs); |
| 2094 | ASSERT_VK_SUCCESS(err); |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2095 | VkPipelineShaderStageCreateInfo pipe_vs_ci = {}; |
| 2096 | pipe_vs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 2097 | pipe_vs_ci.pNext = NULL; |
| 2098 | pipe_vs_ci.stage = VK_SHADER_STAGE_VERTEX; |
| 2099 | pipe_vs_ci.shader = vs; |
| 2100 | pipe_vs_ci.pSpecializationInfo = NULL; |
Tobin Ehlis | 8cd650e | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 2101 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2102 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 2103 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 2104 | gp_ci.pNext = NULL; |
| 2105 | gp_ci.stageCount = 1; |
| 2106 | gp_ci.pStages = &pipe_vs_ci; |
| 2107 | gp_ci.pVertexInputState = NULL; |
| 2108 | gp_ci.pInputAssemblyState = NULL; |
| 2109 | gp_ci.pTessellationState = NULL; |
| 2110 | gp_ci.pViewportState = NULL; |
| 2111 | gp_ci.pRasterState = NULL; |
| 2112 | gp_ci.pMultisampleState = &pipe_ms_state_ci; |
| 2113 | gp_ci.pDepthStencilState = NULL; |
| 2114 | gp_ci.pColorBlendState = NULL; |
| 2115 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 2116 | gp_ci.layout = pipeline_layout; |
| 2117 | |
| 2118 | VkPipelineCacheCreateInfo pc_ci = {}; |
| 2119 | pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 2120 | pc_ci.pNext = NULL; |
| 2121 | pc_ci.initialSize = 0; |
| 2122 | pc_ci.initialData = 0; |
| 2123 | pc_ci.maxSize = 0; |
Tobin Ehlis | 8cd650e | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 2124 | |
| 2125 | VkPipeline pipeline; |
Jon Ashburn | 0d60d27 | 2015-07-09 15:02:25 -0600 | [diff] [blame] | 2126 | VkPipelineCache pipelineCache; |
| 2127 | |
| 2128 | err = vkCreatePipelineCache(m_device->device(), &pc_ci, &pipelineCache); |
| 2129 | ASSERT_VK_SUCCESS(err); |
| 2130 | err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, &pipeline); |
Tobin Ehlis | 8cd650e | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 2131 | ASSERT_VK_SUCCESS(err); |
| 2132 | |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2133 | |
| 2134 | BeginCommandBuffer(); |
Tobin Ehlis | 8cd650e | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 2135 | |
| 2136 | m_errorMonitor->ClearState(); |
| 2137 | // Main thing we care about for this test is that the VkImage obj we're clearing matches Color Attachment of FB |
| 2138 | // Also pass down other dummy params to keep driver and paramchecker happy |
| 2139 | VkClearColorValue cCV; |
| 2140 | cCV.f32[0] = 1.0; |
| 2141 | cCV.f32[1] = 1.0; |
| 2142 | cCV.f32[2] = 1.0; |
| 2143 | cCV.f32[3] = 1.0; |
| 2144 | |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2145 | vkCmdClearColorAttachment(m_cmdBuffer->GetBufferHandle(), 0, (VkImageLayout)NULL, &cCV, 0, NULL); |
Tobin Ehlis | 8cd650e | 2015-07-01 16:46:13 -0600 | [diff] [blame] | 2146 | msgFlags = m_errorMonitor->GetState(&msgString); |
| 2147 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT) << "Did not receive error after issuing Clear Cmd on FB color attachment prior to Draw Cmd."; |
| 2148 | if (!strstr(msgString.c_str(),"vkCmdClearColorAttachment() issued on CB object ")) { |
| 2149 | FAIL() << "Error received was not 'vkCmdClearColorAttachment() issued on CB object...'"; |
| 2150 | } |
| 2151 | } |
| 2152 | |
Tobin Ehlis | e407678 | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 2153 | TEST_F(VkLayerTest, VtxBufferBadIndex) |
| 2154 | { |
| 2155 | // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount |
| 2156 | VkFlags msgFlags; |
| 2157 | std::string msgString; |
| 2158 | VkResult err; |
| 2159 | |
| 2160 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2161 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 2162 | m_errorMonitor->ClearState(); |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2163 | |
| 2164 | VkDescriptorTypeCount ds_type_count = {}; |
| 2165 | ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 2166 | ds_type_count.count = 1; |
| 2167 | |
| 2168 | VkDescriptorPoolCreateInfo ds_pool_ci = {}; |
| 2169 | ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 2170 | ds_pool_ci.pNext = NULL; |
| 2171 | ds_pool_ci.count = 1; |
| 2172 | ds_pool_ci.pTypeCount = &ds_type_count; |
| 2173 | |
| 2174 | VkDescriptorPool ds_pool; |
Tobin Ehlis | e407678 | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 2175 | err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool); |
| 2176 | ASSERT_VK_SUCCESS(err); |
| 2177 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2178 | VkDescriptorSetLayoutBinding dsl_binding = {}; |
| 2179 | dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 2180 | dsl_binding.arraySize = 1; |
| 2181 | dsl_binding.stageFlags = VK_SHADER_STAGE_ALL; |
| 2182 | dsl_binding.pImmutableSamplers = NULL; |
Tobin Ehlis | e407678 | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 2183 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2184 | VkDescriptorSetLayoutCreateInfo ds_layout_ci = {}; |
| 2185 | ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 2186 | ds_layout_ci.pNext = NULL; |
| 2187 | ds_layout_ci.count = 1; |
| 2188 | ds_layout_ci.pBinding = &dsl_binding; |
| 2189 | |
Tobin Ehlis | e407678 | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 2190 | VkDescriptorSetLayout ds_layout; |
| 2191 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout); |
| 2192 | ASSERT_VK_SUCCESS(err); |
| 2193 | |
| 2194 | VkDescriptorSet descriptorSet; |
Cody Northrop | c8aa4a5 | 2015-08-03 12:47:29 -0600 | [diff] [blame] | 2195 | err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet); |
Tobin Ehlis | e407678 | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 2196 | ASSERT_VK_SUCCESS(err); |
| 2197 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2198 | VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {}; |
| 2199 | pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; |
| 2200 | pipe_ms_state_ci.pNext = NULL; |
| 2201 | pipe_ms_state_ci.rasterSamples = 1; |
| 2202 | pipe_ms_state_ci.sampleShadingEnable = 0; |
| 2203 | pipe_ms_state_ci.minSampleShading = 1.0; |
| 2204 | pipe_ms_state_ci.sampleMask = 15; |
Tobin Ehlis | e407678 | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 2205 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2206 | VkPipelineLayoutCreateInfo pipeline_layout_ci = {}; |
| 2207 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 2208 | pipeline_layout_ci.pNext = NULL; |
| 2209 | pipeline_layout_ci.descriptorSetCount = 1; |
| 2210 | pipeline_layout_ci.pSetLayouts = &ds_layout; |
| 2211 | VkPipelineLayout pipeline_layout; |
Tobin Ehlis | e407678 | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 2212 | |
Tobin Ehlis | e407678 | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 2213 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout); |
| 2214 | ASSERT_VK_SUCCESS(err); |
| 2215 | |
Courtney Goeltzenleuchter | 2d034fd | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 2216 | VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX, this); |
Tobin Ehlis | e407678 | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 2217 | |
Tony Barbour | efbe9ca | 2015-07-15 12:50:33 -0600 | [diff] [blame] | 2218 | VkPipelineShaderStageCreateInfo pipe_vs_ci = {}; |
| 2219 | pipe_vs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 2220 | pipe_vs_ci.pNext = NULL; |
| 2221 | pipe_vs_ci.stage = VK_SHADER_STAGE_VERTEX; |
| 2222 | pipe_vs_ci.shader = vs.handle(); |
| 2223 | pipe_vs_ci.pSpecializationInfo = NULL; |
| 2224 | |
| 2225 | VkGraphicsPipelineCreateInfo gp_ci = {}; |
| 2226 | gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 2227 | gp_ci.pNext = NULL; |
| 2228 | gp_ci.stageCount = 1; |
| 2229 | gp_ci.pStages = &pipe_vs_ci; |
| 2230 | gp_ci.pVertexInputState = NULL; |
| 2231 | gp_ci.pInputAssemblyState = NULL; |
| 2232 | gp_ci.pTessellationState = NULL; |
| 2233 | gp_ci.pViewportState = NULL; |
| 2234 | gp_ci.pRasterState = NULL; |
| 2235 | gp_ci.pMultisampleState = &pipe_ms_state_ci; |
| 2236 | gp_ci.pDepthStencilState = NULL; |
| 2237 | gp_ci.pColorBlendState = NULL; |
| 2238 | gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT; |
| 2239 | gp_ci.layout = pipeline_layout; |
Tobin Ehlis | e407678 | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 2240 | |
Courtney Goeltzenleuchter | cdf5e83 | 2015-07-10 09:21:02 -0600 | [diff] [blame] | 2241 | VkPipelineCacheCreateInfo pipelineCache; |
| 2242 | VkPipelineCache pipeline_cache; |
| 2243 | |
| 2244 | memset(&pipelineCache, 0, sizeof(pipelineCache)); |
| 2245 | pipelineCache.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; |
| 2246 | err = vkCreatePipelineCache(m_device->device(), &pipelineCache, &pipeline_cache); |
| 2247 | |
Tobin Ehlis | e407678 | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 2248 | VkPipeline pipeline; |
Courtney Goeltzenleuchter | cdf5e83 | 2015-07-10 09:21:02 -0600 | [diff] [blame] | 2249 | err = vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &gp_ci, &pipeline); |
Tobin Ehlis | e407678 | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 2250 | ASSERT_VK_SUCCESS(err); |
| 2251 | |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2252 | |
| 2253 | BeginCommandBuffer(); |
| 2254 | vkCmdBindPipeline(m_cmdBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
Tobin Ehlis | e407678 | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 2255 | // Should error before calling to driver so don't care about actual data |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2256 | vkCmdBindVertexBuffers(m_cmdBuffer->GetBufferHandle(), 0, 1, NULL, NULL); |
Tobin Ehlis | e407678 | 2015-06-24 15:53:07 -0600 | [diff] [blame] | 2257 | |
| 2258 | msgFlags = m_errorMonitor->GetState(&msgString); |
| 2259 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive error after binding Vtx Buffer w/o VBO attached to PSO."; |
| 2260 | if (!strstr(msgString.c_str(),"Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.")) { |
| 2261 | FAIL() << "Error received was not 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'"; |
| 2262 | } |
| 2263 | } |
Tobin Ehlis | 57e6a61 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 2264 | #endif |
| 2265 | #if THREADING_TESTS |
Mike Stroyan | 09aae81 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 2266 | #if GTEST_IS_THREADSAFE |
| 2267 | struct thread_data_struct { |
| 2268 | VkCmdBuffer cmdBuffer; |
| 2269 | VkEvent event; |
| 2270 | bool bailout; |
| 2271 | }; |
| 2272 | |
| 2273 | extern "C" void *AddToCommandBuffer(void *arg) |
| 2274 | { |
| 2275 | struct thread_data_struct *data = (struct thread_data_struct *) arg; |
| 2276 | std::string msgString; |
| 2277 | |
| 2278 | for (int i = 0; i<10000; i++) { |
Tony Barbour | c2e987e | 2015-06-29 16:20:35 -0600 | [diff] [blame] | 2279 | vkCmdSetEvent(data->cmdBuffer, data->event, VK_PIPELINE_STAGE_ALL_GPU_COMMANDS); |
Mike Stroyan | 09aae81 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 2280 | if (data->bailout) { |
| 2281 | break; |
| 2282 | } |
| 2283 | } |
| 2284 | return NULL; |
| 2285 | } |
| 2286 | |
| 2287 | TEST_F(VkLayerTest, ThreadCmdBufferCollision) |
| 2288 | { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2289 | VkFlags msgFlags; |
Mike Stroyan | 09aae81 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 2290 | std::string msgString; |
Mike Stroyan | 7016f4f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 2291 | test_platform_thread thread; |
Mike Stroyan | 09aae81 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 2292 | |
| 2293 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2294 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 2295 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 2296 | |
Mike Stroyan | 09aae81 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 2297 | m_errorMonitor->ClearState(); |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2298 | BeginCommandBuffer(); |
Mike Stroyan | 09aae81 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 2299 | |
| 2300 | VkEventCreateInfo event_info; |
| 2301 | VkEvent event; |
Mike Stroyan | 09aae81 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 2302 | VkResult err; |
| 2303 | |
| 2304 | memset(&event_info, 0, sizeof(event_info)); |
| 2305 | event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 2306 | |
| 2307 | err = vkCreateEvent(device(), &event_info, &event); |
| 2308 | ASSERT_VK_SUCCESS(err); |
| 2309 | |
Mike Stroyan | 09aae81 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 2310 | err = vkResetEvent(device(), event); |
| 2311 | ASSERT_VK_SUCCESS(err); |
| 2312 | |
| 2313 | struct thread_data_struct data; |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2314 | data.cmdBuffer = m_cmdBuffer->handle(); |
Mike Stroyan | 09aae81 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 2315 | data.event = event; |
| 2316 | data.bailout = false; |
| 2317 | m_errorMonitor->SetBailout(&data.bailout); |
| 2318 | // Add many entries to command buffer from another thread. |
Mike Stroyan | 7016f4f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 2319 | test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data); |
Mike Stroyan | 09aae81 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 2320 | // Add many entries to command buffer from this thread at the same time. |
| 2321 | AddToCommandBuffer(&data); |
Mike Stroyan | 7016f4f | 2015-07-13 14:45:35 -0600 | [diff] [blame] | 2322 | test_platform_thread_join(thread, NULL); |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2323 | EndCommandBuffer(); |
Mike Stroyan | 09aae81 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 2324 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2325 | msgFlags = m_errorMonitor->GetState(&msgString); |
Mike Stroyan | ed25457 | 2015-06-17 16:32:06 -0600 | [diff] [blame] | 2326 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT) << "Did not receive an err from using one VkCommandBufferObj in two threads"; |
Mike Stroyan | 09aae81 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 2327 | if (!strstr(msgString.c_str(),"THREADING ERROR")) { |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 2328 | FAIL() << "Error received was not 'THREADING ERROR'"; |
Mike Stroyan | 09aae81 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 2329 | } |
| 2330 | |
| 2331 | } |
| 2332 | #endif |
Tobin Ehlis | 57e6a61 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 2333 | #endif |
Chris Forbes | 5af3bf2 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 2334 | #if SHADER_CHECKER_TESTS |
| 2335 | TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) |
| 2336 | { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2337 | VkFlags msgFlags; |
Chris Forbes | 5af3bf2 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 2338 | std::string msgString; |
| 2339 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Cody Northrop | 1cfbd17 | 2015-06-03 16:49:20 -0600 | [diff] [blame] | 2340 | ScopedUseGlsl useGlsl(false); |
Chris Forbes | 5af3bf2 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 2341 | |
| 2342 | char const *vsSource = |
| 2343 | "#version 140\n" |
| 2344 | "#extension GL_ARB_separate_shader_objects: require\n" |
| 2345 | "#extension GL_ARB_shading_language_420pack: require\n" |
| 2346 | "\n" |
| 2347 | "layout(location=0) out float x;\n" |
| 2348 | "void main(){\n" |
| 2349 | " gl_Position = vec4(1);\n" |
| 2350 | " x = 0;\n" |
| 2351 | "}\n"; |
| 2352 | char const *fsSource = |
| 2353 | "#version 140\n" |
| 2354 | "#extension GL_ARB_separate_shader_objects: require\n" |
| 2355 | "#extension GL_ARB_shading_language_420pack: require\n" |
| 2356 | "\n" |
| 2357 | "layout(location=0) out vec4 color;\n" |
| 2358 | "void main(){\n" |
| 2359 | " color = vec4(1);\n" |
| 2360 | "}\n"; |
| 2361 | |
| 2362 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this); |
| 2363 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this); |
| 2364 | |
| 2365 | VkPipelineObj pipe(m_device); |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 2366 | pipe.AddColorAttachment(); |
Chris Forbes | 5af3bf2 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 2367 | pipe.AddShader(&vs); |
| 2368 | pipe.AddShader(&fs); |
| 2369 | |
Chris Forbes | 5af3bf2 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 2370 | VkDescriptorSetObj descriptorSet(m_device); |
| 2371 | descriptorSet.AppendDummy(); |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2372 | descriptorSet.CreateVKDescriptorSet(m_cmdBuffer); |
Chris Forbes | 5af3bf2 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 2373 | |
| 2374 | m_errorMonitor->ClearState(); |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 2375 | pipe.CreateVKPipeline(descriptorSet, renderPass()); |
Chris Forbes | 5af3bf2 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 2376 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2377 | msgFlags = m_errorMonitor->GetState(&msgString); |
Chris Forbes | 5af3bf2 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 2378 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2379 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT); |
Chris Forbes | 5af3bf2 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 2380 | if (!strstr(msgString.c_str(),"not consumed by fragment shader")) { |
| 2381 | FAIL() << "Incorrect warning: " << msgString; |
| 2382 | } |
| 2383 | } |
Chris Forbes | 5af3bf2 | 2015-05-25 11:13:08 +1200 | [diff] [blame] | 2384 | |
Chris Forbes | 3c10b85 | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 2385 | TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) |
| 2386 | { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2387 | VkFlags msgFlags; |
Chris Forbes | 3c10b85 | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 2388 | std::string msgString; |
| 2389 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Cody Northrop | 1cfbd17 | 2015-06-03 16:49:20 -0600 | [diff] [blame] | 2390 | ScopedUseGlsl useGlsl(false); |
Chris Forbes | 3c10b85 | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 2391 | |
| 2392 | char const *vsSource = |
| 2393 | "#version 140\n" |
| 2394 | "#extension GL_ARB_separate_shader_objects: require\n" |
| 2395 | "#extension GL_ARB_shading_language_420pack: require\n" |
| 2396 | "\n" |
| 2397 | "void main(){\n" |
| 2398 | " gl_Position = vec4(1);\n" |
| 2399 | "}\n"; |
| 2400 | char const *fsSource = |
| 2401 | "#version 140\n" |
| 2402 | "#extension GL_ARB_separate_shader_objects: require\n" |
| 2403 | "#extension GL_ARB_shading_language_420pack: require\n" |
| 2404 | "\n" |
| 2405 | "layout(location=0) in float x;\n" |
| 2406 | "layout(location=0) out vec4 color;\n" |
| 2407 | "void main(){\n" |
| 2408 | " color = vec4(x);\n" |
| 2409 | "}\n"; |
| 2410 | |
| 2411 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this); |
| 2412 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this); |
| 2413 | |
| 2414 | VkPipelineObj pipe(m_device); |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 2415 | pipe.AddColorAttachment(); |
Chris Forbes | 3c10b85 | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 2416 | pipe.AddShader(&vs); |
| 2417 | pipe.AddShader(&fs); |
| 2418 | |
Chris Forbes | 3c10b85 | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 2419 | VkDescriptorSetObj descriptorSet(m_device); |
| 2420 | descriptorSet.AppendDummy(); |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2421 | descriptorSet.CreateVKDescriptorSet(m_cmdBuffer); |
Chris Forbes | 3c10b85 | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 2422 | |
| 2423 | m_errorMonitor->ClearState(); |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 2424 | pipe.CreateVKPipeline(descriptorSet, renderPass()); |
Chris Forbes | 3c10b85 | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 2425 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2426 | msgFlags = m_errorMonitor->GetState(&msgString); |
Chris Forbes | 3c10b85 | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 2427 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2428 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT); |
Chris Forbes | 3c10b85 | 2015-05-25 11:13:13 +1200 | [diff] [blame] | 2429 | if (!strstr(msgString.c_str(),"not written by vertex shader")) { |
| 2430 | FAIL() << "Incorrect error: " << msgString; |
| 2431 | } |
| 2432 | } |
| 2433 | |
Chris Forbes | cc28169 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 2434 | TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) |
| 2435 | { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2436 | VkFlags msgFlags; |
Chris Forbes | cc28169 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 2437 | std::string msgString; |
| 2438 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Cody Northrop | 1cfbd17 | 2015-06-03 16:49:20 -0600 | [diff] [blame] | 2439 | ScopedUseGlsl useGlsl(false); |
Chris Forbes | cc28169 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 2440 | |
| 2441 | char const *vsSource = |
| 2442 | "#version 140\n" |
| 2443 | "#extension GL_ARB_separate_shader_objects: require\n" |
| 2444 | "#extension GL_ARB_shading_language_420pack: require\n" |
| 2445 | "\n" |
| 2446 | "layout(location=0) out int x;\n" |
| 2447 | "void main(){\n" |
| 2448 | " x = 0;\n" |
| 2449 | " gl_Position = vec4(1);\n" |
| 2450 | "}\n"; |
| 2451 | char const *fsSource = |
| 2452 | "#version 140\n" |
| 2453 | "#extension GL_ARB_separate_shader_objects: require\n" |
| 2454 | "#extension GL_ARB_shading_language_420pack: require\n" |
| 2455 | "\n" |
| 2456 | "layout(location=0) in float x;\n" /* VS writes int */ |
| 2457 | "layout(location=0) out vec4 color;\n" |
| 2458 | "void main(){\n" |
| 2459 | " color = vec4(x);\n" |
| 2460 | "}\n"; |
| 2461 | |
| 2462 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this); |
| 2463 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this); |
| 2464 | |
| 2465 | VkPipelineObj pipe(m_device); |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 2466 | pipe.AddColorAttachment(); |
Chris Forbes | cc28169 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 2467 | pipe.AddShader(&vs); |
| 2468 | pipe.AddShader(&fs); |
| 2469 | |
Chris Forbes | cc28169 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 2470 | VkDescriptorSetObj descriptorSet(m_device); |
| 2471 | descriptorSet.AppendDummy(); |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2472 | descriptorSet.CreateVKDescriptorSet(m_cmdBuffer); |
Chris Forbes | cc28169 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 2473 | |
| 2474 | m_errorMonitor->ClearState(); |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 2475 | pipe.CreateVKPipeline(descriptorSet, renderPass()); |
Chris Forbes | cc28169 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 2476 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2477 | msgFlags = m_errorMonitor->GetState(&msgString); |
Chris Forbes | cc28169 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 2478 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2479 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT); |
Chris Forbes | cc28169 | 2015-05-25 11:13:17 +1200 | [diff] [blame] | 2480 | if (!strstr(msgString.c_str(),"Type mismatch on location 0")) { |
| 2481 | FAIL() << "Incorrect error: " << msgString; |
| 2482 | } |
| 2483 | } |
| 2484 | |
Chris Forbes | 8291c05 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 2485 | TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) |
| 2486 | { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2487 | VkFlags msgFlags; |
Chris Forbes | 8291c05 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 2488 | std::string msgString; |
| 2489 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Cody Northrop | 1cfbd17 | 2015-06-03 16:49:20 -0600 | [diff] [blame] | 2490 | ScopedUseGlsl useGlsl(false); |
Chris Forbes | 8291c05 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 2491 | |
| 2492 | VkVertexInputBindingDescription input_binding; |
| 2493 | memset(&input_binding, 0, sizeof(input_binding)); |
| 2494 | |
| 2495 | VkVertexInputAttributeDescription input_attrib; |
| 2496 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 2497 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 2498 | |
| 2499 | char const *vsSource = |
| 2500 | "#version 140\n" |
| 2501 | "#extension GL_ARB_separate_shader_objects: require\n" |
| 2502 | "#extension GL_ARB_shading_language_420pack: require\n" |
| 2503 | "\n" |
| 2504 | "void main(){\n" |
| 2505 | " gl_Position = vec4(1);\n" |
| 2506 | "}\n"; |
| 2507 | char const *fsSource = |
| 2508 | "#version 140\n" |
| 2509 | "#extension GL_ARB_separate_shader_objects: require\n" |
| 2510 | "#extension GL_ARB_shading_language_420pack: require\n" |
| 2511 | "\n" |
| 2512 | "layout(location=0) out vec4 color;\n" |
| 2513 | "void main(){\n" |
| 2514 | " color = vec4(1);\n" |
| 2515 | "}\n"; |
| 2516 | |
| 2517 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this); |
| 2518 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this); |
| 2519 | |
| 2520 | VkPipelineObj pipe(m_device); |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 2521 | pipe.AddColorAttachment(); |
Chris Forbes | 8291c05 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 2522 | pipe.AddShader(&vs); |
| 2523 | pipe.AddShader(&fs); |
| 2524 | |
| 2525 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 2526 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 2527 | |
Chris Forbes | 8291c05 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 2528 | VkDescriptorSetObj descriptorSet(m_device); |
| 2529 | descriptorSet.AppendDummy(); |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2530 | descriptorSet.CreateVKDescriptorSet(m_cmdBuffer); |
Chris Forbes | 8291c05 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 2531 | |
| 2532 | m_errorMonitor->ClearState(); |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 2533 | pipe.CreateVKPipeline(descriptorSet, renderPass()); |
Chris Forbes | 8291c05 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 2534 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2535 | msgFlags = m_errorMonitor->GetState(&msgString); |
Chris Forbes | 8291c05 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 2536 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2537 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT); |
Chris Forbes | 8291c05 | 2015-05-25 11:13:28 +1200 | [diff] [blame] | 2538 | if (!strstr(msgString.c_str(),"location 0 not consumed by VS")) { |
| 2539 | FAIL() << "Incorrect warning: " << msgString; |
| 2540 | } |
| 2541 | } |
| 2542 | |
Chris Forbes | 37367e6 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 2543 | TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) |
| 2544 | { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2545 | VkFlags msgFlags; |
Chris Forbes | 37367e6 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 2546 | std::string msgString; |
| 2547 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Cody Northrop | 1cfbd17 | 2015-06-03 16:49:20 -0600 | [diff] [blame] | 2548 | ScopedUseGlsl useGlsl(false); |
Chris Forbes | 37367e6 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 2549 | |
| 2550 | char const *vsSource = |
| 2551 | "#version 140\n" |
| 2552 | "#extension GL_ARB_separate_shader_objects: require\n" |
| 2553 | "#extension GL_ARB_shading_language_420pack: require\n" |
| 2554 | "\n" |
| 2555 | "layout(location=0) in vec4 x;\n" /* not provided */ |
| 2556 | "void main(){\n" |
| 2557 | " gl_Position = x;\n" |
| 2558 | "}\n"; |
| 2559 | char const *fsSource = |
| 2560 | "#version 140\n" |
| 2561 | "#extension GL_ARB_separate_shader_objects: require\n" |
| 2562 | "#extension GL_ARB_shading_language_420pack: require\n" |
| 2563 | "\n" |
| 2564 | "layout(location=0) out vec4 color;\n" |
| 2565 | "void main(){\n" |
| 2566 | " color = vec4(1);\n" |
| 2567 | "}\n"; |
| 2568 | |
| 2569 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this); |
| 2570 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this); |
| 2571 | |
| 2572 | VkPipelineObj pipe(m_device); |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 2573 | pipe.AddColorAttachment(); |
Chris Forbes | 37367e6 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 2574 | pipe.AddShader(&vs); |
| 2575 | pipe.AddShader(&fs); |
| 2576 | |
Chris Forbes | 37367e6 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 2577 | VkDescriptorSetObj descriptorSet(m_device); |
| 2578 | descriptorSet.AppendDummy(); |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2579 | descriptorSet.CreateVKDescriptorSet(m_cmdBuffer); |
Chris Forbes | 37367e6 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 2580 | |
| 2581 | m_errorMonitor->ClearState(); |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 2582 | pipe.CreateVKPipeline(descriptorSet, renderPass()); |
Chris Forbes | 37367e6 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 2583 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2584 | msgFlags = m_errorMonitor->GetState(&msgString); |
Chris Forbes | 37367e6 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 2585 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2586 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT); |
Chris Forbes | 37367e6 | 2015-05-25 11:13:29 +1200 | [diff] [blame] | 2587 | if (!strstr(msgString.c_str(),"VS consumes input at location 0 but not provided")) { |
| 2588 | FAIL() << "Incorrect warning: " << msgString; |
| 2589 | } |
| 2590 | } |
| 2591 | |
Chris Forbes | a4b0232 | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 2592 | TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) |
| 2593 | { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2594 | VkFlags msgFlags; |
Chris Forbes | a4b0232 | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 2595 | std::string msgString; |
| 2596 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Cody Northrop | 1cfbd17 | 2015-06-03 16:49:20 -0600 | [diff] [blame] | 2597 | ScopedUseGlsl useGlsl(false); |
Chris Forbes | a4b0232 | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 2598 | |
| 2599 | VkVertexInputBindingDescription input_binding; |
| 2600 | memset(&input_binding, 0, sizeof(input_binding)); |
| 2601 | |
| 2602 | VkVertexInputAttributeDescription input_attrib; |
| 2603 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 2604 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 2605 | |
| 2606 | char const *vsSource = |
| 2607 | "#version 140\n" |
| 2608 | "#extension GL_ARB_separate_shader_objects: require\n" |
| 2609 | "#extension GL_ARB_shading_language_420pack: require\n" |
| 2610 | "\n" |
| 2611 | "layout(location=0) in int x;\n" /* attrib provided float */ |
| 2612 | "void main(){\n" |
| 2613 | " gl_Position = vec4(x);\n" |
| 2614 | "}\n"; |
| 2615 | char const *fsSource = |
| 2616 | "#version 140\n" |
| 2617 | "#extension GL_ARB_separate_shader_objects: require\n" |
| 2618 | "#extension GL_ARB_shading_language_420pack: require\n" |
| 2619 | "\n" |
| 2620 | "layout(location=0) out vec4 color;\n" |
| 2621 | "void main(){\n" |
| 2622 | " color = vec4(1);\n" |
| 2623 | "}\n"; |
| 2624 | |
| 2625 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this); |
| 2626 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this); |
| 2627 | |
| 2628 | VkPipelineObj pipe(m_device); |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 2629 | pipe.AddColorAttachment(); |
Chris Forbes | a4b0232 | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 2630 | pipe.AddShader(&vs); |
| 2631 | pipe.AddShader(&fs); |
| 2632 | |
| 2633 | pipe.AddVertexInputBindings(&input_binding, 1); |
| 2634 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 2635 | |
Chris Forbes | a4b0232 | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 2636 | VkDescriptorSetObj descriptorSet(m_device); |
| 2637 | descriptorSet.AppendDummy(); |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2638 | descriptorSet.CreateVKDescriptorSet(m_cmdBuffer); |
Chris Forbes | a4b0232 | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 2639 | |
| 2640 | m_errorMonitor->ClearState(); |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 2641 | pipe.CreateVKPipeline(descriptorSet, renderPass()); |
Chris Forbes | a4b0232 | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 2642 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2643 | msgFlags = m_errorMonitor->GetState(&msgString); |
Chris Forbes | a4b0232 | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 2644 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2645 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT); |
Chris Forbes | a4b0232 | 2015-05-25 11:13:31 +1200 | [diff] [blame] | 2646 | if (!strstr(msgString.c_str(),"location 0 does not match VS input type")) { |
| 2647 | FAIL() << "Incorrect error: " << msgString; |
| 2648 | } |
| 2649 | } |
| 2650 | |
Chris Forbes | 0bf8fe1 | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 2651 | TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) |
| 2652 | { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2653 | VkFlags msgFlags; |
Chris Forbes | 0bf8fe1 | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 2654 | std::string msgString; |
| 2655 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Cody Northrop | 1cfbd17 | 2015-06-03 16:49:20 -0600 | [diff] [blame] | 2656 | ScopedUseGlsl useGlsl(false); |
Chris Forbes | 0bf8fe1 | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 2657 | |
| 2658 | /* Two binding descriptions for binding 0 */ |
| 2659 | VkVertexInputBindingDescription input_bindings[2]; |
| 2660 | memset(input_bindings, 0, sizeof(input_bindings)); |
| 2661 | |
| 2662 | VkVertexInputAttributeDescription input_attrib; |
| 2663 | memset(&input_attrib, 0, sizeof(input_attrib)); |
| 2664 | input_attrib.format = VK_FORMAT_R32_SFLOAT; |
| 2665 | |
| 2666 | char const *vsSource = |
| 2667 | "#version 140\n" |
| 2668 | "#extension GL_ARB_separate_shader_objects: require\n" |
| 2669 | "#extension GL_ARB_shading_language_420pack: require\n" |
| 2670 | "\n" |
| 2671 | "layout(location=0) in float x;\n" /* attrib provided float */ |
| 2672 | "void main(){\n" |
| 2673 | " gl_Position = vec4(x);\n" |
| 2674 | "}\n"; |
| 2675 | char const *fsSource = |
| 2676 | "#version 140\n" |
| 2677 | "#extension GL_ARB_separate_shader_objects: require\n" |
| 2678 | "#extension GL_ARB_shading_language_420pack: require\n" |
| 2679 | "\n" |
| 2680 | "layout(location=0) out vec4 color;\n" |
| 2681 | "void main(){\n" |
| 2682 | " color = vec4(1);\n" |
| 2683 | "}\n"; |
| 2684 | |
| 2685 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this); |
| 2686 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this); |
| 2687 | |
| 2688 | VkPipelineObj pipe(m_device); |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 2689 | pipe.AddColorAttachment(); |
Chris Forbes | 0bf8fe1 | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 2690 | pipe.AddShader(&vs); |
| 2691 | pipe.AddShader(&fs); |
| 2692 | |
| 2693 | pipe.AddVertexInputBindings(input_bindings, 2); |
| 2694 | pipe.AddVertexInputAttribs(&input_attrib, 1); |
| 2695 | |
Chris Forbes | 0bf8fe1 | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 2696 | VkDescriptorSetObj descriptorSet(m_device); |
| 2697 | descriptorSet.AppendDummy(); |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2698 | descriptorSet.CreateVKDescriptorSet(m_cmdBuffer); |
Chris Forbes | 0bf8fe1 | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 2699 | |
| 2700 | m_errorMonitor->ClearState(); |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 2701 | pipe.CreateVKPipeline(descriptorSet, renderPass()); |
Chris Forbes | 0bf8fe1 | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 2702 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2703 | msgFlags = m_errorMonitor->GetState(&msgString); |
Chris Forbes | 0bf8fe1 | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 2704 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2705 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT); |
Chris Forbes | 0bf8fe1 | 2015-06-12 11:16:41 +1200 | [diff] [blame] | 2706 | if (!strstr(msgString.c_str(),"Duplicate vertex input binding descriptions for binding 0")) { |
| 2707 | FAIL() << "Incorrect error: " << msgString; |
| 2708 | } |
| 2709 | } |
Chris Forbes | 4c94870 | 2015-05-25 11:13:32 +1200 | [diff] [blame] | 2710 | |
Chris Forbes | c12ef12 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 2711 | /* TODO: would be nice to test the mixed broadcast & custom case, but the GLSL->SPV compiler |
| 2712 | * rejects it. */ |
| 2713 | |
| 2714 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) |
| 2715 | { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2716 | VkFlags msgFlags; |
Chris Forbes | c12ef12 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 2717 | std::string msgString; |
| 2718 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Cody Northrop | 1cfbd17 | 2015-06-03 16:49:20 -0600 | [diff] [blame] | 2719 | ScopedUseGlsl useGlsl(false); |
Chris Forbes | c12ef12 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 2720 | |
| 2721 | char const *vsSource = |
| 2722 | "#version 140\n" |
| 2723 | "#extension GL_ARB_separate_shader_objects: require\n" |
| 2724 | "#extension GL_ARB_shading_language_420pack: require\n" |
| 2725 | "\n" |
| 2726 | "void main(){\n" |
| 2727 | " gl_Position = vec4(1);\n" |
| 2728 | "}\n"; |
| 2729 | char const *fsSource = |
| 2730 | "#version 140\n" |
| 2731 | "#extension GL_ARB_separate_shader_objects: require\n" |
| 2732 | "#extension GL_ARB_shading_language_420pack: require\n" |
| 2733 | "\n" |
| 2734 | "void main(){\n" |
| 2735 | "}\n"; |
| 2736 | |
| 2737 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this); |
| 2738 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this); |
| 2739 | |
| 2740 | VkPipelineObj pipe(m_device); |
| 2741 | pipe.AddShader(&vs); |
| 2742 | pipe.AddShader(&fs); |
| 2743 | |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 2744 | /* set up CB 0, not written */ |
| 2745 | pipe.AddColorAttachment(); |
| 2746 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | c12ef12 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 2747 | |
Chris Forbes | c12ef12 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 2748 | VkDescriptorSetObj descriptorSet(m_device); |
| 2749 | descriptorSet.AppendDummy(); |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2750 | descriptorSet.CreateVKDescriptorSet(m_cmdBuffer); |
Chris Forbes | c12ef12 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 2751 | |
| 2752 | m_errorMonitor->ClearState(); |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 2753 | pipe.CreateVKPipeline(descriptorSet, renderPass()); |
Chris Forbes | c12ef12 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 2754 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2755 | msgFlags = m_errorMonitor->GetState(&msgString); |
Chris Forbes | c12ef12 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 2756 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2757 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT); |
Chris Forbes | c12ef12 | 2015-05-25 11:13:40 +1200 | [diff] [blame] | 2758 | if (!strstr(msgString.c_str(),"Attachment 0 not written by FS")) { |
| 2759 | FAIL() << "Incorrect error: " << msgString; |
| 2760 | } |
| 2761 | } |
| 2762 | |
Chris Forbes | 5d15a4f | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 2763 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) |
| 2764 | { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2765 | VkFlags msgFlags; |
Chris Forbes | 5d15a4f | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 2766 | std::string msgString; |
| 2767 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Cody Northrop | 1cfbd17 | 2015-06-03 16:49:20 -0600 | [diff] [blame] | 2768 | ScopedUseGlsl useGlsl(false); |
Chris Forbes | 5d15a4f | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 2769 | |
| 2770 | char const *vsSource = |
| 2771 | "#version 140\n" |
| 2772 | "#extension GL_ARB_separate_shader_objects: require\n" |
| 2773 | "#extension GL_ARB_shading_language_420pack: require\n" |
| 2774 | "\n" |
| 2775 | "void main(){\n" |
| 2776 | " gl_Position = vec4(1);\n" |
| 2777 | "}\n"; |
| 2778 | char const *fsSource = |
| 2779 | "#version 140\n" |
| 2780 | "#extension GL_ARB_separate_shader_objects: require\n" |
| 2781 | "#extension GL_ARB_shading_language_420pack: require\n" |
| 2782 | "\n" |
| 2783 | "layout(location=0) out vec4 x;\n" |
| 2784 | "layout(location=1) out vec4 y;\n" /* no matching attachment for this */ |
| 2785 | "void main(){\n" |
| 2786 | " x = vec4(1);\n" |
| 2787 | " y = vec4(1);\n" |
| 2788 | "}\n"; |
| 2789 | |
| 2790 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this); |
| 2791 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this); |
| 2792 | |
| 2793 | VkPipelineObj pipe(m_device); |
| 2794 | pipe.AddShader(&vs); |
| 2795 | pipe.AddShader(&fs); |
| 2796 | |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 2797 | /* set up CB 0, not written */ |
| 2798 | pipe.AddColorAttachment(); |
| 2799 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 5d15a4f | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 2800 | /* FS writes CB 1, but we don't configure it */ |
| 2801 | |
Chris Forbes | 5d15a4f | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 2802 | VkDescriptorSetObj descriptorSet(m_device); |
| 2803 | descriptorSet.AppendDummy(); |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2804 | descriptorSet.CreateVKDescriptorSet(m_cmdBuffer); |
Chris Forbes | 5d15a4f | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 2805 | |
| 2806 | m_errorMonitor->ClearState(); |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 2807 | pipe.CreateVKPipeline(descriptorSet, renderPass()); |
Chris Forbes | 5d15a4f | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 2808 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2809 | msgFlags = m_errorMonitor->GetState(&msgString); |
Chris Forbes | 5d15a4f | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 2810 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2811 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT); |
Chris Forbes | 5d15a4f | 2015-05-25 11:13:43 +1200 | [diff] [blame] | 2812 | if (!strstr(msgString.c_str(),"FS writes to output location 1 with no matching attachment")) { |
| 2813 | FAIL() << "Incorrect warning: " << msgString; |
| 2814 | } |
| 2815 | } |
| 2816 | |
Chris Forbes | 7d64a4f | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 2817 | TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) |
| 2818 | { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2819 | VkFlags msgFlags; |
Chris Forbes | 7d64a4f | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 2820 | std::string msgString; |
| 2821 | ASSERT_NO_FATAL_FAILURE(InitState()); |
Cody Northrop | 1cfbd17 | 2015-06-03 16:49:20 -0600 | [diff] [blame] | 2822 | ScopedUseGlsl useGlsl(false); |
Chris Forbes | 7d64a4f | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 2823 | |
| 2824 | char const *vsSource = |
| 2825 | "#version 140\n" |
| 2826 | "#extension GL_ARB_separate_shader_objects: require\n" |
| 2827 | "#extension GL_ARB_shading_language_420pack: require\n" |
| 2828 | "\n" |
| 2829 | "void main(){\n" |
| 2830 | " gl_Position = vec4(1);\n" |
| 2831 | "}\n"; |
| 2832 | char const *fsSource = |
| 2833 | "#version 140\n" |
| 2834 | "#extension GL_ARB_separate_shader_objects: require\n" |
| 2835 | "#extension GL_ARB_shading_language_420pack: require\n" |
| 2836 | "\n" |
| 2837 | "layout(location=0) out ivec4 x;\n" /* not UNORM */ |
| 2838 | "void main(){\n" |
| 2839 | " x = ivec4(1);\n" |
| 2840 | "}\n"; |
| 2841 | |
| 2842 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this); |
| 2843 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this); |
| 2844 | |
| 2845 | VkPipelineObj pipe(m_device); |
| 2846 | pipe.AddShader(&vs); |
| 2847 | pipe.AddShader(&fs); |
| 2848 | |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 2849 | /* set up CB 0; type is UNORM by default */ |
| 2850 | pipe.AddColorAttachment(); |
| 2851 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | 7d64a4f | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 2852 | |
Chris Forbes | 7d64a4f | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 2853 | VkDescriptorSetObj descriptorSet(m_device); |
| 2854 | descriptorSet.AppendDummy(); |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2855 | descriptorSet.CreateVKDescriptorSet(m_cmdBuffer); |
Chris Forbes | 7d64a4f | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 2856 | |
| 2857 | m_errorMonitor->ClearState(); |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 2858 | pipe.CreateVKPipeline(descriptorSet, renderPass()); |
Chris Forbes | 7d64a4f | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 2859 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2860 | msgFlags = m_errorMonitor->GetState(&msgString); |
Chris Forbes | 7d64a4f | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 2861 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2862 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_ERROR_BIT); |
Chris Forbes | 7d64a4f | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 2863 | if (!strstr(msgString.c_str(),"does not match FS output type")) { |
| 2864 | FAIL() << "Incorrect error: " << msgString; |
| 2865 | } |
| 2866 | } |
Chris Forbes | c205073 | 2015-06-05 14:43:36 +1200 | [diff] [blame] | 2867 | |
| 2868 | TEST_F(VkLayerTest, CreatePipelineNonSpirvShader) |
| 2869 | { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2870 | VkFlags msgFlags; |
Chris Forbes | c205073 | 2015-06-05 14:43:36 +1200 | [diff] [blame] | 2871 | std::string msgString; |
| 2872 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 2873 | /* Intentionally provided GLSL rather than compiling to SPIRV first */ |
Cody Northrop | 1cfbd17 | 2015-06-03 16:49:20 -0600 | [diff] [blame] | 2874 | ScopedUseGlsl useGlsl(true); |
Chris Forbes | c205073 | 2015-06-05 14:43:36 +1200 | [diff] [blame] | 2875 | |
| 2876 | char const *vsSource = |
| 2877 | "#version 140\n" |
| 2878 | "#extension GL_ARB_separate_shader_objects: require\n" |
| 2879 | "#extension GL_ARB_shading_language_420pack: require\n" |
| 2880 | "\n" |
| 2881 | "void main(){\n" |
| 2882 | " gl_Position = vec4(1);\n" |
| 2883 | "}\n"; |
| 2884 | char const *fsSource = |
| 2885 | "#version 140\n" |
| 2886 | "#extension GL_ARB_separate_shader_objects: require\n" |
| 2887 | "#extension GL_ARB_shading_language_420pack: require\n" |
| 2888 | "\n" |
| 2889 | "layout(location=0) out vec4 x;\n" |
| 2890 | "void main(){\n" |
| 2891 | " x = vec4(1);\n" |
| 2892 | "}\n"; |
| 2893 | |
| 2894 | m_errorMonitor->ClearState(); |
| 2895 | |
| 2896 | VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX, this); |
| 2897 | VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT, this); |
| 2898 | |
| 2899 | |
| 2900 | VkPipelineObj pipe(m_device); |
| 2901 | pipe.AddShader(&vs); |
| 2902 | pipe.AddShader(&fs); |
| 2903 | |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 2904 | /* set up CB 0; type is UNORM by default */ |
| 2905 | pipe.AddColorAttachment(); |
| 2906 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
Chris Forbes | c205073 | 2015-06-05 14:43:36 +1200 | [diff] [blame] | 2907 | |
Chris Forbes | c205073 | 2015-06-05 14:43:36 +1200 | [diff] [blame] | 2908 | VkDescriptorSetObj descriptorSet(m_device); |
| 2909 | descriptorSet.AppendDummy(); |
Tony Barbour | 1490c91 | 2015-07-28 10:17:20 -0600 | [diff] [blame] | 2910 | descriptorSet.CreateVKDescriptorSet(m_cmdBuffer); |
Chris Forbes | c205073 | 2015-06-05 14:43:36 +1200 | [diff] [blame] | 2911 | |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 2912 | VkResult res = pipe.CreateVKPipeline(descriptorSet, renderPass()); |
Chris Forbes | c205073 | 2015-06-05 14:43:36 +1200 | [diff] [blame] | 2913 | /* pipeline creation should have succeeded */ |
| 2914 | ASSERT_EQ(VK_SUCCESS, res); |
| 2915 | |
| 2916 | /* should have emitted a warning: the shader is not SPIRV, so we're |
| 2917 | * not going to be able to analyze it */ |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 2918 | msgFlags = m_errorMonitor->GetState(&msgString); |
| 2919 | ASSERT_TRUE(msgFlags & VK_DBG_REPORT_WARN_BIT); |
Chris Forbes | c205073 | 2015-06-05 14:43:36 +1200 | [diff] [blame] | 2920 | if (!strstr(msgString.c_str(),"is not SPIR-V")) { |
| 2921 | FAIL() << "Incorrect warning: " << msgString; |
| 2922 | } |
| 2923 | } |
Chris Forbes | 01c9db7 | 2015-06-04 09:25:25 +1200 | [diff] [blame] | 2924 | #endif |
Chris Forbes | 7d64a4f | 2015-05-25 11:13:44 +1200 | [diff] [blame] | 2925 | |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2926 | int main(int argc, char **argv) { |
| 2927 | int result; |
| 2928 | |
| 2929 | ::testing::InitGoogleTest(&argc, argv); |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2930 | VkTestFramework::InitArgs(&argc, argv); |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2931 | |
| 2932 | ::testing::AddGlobalTestEnvironment(new TestEnvironment); |
| 2933 | |
| 2934 | result = RUN_ALL_TESTS(); |
| 2935 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 2936 | VkTestFramework::Finish(); |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 2937 | return result; |
| 2938 | } |