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