Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1 | #include <vulkan.h> |
| 2 | #include <vkDbg.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" |
Mark Lobodzinski | a910dc8 | 2015-05-14 14:30:48 -0500 | [diff] [blame] | 5 | #include "layers_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 |
| 15 | |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 16 | //-------------------------------------------------------------------------------------- |
| 17 | // Mesh and VertexFormat Data |
| 18 | //-------------------------------------------------------------------------------------- |
| 19 | struct Vertex |
| 20 | { |
| 21 | float posX, posY, posZ, posW; // Position data |
| 22 | float r, g, b, a; // Color |
| 23 | }; |
| 24 | |
| 25 | #define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f |
| 26 | |
| 27 | typedef enum _BsoFailSelect { |
| 28 | BsoFailNone = 0x00000000, |
| 29 | BsoFailRaster = 0x00000001, |
| 30 | BsoFailViewport = 0x00000002, |
| 31 | BsoFailColorBlend = 0x00000004, |
| 32 | BsoFailDepthStencil = 0x00000008, |
| 33 | } BsoFailSelect; |
| 34 | |
| 35 | struct vktriangle_vs_uniform { |
| 36 | // Must start with MVP |
| 37 | float mvp[4][4]; |
| 38 | float position[3][4]; |
| 39 | float color[3][4]; |
| 40 | }; |
| 41 | |
Mark Lobodzinski | 6bbdff1 | 2015-06-02 09:41:30 -0500 | [diff] [blame] | 42 | static const char bindStateVertShaderText[] = |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 43 | "#version 130\n" |
| 44 | "vec2 vertices[3];\n" |
| 45 | "void main() {\n" |
| 46 | " vertices[0] = vec2(-1.0, -1.0);\n" |
| 47 | " vertices[1] = vec2( 1.0, -1.0);\n" |
| 48 | " vertices[2] = vec2( 0.0, 1.0);\n" |
| 49 | " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" |
| 50 | "}\n"; |
| 51 | |
Mark Lobodzinski | 6bbdff1 | 2015-06-02 09:41:30 -0500 | [diff] [blame] | 52 | static const char bindStateFragShaderText[] = |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 53 | "#version 130\n" |
| 54 | "void main() {\n" |
| 55 | " gl_FragColor = vec4(0,1,0,1);\n" |
| 56 | "}\n"; |
| 57 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 58 | void VKAPI myDbgFunc( |
| 59 | VK_DBG_MSG_TYPE msgType, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 60 | VkValidationLevel validationLevel, |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 61 | VkObject srcObject, |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 62 | size_t location, |
| 63 | int32_t msgCode, |
| 64 | const char* pMsg, |
| 65 | void* pUserData); |
| 66 | |
| 67 | class ErrorMonitor { |
| 68 | public: |
Tony Barbour | 0c1bdc6 | 2015-04-29 17:34:29 -0600 | [diff] [blame] | 69 | ErrorMonitor() |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 70 | { |
Mike Stroyan | 09aae81 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 71 | pthread_mutexattr_t attr; |
| 72 | pthread_mutexattr_init(&attr); |
| 73 | pthread_mutex_init(&m_mutex, &attr); |
| 74 | pthread_mutex_lock(&m_mutex); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 75 | m_msgType = VK_DBG_MSG_UNKNOWN; |
Mike Stroyan | 09aae81 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 76 | m_bailout = NULL; |
| 77 | pthread_mutex_unlock(&m_mutex); |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 78 | } |
| 79 | void ClearState() |
| 80 | { |
Mike Stroyan | 09aae81 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 81 | pthread_mutex_lock(&m_mutex); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 82 | m_msgType = VK_DBG_MSG_UNKNOWN; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 83 | m_msgString.clear(); |
Mike Stroyan | 09aae81 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 84 | pthread_mutex_unlock(&m_mutex); |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 85 | } |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 86 | VK_DBG_MSG_TYPE GetState(std::string *msgString) |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 87 | { |
Mike Stroyan | 09aae81 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 88 | pthread_mutex_lock(&m_mutex); |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 89 | *msgString = m_msgString; |
Mike Stroyan | 09aae81 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 90 | pthread_mutex_unlock(&m_mutex); |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 91 | return m_msgType; |
| 92 | } |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 93 | void SetState(VK_DBG_MSG_TYPE msgType, const char *msgString) |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 94 | { |
Mike Stroyan | 09aae81 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 95 | pthread_mutex_lock(&m_mutex); |
| 96 | if (m_bailout != NULL) { |
| 97 | *m_bailout = true; |
| 98 | } |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 99 | m_msgType = msgType; |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 100 | m_msgString.reserve(strlen(msgString)); |
| 101 | m_msgString = msgString; |
Mike Stroyan | 09aae81 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 102 | pthread_mutex_unlock(&m_mutex); |
| 103 | } |
| 104 | void SetBailout(bool *bailout) |
| 105 | { |
| 106 | m_bailout = bailout; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | private: |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 110 | VK_DBG_MSG_TYPE m_msgType; |
Mike Stroyan | 09aae81 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 111 | std::string m_msgString; |
| 112 | pthread_mutex_t m_mutex; |
| 113 | bool* m_bailout; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 114 | }; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 115 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 116 | void VKAPI myDbgFunc( |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 117 | VK_DBG_MSG_TYPE msgType, |
| 118 | VkValidationLevel validationLevel, |
| 119 | VkObject srcObject, |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 120 | size_t location, |
| 121 | int32_t msgCode, |
| 122 | const char* pMsg, |
| 123 | void* pUserData) |
| 124 | { |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 125 | if (msgType == VK_DBG_MSG_WARNING || msgType == VK_DBG_MSG_ERROR) { |
| 126 | ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData; |
| 127 | errMonitor->SetState(msgType, pMsg); |
| 128 | } |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 129 | } |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 130 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 131 | class VkLayerTest : public VkRenderFramework |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 132 | { |
| 133 | public: |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 134 | VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer); |
| 135 | VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 136 | void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask); |
| 137 | void GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask); |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 138 | |
| 139 | protected: |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 140 | VkMemoryRefManager m_memoryRefManager; |
| 141 | ErrorMonitor *m_errorMonitor; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 142 | |
| 143 | virtual void SetUp() { |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 144 | const char *extension_names[] = {"MemTracker", "ObjectTracker", "Threading", "DrawState"}; |
Mike Stroyan | 09aae81 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 145 | const std::vector<const char *> extensions(extension_names, |
| 146 | extension_names + sizeof(extension_names)/sizeof(extension_names[0])); |
Tony Barbour | 950ebc0 | 2015-04-23 12:55:36 -0600 | [diff] [blame] | 147 | |
| 148 | size_t extSize = sizeof(uint32_t); |
| 149 | uint32_t extCount = 0; |
Tony Barbour | 04ada4a | 2015-04-23 15:28:27 -0600 | [diff] [blame] | 150 | VkResult U_ASSERT_ONLY err; |
Tony Barbour | 950ebc0 | 2015-04-23 12:55:36 -0600 | [diff] [blame] | 151 | err = vkGetGlobalExtensionInfo(VK_EXTENSION_INFO_TYPE_COUNT, 0, &extSize, &extCount); |
| 152 | assert(!err); |
| 153 | |
| 154 | VkExtensionProperties extProp; |
| 155 | extSize = sizeof(VkExtensionProperties); |
| 156 | bool32_t extFound; |
| 157 | |
Tony Barbour | 04ada4a | 2015-04-23 15:28:27 -0600 | [diff] [blame] | 158 | for (uint32_t i = 0; i < extensions.size(); i++) { |
Tony Barbour | 950ebc0 | 2015-04-23 12:55:36 -0600 | [diff] [blame] | 159 | extFound = 0; |
| 160 | for (uint32_t j = 0; j < extCount; j++) { |
| 161 | err = vkGetGlobalExtensionInfo(VK_EXTENSION_INFO_TYPE_PROPERTIES, j, &extSize, &extProp); |
Tony Barbour | 04ada4a | 2015-04-23 15:28:27 -0600 | [diff] [blame] | 162 | assert(!err); |
| 163 | if (!strcmp(extensions[i], extProp.extName)) { |
Tony Barbour | 950ebc0 | 2015-04-23 12:55:36 -0600 | [diff] [blame] | 164 | extFound = 1; |
| 165 | break; |
| 166 | } |
| 167 | } |
Tony Barbour | 04ada4a | 2015-04-23 15:28:27 -0600 | [diff] [blame] | 168 | ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << extensions[i] << " which is necessary to pass this test"; |
Tony Barbour | 950ebc0 | 2015-04-23 12:55:36 -0600 | [diff] [blame] | 169 | } |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 170 | |
Mark Lobodzinski | a910dc8 | 2015-05-14 14:30:48 -0500 | [diff] [blame] | 171 | // Force layer output level to be >= WARNING so that we catch those messages but ignore others |
| 172 | setLayerOptionEnum("MemTrackerReportLevel", "VK_DBG_LAYER_LEVEL_WARNING"); |
| 173 | setLayerOptionEnum("ObjectTrackerReportLevel", "VK_DBG_LAYER_LEVEL_WARNING"); |
| 174 | setLayerOptionEnum("ThreadingReportLevel", "VK_DBG_LAYER_LEVEL_WARNING"); |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 175 | setLayerOptionEnum("DrawStateReportLevel", "VK_DBG_LAYER_LEVEL_WARNING"); |
Mark Lobodzinski | a910dc8 | 2015-05-14 14:30:48 -0500 | [diff] [blame] | 176 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 177 | this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 178 | this->app_info.pNext = NULL; |
| 179 | this->app_info.pAppName = "layer_tests"; |
| 180 | this->app_info.appVersion = 1; |
| 181 | this->app_info.pEngineName = "unittest"; |
| 182 | this->app_info.engineVersion = 1; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 183 | this->app_info.apiVersion = VK_API_VERSION; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 184 | |
Tony Barbour | 0c1bdc6 | 2015-04-29 17:34:29 -0600 | [diff] [blame] | 185 | m_errorMonitor = new ErrorMonitor; |
| 186 | InitFramework(extensions, myDbgFunc, m_errorMonitor); |
| 187 | |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | virtual void TearDown() { |
| 191 | // Clean up resources before we reset |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 192 | ShutdownFramework(); |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 193 | delete m_errorMonitor; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 194 | } |
| 195 | }; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 196 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 197 | VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer) |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 198 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 199 | VkResult result; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 200 | |
| 201 | result = cmdBuffer.BeginCommandBuffer(); |
| 202 | |
| 203 | /* |
| 204 | * For render test all drawing happens in a single render pass |
| 205 | * on a single command buffer. |
| 206 | */ |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 207 | if (VK_SUCCESS == result) { |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 208 | cmdBuffer.BeginRenderPass(renderPass(), framebuffer()); |
| 209 | } |
| 210 | |
| 211 | return result; |
| 212 | } |
| 213 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 214 | VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer) |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 215 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 216 | VkResult result; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 217 | |
| 218 | cmdBuffer.EndRenderPass(renderPass()); |
| 219 | |
| 220 | result = cmdBuffer.EndCommandBuffer(); |
| 221 | |
| 222 | return result; |
| 223 | } |
| 224 | |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 225 | void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) |
| 226 | { |
| 227 | // Create identity matrix |
| 228 | int i; |
| 229 | struct vktriangle_vs_uniform data; |
| 230 | |
| 231 | glm::mat4 Projection = glm::mat4(1.0f); |
| 232 | glm::mat4 View = glm::mat4(1.0f); |
| 233 | glm::mat4 Model = glm::mat4(1.0f); |
| 234 | glm::mat4 MVP = Projection * View * Model; |
| 235 | const int matrixSize = sizeof(MVP); |
| 236 | const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float); |
| 237 | |
| 238 | memcpy(&data.mvp, &MVP[0][0], matrixSize); |
| 239 | |
| 240 | static const Vertex tri_data[] = |
| 241 | { |
| 242 | { XYZ1( -1, -1, 0 ), XYZ1( 1.f, 0.f, 0.f ) }, |
| 243 | { XYZ1( 1, -1, 0 ), XYZ1( 0.f, 1.f, 0.f ) }, |
| 244 | { XYZ1( 0, 1, 0 ), XYZ1( 0.f, 0.f, 1.f ) }, |
| 245 | }; |
| 246 | |
| 247 | for (i=0; i<3; i++) { |
| 248 | data.position[i][0] = tri_data[i].posX; |
| 249 | data.position[i][1] = tri_data[i].posY; |
| 250 | data.position[i][2] = tri_data[i].posZ; |
| 251 | data.position[i][3] = tri_data[i].posW; |
| 252 | data.color[i][0] = tri_data[i].r; |
| 253 | data.color[i][1] = tri_data[i].g; |
| 254 | data.color[i][2] = tri_data[i].b; |
| 255 | data.color[i][3] = tri_data[i].a; |
| 256 | } |
| 257 | |
| 258 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 259 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 260 | |
| 261 | VkConstantBufferObj constantBuffer(m_device, bufSize*2, sizeof(float), (const void*) &data); |
| 262 | |
| 263 | VkShaderObj vs(m_device,vertShaderText,VK_SHADER_STAGE_VERTEX, this); |
| 264 | VkShaderObj ps(m_device,fragShaderText, VK_SHADER_STAGE_FRAGMENT, this); |
| 265 | |
| 266 | VkPipelineObj pipelineobj(m_device); |
| 267 | pipelineobj.AddShader(&vs); |
| 268 | pipelineobj.AddShader(&ps); |
| 269 | |
| 270 | VkDescriptorSetObj descriptorSet(m_device); |
| 271 | descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer); |
| 272 | |
| 273 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 274 | VkCommandBufferObj cmdBuffer(m_device); |
| 275 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
| 276 | |
| 277 | ASSERT_VK_SUCCESS(BeginCommandBuffer(cmdBuffer)); |
| 278 | |
| 279 | GenericDrawPreparation(&cmdBuffer, pipelineobj, descriptorSet, failMask); |
| 280 | |
| 281 | // render triangle |
| 282 | cmdBuffer.Draw(0, 3, 0, 1); |
| 283 | |
| 284 | // finalize recording of the command buffer |
| 285 | EndCommandBuffer(cmdBuffer); |
| 286 | |
| 287 | cmdBuffer.QueueCommandBuffer(); |
| 288 | } |
| 289 | |
| 290 | void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *cmdBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) |
| 291 | { |
| 292 | if (m_depthStencil->Initialized()) { |
| 293 | cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil); |
| 294 | } else { |
| 295 | cmdBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL); |
| 296 | } |
| 297 | |
| 298 | cmdBuffer->PrepareAttachments(); |
| 299 | if ((failMask & BsoFailRaster) != BsoFailRaster) { |
| 300 | cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_RASTER, m_stateRaster); |
| 301 | } |
| 302 | if ((failMask & BsoFailViewport) != BsoFailViewport) { |
| 303 | cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_VIEWPORT, m_stateViewport); |
| 304 | } |
| 305 | if ((failMask & BsoFailColorBlend) != BsoFailColorBlend) { |
| 306 | cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_COLOR_BLEND, m_colorBlend); |
| 307 | } |
| 308 | if ((failMask & BsoFailDepthStencil) != BsoFailDepthStencil) { |
| 309 | cmdBuffer->BindStateObject(VK_STATE_BIND_POINT_DEPTH_STENCIL, m_stateDepthStencil); |
| 310 | } |
| 311 | descriptorSet.CreateVKDescriptorSet(cmdBuffer); |
| 312 | pipelineobj.CreateVKPipeline(descriptorSet); |
| 313 | cmdBuffer->BindPipeline(pipelineobj); |
| 314 | cmdBuffer->BindDescriptorSet(descriptorSet); |
| 315 | } |
| 316 | |
| 317 | // ******************************************************************************************************************** |
| 318 | // ******************************************************************************************************************** |
| 319 | // ******************************************************************************************************************** |
| 320 | // ******************************************************************************************************************** |
Tobin Ehlis | 57e6a61 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 321 | #if MEM_TRACKER_TESTS |
Mark Lobodzinski | 8107819 | 2015-05-19 10:28:29 -0500 | [diff] [blame] | 322 | TEST_F(VkLayerTest, CallResetCmdBufferBeforeCompletion) |
| 323 | { |
| 324 | vk_testing::Fence testFence; |
| 325 | VK_DBG_MSG_TYPE msgType; |
| 326 | std::string msgString; |
| 327 | |
| 328 | VkFenceCreateInfo fenceInfo = {}; |
| 329 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 330 | fenceInfo.pNext = NULL; |
| 331 | fenceInfo.flags = 0; |
| 332 | |
| 333 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 334 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 335 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 336 | |
| 337 | VkCommandBufferObj cmdBuffer(m_device); |
| 338 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
| 339 | |
| 340 | BeginCommandBuffer(cmdBuffer); |
| 341 | cmdBuffer.ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL); |
| 342 | EndCommandBuffer(cmdBuffer); |
| 343 | |
| 344 | testFence.init(*m_device, fenceInfo); |
| 345 | |
| 346 | // Bypass framework since it does the waits automatically |
| 347 | VkResult err = VK_SUCCESS; |
| 348 | err = vkQueueSubmit( m_device->m_queue, 1, &cmdBuffer.obj(), testFence.obj()); |
| 349 | ASSERT_VK_SUCCESS( err ); |
| 350 | |
| 351 | m_errorMonitor->ClearState(); |
| 352 | // Introduce failure by calling begin again before checking fence |
| 353 | vkResetCommandBuffer(cmdBuffer.obj()); |
| 354 | |
| 355 | msgType = m_errorMonitor->GetState(&msgString); |
| 356 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive an err after calling ResetCommandBuffer on an active Command Buffer"; |
| 357 | if (!strstr(msgString.c_str(),"Resetting CB")) { |
| 358 | FAIL() << "Error received was not 'Resetting CB (0xaddress) before it has completed. You must check CB flag before'"; |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | TEST_F(VkLayerTest, CallBeginCmdBufferBeforeCompletion) |
| 363 | { |
| 364 | vk_testing::Fence testFence; |
| 365 | VK_DBG_MSG_TYPE msgType; |
| 366 | std::string msgString; |
| 367 | |
| 368 | VkFenceCreateInfo fenceInfo = {}; |
| 369 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 370 | fenceInfo.pNext = NULL; |
| 371 | fenceInfo.flags = 0; |
| 372 | |
| 373 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 374 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 375 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 376 | |
| 377 | VkCommandBufferObj cmdBuffer(m_device); |
| 378 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
| 379 | |
| 380 | BeginCommandBuffer(cmdBuffer); |
| 381 | cmdBuffer.ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL); |
| 382 | EndCommandBuffer(cmdBuffer); |
| 383 | |
| 384 | testFence.init(*m_device, fenceInfo); |
| 385 | |
| 386 | // Bypass framework since it does the waits automatically |
| 387 | VkResult err = VK_SUCCESS; |
| 388 | err = vkQueueSubmit( m_device->m_queue, 1, &cmdBuffer.obj(), testFence.obj()); |
| 389 | ASSERT_VK_SUCCESS( err ); |
| 390 | |
| 391 | m_errorMonitor->ClearState(); |
| 392 | // Introduce failure by calling begin again before checking fence |
| 393 | BeginCommandBuffer(cmdBuffer); |
| 394 | |
| 395 | msgType = m_errorMonitor->GetState(&msgString); |
| 396 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive an err after calling BeginCommandBuffer on an active Command Buffer"; |
| 397 | if (!strstr(msgString.c_str(),"Calling vkBeginCommandBuffer() on active CB")) { |
| 398 | FAIL() << "Error received was not 'Calling vkBeginCommandBuffer() on an active CB (0xaddress) before it has completed'"; |
| 399 | } |
| 400 | } |
| 401 | |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 402 | TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) |
| 403 | { |
| 404 | VK_DBG_MSG_TYPE msgType; |
| 405 | std::string msgString; |
| 406 | VkResult err; |
| 407 | |
| 408 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 409 | m_errorMonitor->ClearState(); |
| 410 | |
| 411 | // Create an image, allocate memory, free it, and then try to bind it |
| 412 | VkImage image; |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 413 | VkDeviceMemory mem; |
| 414 | VkMemoryRequirements mem_reqs; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 415 | |
| 416 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 417 | const int32_t tex_width = 32; |
| 418 | const int32_t tex_height = 32; |
| 419 | size_t mem_reqs_size = sizeof(VkMemoryRequirements); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 420 | |
| 421 | const VkImageCreateInfo image_create_info = { |
| 422 | .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, |
| 423 | .pNext = NULL, |
| 424 | .imageType = VK_IMAGE_TYPE_2D, |
| 425 | .format = tex_format, |
| 426 | .extent = { tex_width, tex_height, 1 }, |
| 427 | .mipLevels = 1, |
| 428 | .arraySize = 1, |
| 429 | .samples = 1, |
| 430 | .tiling = VK_IMAGE_TILING_LINEAR, |
| 431 | .usage = VK_IMAGE_USAGE_SAMPLED_BIT, |
| 432 | .flags = 0, |
| 433 | }; |
| 434 | VkMemoryAllocInfo mem_alloc = { |
| 435 | .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO, |
| 436 | .pNext = NULL, |
| 437 | .allocationSize = 0, |
| 438 | // Introduce failure, do NOT set memProps to VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
| 439 | .memProps = 0, |
| 440 | .memPriority = VK_MEMORY_PRIORITY_NORMAL, |
| 441 | }; |
| 442 | |
| 443 | err = vkCreateImage(m_device->device(), &image_create_info, &image); |
| 444 | ASSERT_VK_SUCCESS(err); |
| 445 | |
| 446 | err = vkGetObjectInfo(m_device->device(), |
| 447 | VK_OBJECT_TYPE_IMAGE, |
| 448 | image, |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 449 | VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS, |
| 450 | &mem_reqs_size, |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 451 | &mem_reqs); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 452 | ASSERT_VK_SUCCESS(err); |
| 453 | |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 454 | mem_alloc.allocationSize = mem_reqs.size; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 455 | |
| 456 | // allocate memory |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 457 | err = vkAllocMemory(m_device->device(), &mem_alloc, &mem); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 458 | ASSERT_VK_SUCCESS(err); |
| 459 | |
| 460 | // Try to bind free memory that has been freed |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 461 | err = vkBindObjectMemory(m_device->device(), VK_OBJECT_TYPE_IMAGE, image, mem, 0); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 462 | ASSERT_VK_SUCCESS(err); |
| 463 | |
| 464 | // Map memory as if to initialize the image |
| 465 | void *mappedAddress = NULL; |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 466 | err = vkMapMemory(m_device->device(), mem, 0, 0, 0, &mappedAddress); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 467 | |
| 468 | msgType = m_errorMonitor->GetState(&msgString); |
| 469 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive an error while tring to map memory not visible to CPU"; |
| 470 | if (!strstr(msgString.c_str(),"Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT")) { |
| 471 | FAIL() << "Error received did not match expected error message from vkMapMemory in MemTracker"; |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | TEST_F(VkLayerTest, BindInvalidMemory) |
| 476 | { |
| 477 | VK_DBG_MSG_TYPE msgType; |
| 478 | std::string msgString; |
| 479 | VkResult err; |
| 480 | |
| 481 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 482 | m_errorMonitor->ClearState(); |
| 483 | |
| 484 | // Create an image, allocate memory, free it, and then try to bind it |
| 485 | VkImage image; |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 486 | VkDeviceMemory mem; |
| 487 | VkMemoryRequirements mem_reqs; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 488 | |
| 489 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 490 | const int32_t tex_width = 32; |
| 491 | const int32_t tex_height = 32; |
| 492 | size_t mem_reqs_size = sizeof(VkMemoryRequirements); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 493 | |
| 494 | const VkImageCreateInfo image_create_info = { |
| 495 | .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, |
| 496 | .pNext = NULL, |
| 497 | .imageType = VK_IMAGE_TYPE_2D, |
| 498 | .format = tex_format, |
| 499 | .extent = { tex_width, tex_height, 1 }, |
| 500 | .mipLevels = 1, |
| 501 | .arraySize = 1, |
| 502 | .samples = 1, |
| 503 | .tiling = VK_IMAGE_TILING_LINEAR, |
| 504 | .usage = VK_IMAGE_USAGE_SAMPLED_BIT, |
| 505 | .flags = 0, |
| 506 | }; |
| 507 | VkMemoryAllocInfo mem_alloc = { |
| 508 | .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO, |
| 509 | .pNext = NULL, |
| 510 | .allocationSize = 0, |
| 511 | .memProps = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, |
| 512 | .memPriority = VK_MEMORY_PRIORITY_NORMAL, |
| 513 | }; |
| 514 | |
| 515 | err = vkCreateImage(m_device->device(), &image_create_info, &image); |
| 516 | ASSERT_VK_SUCCESS(err); |
| 517 | |
| 518 | err = vkGetObjectInfo(m_device->device(), |
| 519 | VK_OBJECT_TYPE_IMAGE, |
| 520 | image, |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 521 | VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS, |
| 522 | &mem_reqs_size, |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 523 | &mem_reqs); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 524 | ASSERT_VK_SUCCESS(err); |
| 525 | |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 526 | mem_alloc.allocationSize = mem_reqs.size; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 527 | |
| 528 | // allocate memory |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 529 | err = vkAllocMemory(m_device->device(), &mem_alloc, &mem); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 530 | ASSERT_VK_SUCCESS(err); |
| 531 | |
| 532 | // Introduce validation failure, free memory before binding |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 533 | vkFreeMemory(m_device->device(), mem); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 534 | ASSERT_VK_SUCCESS(err); |
| 535 | |
| 536 | // Try to bind free memory that has been freed |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 537 | err = vkBindObjectMemory(m_device->device(), VK_OBJECT_TYPE_IMAGE, image, mem, 0); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 538 | ASSERT_VK_SUCCESS(err); |
| 539 | |
| 540 | msgType = m_errorMonitor->GetState(&msgString); |
| 541 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive an error while tring to bind a freed memory object"; |
| 542 | if (!strstr(msgString.c_str(),"Unable to set object")) { |
| 543 | FAIL() << "Error received did not match expected error message from BindObjectMemory in MemTracker"; |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | TEST_F(VkLayerTest, FreeBoundMemory) |
| 548 | { |
| 549 | VK_DBG_MSG_TYPE msgType; |
| 550 | std::string msgString; |
| 551 | VkResult err; |
| 552 | |
| 553 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 554 | m_errorMonitor->ClearState(); |
| 555 | |
| 556 | // Create an image, allocate memory, free it, and then try to bind it |
| 557 | VkImage image; |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 558 | VkDeviceMemory mem; |
| 559 | VkMemoryRequirements mem_reqs; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 560 | |
| 561 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 562 | const int32_t tex_width = 32; |
| 563 | const int32_t tex_height = 32; |
| 564 | size_t mem_reqs_size = sizeof(VkMemoryRequirements); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 565 | |
| 566 | const VkImageCreateInfo image_create_info = { |
| 567 | .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, |
| 568 | .pNext = NULL, |
| 569 | .imageType = VK_IMAGE_TYPE_2D, |
| 570 | .format = tex_format, |
| 571 | .extent = { tex_width, tex_height, 1 }, |
| 572 | .mipLevels = 1, |
| 573 | .arraySize = 1, |
| 574 | .samples = 1, |
| 575 | .tiling = VK_IMAGE_TILING_LINEAR, |
| 576 | .usage = VK_IMAGE_USAGE_SAMPLED_BIT, |
| 577 | .flags = 0, |
| 578 | }; |
| 579 | VkMemoryAllocInfo mem_alloc = { |
| 580 | .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO, |
| 581 | .pNext = NULL, |
| 582 | .allocationSize = 0, |
| 583 | .memProps = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, |
| 584 | .memPriority = VK_MEMORY_PRIORITY_NORMAL, |
| 585 | }; |
| 586 | |
| 587 | err = vkCreateImage(m_device->device(), &image_create_info, &image); |
| 588 | ASSERT_VK_SUCCESS(err); |
| 589 | |
| 590 | err = vkGetObjectInfo(m_device->device(), |
| 591 | VK_OBJECT_TYPE_IMAGE, |
| 592 | image, |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 593 | VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS, |
| 594 | &mem_reqs_size, |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 595 | &mem_reqs); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 596 | ASSERT_VK_SUCCESS(err); |
| 597 | |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 598 | mem_alloc.allocationSize = mem_reqs.size; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 599 | |
| 600 | // allocate memory |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 601 | err = vkAllocMemory(m_device->device(), &mem_alloc, &mem); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 602 | ASSERT_VK_SUCCESS(err); |
| 603 | |
| 604 | // Bind memory to Image object |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 605 | err = vkBindObjectMemory(m_device->device(), VK_OBJECT_TYPE_IMAGE, image, mem, 0); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 606 | ASSERT_VK_SUCCESS(err); |
| 607 | |
| 608 | // Introduce validation failure, free memory while still bound to object |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 609 | vkFreeMemory(m_device->device(), mem); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 610 | ASSERT_VK_SUCCESS(err); |
| 611 | |
| 612 | msgType = m_errorMonitor->GetState(&msgString); |
| 613 | ASSERT_EQ(msgType, VK_DBG_MSG_WARNING) << "Did not receive an warning while tring to free bound memory"; |
| 614 | if (!strstr(msgString.c_str(),"Freeing memory object while it still has references")) { |
| 615 | FAIL() << "Warning received did not match expected message from freeMemObjInfo in MemTracker"; |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | |
| 620 | TEST_F(VkLayerTest, BindMemoryToDestroyedObject) |
| 621 | { |
| 622 | VK_DBG_MSG_TYPE msgType; |
| 623 | std::string msgString; |
| 624 | VkResult err; |
| 625 | |
| 626 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 627 | m_errorMonitor->ClearState(); |
| 628 | |
| 629 | // Create an image object, allocate memory, destroy the object and then try to bind it |
| 630 | VkImage image; |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 631 | VkDeviceMemory mem; |
| 632 | VkMemoryRequirements mem_reqs; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 633 | |
| 634 | const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM; |
| 635 | const int32_t tex_width = 32; |
| 636 | const int32_t tex_height = 32; |
| 637 | size_t mem_reqs_size = sizeof(VkMemoryRequirements); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 638 | |
| 639 | const VkImageCreateInfo image_create_info = { |
| 640 | .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, |
| 641 | .pNext = NULL, |
| 642 | .imageType = VK_IMAGE_TYPE_2D, |
| 643 | .format = tex_format, |
| 644 | .extent = { tex_width, tex_height, 1 }, |
| 645 | .mipLevels = 1, |
| 646 | .arraySize = 1, |
| 647 | .samples = 1, |
| 648 | .tiling = VK_IMAGE_TILING_LINEAR, |
| 649 | .usage = VK_IMAGE_USAGE_SAMPLED_BIT, |
| 650 | .flags = 0, |
| 651 | }; |
| 652 | VkMemoryAllocInfo mem_alloc = { |
| 653 | .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO, |
| 654 | .pNext = NULL, |
| 655 | .allocationSize = 0, |
| 656 | .memProps = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, |
| 657 | .memPriority = VK_MEMORY_PRIORITY_NORMAL, |
| 658 | }; |
| 659 | |
| 660 | err = vkCreateImage(m_device->device(), &image_create_info, &image); |
| 661 | ASSERT_VK_SUCCESS(err); |
| 662 | |
| 663 | err = vkGetObjectInfo(m_device->device(), |
| 664 | VK_OBJECT_TYPE_IMAGE, |
| 665 | image, |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 666 | VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS, |
| 667 | &mem_reqs_size, |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 668 | &mem_reqs); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 669 | ASSERT_VK_SUCCESS(err); |
| 670 | |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 671 | mem_alloc.allocationSize = mem_reqs.size; |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 672 | |
| 673 | // Allocate memory |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 674 | err = vkAllocMemory(m_device->device(), &mem_alloc, &mem); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 675 | ASSERT_VK_SUCCESS(err); |
| 676 | |
| 677 | // Introduce validation failure, destroy Image object before binding |
| 678 | vkDestroyObject(m_device->device(), VK_OBJECT_TYPE_IMAGE, image); |
| 679 | ASSERT_VK_SUCCESS(err); |
| 680 | |
| 681 | // Now Try to bind memory to this destroyted object |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 682 | err = vkBindObjectMemory(m_device->device(), VK_OBJECT_TYPE_IMAGE, image, mem, 0); |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 683 | ASSERT_VK_SUCCESS(err); |
| 684 | |
| 685 | msgType = m_errorMonitor->GetState(&msgString); |
| 686 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive an error while binding memory to a destroyed object"; |
| 687 | if (!strstr(msgString.c_str(),"Unable to set object")) { |
| 688 | FAIL() << "Error received did not match expected error message from updateObjectBinding in MemTracker"; |
| 689 | } |
| 690 | } |
| 691 | |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 692 | TEST_F(VkLayerTest, SubmitSignaledFence) |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 693 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 694 | vk_testing::Fence testFence; |
| 695 | VK_DBG_MSG_TYPE msgType; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 696 | std::string msgString; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 697 | |
| 698 | VkFenceCreateInfo fenceInfo = {}; |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 699 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 700 | fenceInfo.pNext = NULL; |
| 701 | fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 702 | |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 703 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 704 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 705 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 706 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 707 | VkCommandBufferObj cmdBuffer(m_device); |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 708 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
| 709 | |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 710 | BeginCommandBuffer(cmdBuffer); |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 711 | 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] | 712 | EndCommandBuffer(cmdBuffer); |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 713 | |
| 714 | testFence.init(*m_device, fenceInfo); |
| 715 | m_errorMonitor->ClearState(); |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 716 | cmdBuffer.QueueCommandBuffer(testFence.obj()); |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 717 | msgType = m_errorMonitor->GetState(&msgString); |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 718 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive an err from using a fence in SIGNALED state in call to vkQueueSubmit"; |
| 719 | 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] | 720 | FAIL() << "Error received was not 'VkQueueSubmit with fence in SIGNALED_STATE'"; |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | } |
| 724 | |
| 725 | TEST_F(VkLayerTest, ResetUnsignaledFence) |
| 726 | { |
| 727 | vk_testing::Fence testFence; |
| 728 | VK_DBG_MSG_TYPE msgType; |
| 729 | std::string msgString; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 730 | VkFenceCreateInfo fenceInfo = {}; |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 731 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 732 | fenceInfo.pNext = NULL; |
| 733 | |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 734 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 735 | testFence.init(*m_device, fenceInfo); |
| 736 | m_errorMonitor->ClearState(); |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 737 | VkFence fences[1] = {testFence.obj()}; |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 738 | vkResetFences(m_device->device(), 1, fences); |
| 739 | msgType = m_errorMonitor->GetState(&msgString); |
| 740 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "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] | 741 | if (!strstr(msgString.c_str(),"submitted to VkResetFences in UNSIGNALED STATE")) { |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 742 | FAIL() << "Error received was not 'VkResetFences with fence in UNSIGNALED_STATE'"; |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 743 | } |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 744 | |
| 745 | } |
Tobin Ehlis | 57e6a61 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 746 | #endif |
| 747 | #if OBJECT_TRACKER_TESTS |
Tony Barbour | 54cdd19 | 2015-04-22 15:12:07 -0600 | [diff] [blame] | 748 | TEST_F(VkLayerTest, WaitForUnsubmittedFence) |
| 749 | { |
| 750 | vk_testing::Fence testFence; |
| 751 | VK_DBG_MSG_TYPE msgType; |
| 752 | std::string msgString; |
| 753 | VkFenceCreateInfo fenceInfo = {}; |
| 754 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 755 | fenceInfo.pNext = NULL; |
| 756 | |
Tony Barbour | 54cdd19 | 2015-04-22 15:12:07 -0600 | [diff] [blame] | 757 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 758 | testFence.init(*m_device, fenceInfo); |
| 759 | m_errorMonitor->ClearState(); |
| 760 | vkGetFenceStatus(m_device->device(),testFence.obj()); |
| 761 | msgType = m_errorMonitor->GetState(&msgString); |
| 762 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive an error asking for status of unsubmitted fence"; |
| 763 | if (!strstr(msgString.c_str(),"Status Requested for Unsubmitted Fence")) { |
| 764 | FAIL() << "Error received was not Status Requested for Unsubmitted Fence"; |
| 765 | } |
| 766 | |
| 767 | VkFence fences[1] = {testFence.obj()}; |
| 768 | m_errorMonitor->ClearState(); |
| 769 | vkWaitForFences(m_device->device(), 1, fences, VK_TRUE, 0); |
| 770 | msgType = m_errorMonitor->GetState(&msgString); |
| 771 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive an error for waiting for unsubmitted fence"; |
| 772 | if (!strstr(msgString.c_str(),"Waiting for Unsubmitted Fence")) { |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 773 | FAIL() << "Error received was not 'Waiting for Unsubmitted Fence'"; |
Tony Barbour | 54cdd19 | 2015-04-22 15:12:07 -0600 | [diff] [blame] | 774 | } |
| 775 | } |
| 776 | |
Tony Barbour | db68662 | 2015-05-06 09:35:56 -0600 | [diff] [blame] | 777 | TEST_F(VkLayerTest, GetObjectInfoMismatchedType) |
| 778 | { |
| 779 | VkEventCreateInfo event_info; |
| 780 | VkEvent event; |
| 781 | VkMemoryRequirements mem_req; |
| 782 | size_t data_size = sizeof(mem_req); |
| 783 | VK_DBG_MSG_TYPE msgType; |
| 784 | std::string msgString; |
| 785 | VkResult err; |
| 786 | |
| 787 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 788 | memset(&event_info, 0, sizeof(event_info)); |
| 789 | event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 790 | |
| 791 | err = vkCreateEvent(device(), &event_info, &event); |
| 792 | ASSERT_VK_SUCCESS(err); |
| 793 | m_errorMonitor->ClearState(); |
| 794 | err = vkGetObjectInfo(device(), VK_OBJECT_TYPE_IMAGE, event, VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS, |
| 795 | &data_size, &mem_req); |
| 796 | msgType = m_errorMonitor->GetState(&msgString); |
| 797 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive an error from mismatched types in vkGetObjectInfo"; |
| 798 | if (!strstr(msgString.c_str(),"does not match designated type")) { |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 799 | FAIL() << "Error received was not 'does not match designated type'"; |
Tony Barbour | db68662 | 2015-05-06 09:35:56 -0600 | [diff] [blame] | 800 | } |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 801 | } |
Tony Barbour | db68662 | 2015-05-06 09:35:56 -0600 | [diff] [blame] | 802 | |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 803 | TEST_F(VkLayerTest, RasterStateNotBound) |
| 804 | { |
| 805 | VK_DBG_MSG_TYPE msgType; |
| 806 | std::string msgString; |
| 807 | |
| 808 | TEST_DESCRIPTION("Simple Draw Call that validates failure when a raster state object is not bound beforehand"); |
| 809 | |
| 810 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailRaster); |
| 811 | |
| 812 | msgType = m_errorMonitor->GetState(&msgString); |
| 813 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive an error from Not Binding a Raster State Object"; |
| 814 | if (!strstr(msgString.c_str(),"Raster object not bound to this command buffer")) { |
| 815 | FAIL() << "Error received was not 'Raster object not bound to this command buffer'"; |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | TEST_F(VkLayerTest, ViewportStateNotBound) |
| 820 | { |
| 821 | VK_DBG_MSG_TYPE msgType; |
| 822 | std::string msgString; |
| 823 | TEST_DESCRIPTION("Simple Draw Call that validates failure when a viewport state object is not bound beforehand"); |
| 824 | |
| 825 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport); |
| 826 | |
| 827 | msgType = m_errorMonitor->GetState(&msgString); |
| 828 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive an error from Not Binding a Viewport State Object"; |
| 829 | if (!strstr(msgString.c_str(),"Viewport object not bound to this command buffer")) { |
| 830 | FAIL() << "Error received was not 'Viewport object not bound to this command buffer'"; |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | TEST_F(VkLayerTest, ColorBlendStateNotBound) |
| 835 | { |
| 836 | VK_DBG_MSG_TYPE msgType; |
| 837 | std::string msgString; |
| 838 | |
| 839 | TEST_DESCRIPTION("Simple Draw Call that validates failure when a color-blend state object is not bound beforehand"); |
| 840 | |
| 841 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailColorBlend); |
| 842 | |
| 843 | msgType = m_errorMonitor->GetState(&msgString); |
| 844 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive an error from Not Binding a ColorBlend State Object"; |
| 845 | if (!strstr(msgString.c_str(),"Color-blend object not bound to this command buffer")) { |
| 846 | FAIL() << "Error received was not 'Color-blend object not bound to this command buffer'"; |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | TEST_F(VkLayerTest, DepthStencilStateNotBound) |
| 851 | { |
| 852 | VK_DBG_MSG_TYPE msgType; |
| 853 | std::string msgString; |
| 854 | |
| 855 | TEST_DESCRIPTION("Simple Draw Call that validates failure when a depth-stencil state object is not bound beforehand"); |
| 856 | |
| 857 | VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthStencil); |
| 858 | |
| 859 | msgType = m_errorMonitor->GetState(&msgString); |
| 860 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive an error from Not Binding a DepthStencil State Object"; |
| 861 | if (!strstr(msgString.c_str(),"Depth-stencil object not bound to this command buffer")) { |
| 862 | FAIL() << "Error received was not 'Depth-stencil object not bound to this command buffer'"; |
| 863 | } |
Tony Barbour | db68662 | 2015-05-06 09:35:56 -0600 | [diff] [blame] | 864 | } |
Tobin Ehlis | 57e6a61 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 865 | #endif |
| 866 | #if DRAW_STATE_TESTS |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 867 | TEST_F(VkLayerTest, PipelineNotBound) |
| 868 | { |
| 869 | // Initiate Draw w/o a PSO bound |
Tobin Ehlis | 6bdfa37 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 870 | VK_DBG_MSG_TYPE msgType; |
| 871 | std::string msgString; |
| 872 | |
| 873 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 874 | m_errorMonitor->ClearState(); |
| 875 | VkCommandBufferObj cmdBuffer(m_device); |
| 876 | BeginCommandBuffer(cmdBuffer); |
| 877 | VkPipeline badPipeline = (VkPipeline)0xbaadb1be; |
| 878 | vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline); |
| 879 | msgType = m_errorMonitor->GetState(&msgString); |
| 880 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive error after binding invalid pipeline to CmdBuffer"; |
| 881 | if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) { |
| 882 | FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'"; |
| 883 | } |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | TEST_F(VkLayerTest, InvalidDescriptorPool) |
| 887 | { |
| 888 | // TODO : Simple check for bad object should be added to ObjectTracker to catch this case |
| 889 | // The DS check for this is after driver has been called to validate DS internal data struct |
| 890 | // Attempt to clear DS Pool with bad object |
| 891 | /* VK_DBG_MSG_TYPE msgType; |
| 892 | std::string msgString; |
| 893 | VkDescriptorPool badPool = (VkDescriptorPool)0xbaad6001; |
| 894 | vkResetDescriptorPool(device(), badPool); |
| 895 | |
| 896 | msgType = m_errorMonitor->GetState(&msgString); |
| 897 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive an error from Resetting an invalid DescriptorPool Object"; |
| 898 | if (!strstr(msgString.c_str(),"Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call")) { |
| 899 | FAIL() << "Error received was note 'Unable to find pool node for pool 0xbaad6001 specified in vkResetDescriptorPool() call'"; |
| 900 | }*/ |
| 901 | } |
| 902 | |
| 903 | TEST_F(VkLayerTest, InvalidDescriptorSet) |
| 904 | { |
Tobin Ehlis | 6bdfa37 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 905 | // TODO : Simple check for bad object should be added to ObjectTracker to catch this case |
| 906 | // 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] | 907 | // Create a valid cmd buffer |
| 908 | // call vkCmdBindDescriptorSets w/ false DS |
| 909 | } |
| 910 | |
| 911 | TEST_F(VkLayerTest, InvalidDescriptorSetLayout) |
| 912 | { |
| 913 | // TODO : Simple check for bad object should be added to ObjectTracker to catch this case |
| 914 | // The DS check for this is after driver has been called to validate DS internal data struct |
| 915 | } |
| 916 | |
| 917 | TEST_F(VkLayerTest, InvalidPipeline) |
| 918 | { |
Tobin Ehlis | 6bdfa37 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 919 | // TODO : Simple check for bad object should be added to ObjectTracker to catch this case |
| 920 | // 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] | 921 | // Create a valid cmd buffer |
| 922 | // call vkCmdBindPipeline w/ false Pipeline |
Tobin Ehlis | 57e6a61 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 923 | VK_DBG_MSG_TYPE msgType; |
| 924 | std::string msgString; |
| 925 | |
| 926 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 927 | m_errorMonitor->ClearState(); |
| 928 | VkCommandBufferObj cmdBuffer(m_device); |
| 929 | BeginCommandBuffer(cmdBuffer); |
| 930 | VkPipeline badPipeline = (VkPipeline)0xbaadb1be; |
| 931 | vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline); |
| 932 | msgType = m_errorMonitor->GetState(&msgString); |
| 933 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive error after binding invalid pipeline to CmdBuffer"; |
| 934 | if (!strstr(msgString.c_str(),"Attempt to bind Pipeline ")) { |
| 935 | FAIL() << "Error received was not 'Attempt to bind Pipeline 0xbaadb1be that doesn't exist!'"; |
| 936 | } |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 937 | } |
| 938 | |
Tobin Ehlis | 6bdfa37 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 939 | TEST_F(VkLayerTest, NoEndCmdBuffer) |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 940 | { |
Tobin Ehlis | 6bdfa37 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 941 | // Create and update CmdBuffer then call QueueSubmit w/o calling End on CmdBuffer |
| 942 | VK_DBG_MSG_TYPE msgType; |
| 943 | std::string msgString; |
| 944 | VkResult err; |
| 945 | |
| 946 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 947 | m_errorMonitor->ClearState(); |
| 948 | VkCommandBufferObj cmdBuffer(m_device); |
| 949 | const VkDescriptorTypeCount ds_type_count = { |
| 950 | .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, |
| 951 | .count = 1, |
| 952 | }; |
| 953 | const VkDescriptorPoolCreateInfo ds_pool_ci = { |
| 954 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, |
| 955 | .pNext = NULL, |
| 956 | .count = 1, |
| 957 | .pTypeCount = &ds_type_count, |
| 958 | }; |
| 959 | VkDescriptorPool ds_pool; |
| 960 | err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool); |
| 961 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 6bdfa37 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 962 | |
| 963 | const VkDescriptorSetLayoutBinding dsl_binding = { |
| 964 | .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, |
Chia-I Wu | d3114a2 | 2015-05-25 16:22:52 +0800 | [diff] [blame] | 965 | .arraySize = 1, |
Tobin Ehlis | 6bdfa37 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 966 | .stageFlags = VK_SHADER_STAGE_ALL, |
| 967 | .pImmutableSamplers = NULL, |
| 968 | }; |
| 969 | |
| 970 | const VkDescriptorSetLayoutCreateInfo ds_layout_ci = { |
| 971 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, |
| 972 | .pNext = NULL, |
| 973 | .count = 1, |
| 974 | .pBinding = &dsl_binding, |
| 975 | }; |
| 976 | VkDescriptorSetLayout ds_layout; |
| 977 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout); |
| 978 | ASSERT_VK_SUCCESS(err); |
| 979 | |
| 980 | VkDescriptorSet descriptorSet; |
| 981 | uint32_t ds_count = 0; |
| 982 | err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count); |
| 983 | ASSERT_VK_SUCCESS(err); |
| 984 | |
| 985 | const VkPipelineLayoutCreateInfo pipeline_layout_ci = { |
| 986 | .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, |
| 987 | .pNext = NULL, |
| 988 | .descriptorSetCount = 1, |
| 989 | .pSetLayouts = &ds_layout, |
| 990 | }; |
| 991 | |
| 992 | VkPipelineLayout pipeline_layout; |
| 993 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout); |
| 994 | ASSERT_VK_SUCCESS(err); |
| 995 | |
| 996 | size_t shader_len = strlen(bindStateVertShaderText); |
| 997 | size_t codeSize = 3 * sizeof(uint32_t) + shader_len + 1; |
| 998 | void* pCode = malloc(codeSize); |
| 999 | |
| 1000 | /* try version 0 first: VkShaderStage followed by GLSL */ |
| 1001 | ((uint32_t *) pCode)[0] = ICD_SPV_MAGIC; |
| 1002 | ((uint32_t *) pCode)[1] = 0; |
| 1003 | ((uint32_t *) pCode)[2] = VK_SHADER_STAGE_VERTEX; |
| 1004 | memcpy(((uint32_t *) pCode + 3), bindStateVertShaderText, shader_len + 1); |
| 1005 | |
| 1006 | const VkShaderCreateInfo vs_ci = { |
| 1007 | .sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO, |
| 1008 | .pNext = NULL, |
| 1009 | .codeSize = codeSize, |
| 1010 | .pCode = pCode, |
| 1011 | .flags = 0, |
| 1012 | }; |
| 1013 | VkShader vs; |
| 1014 | err = vkCreateShader(m_device->device(), &vs_ci, &vs); |
| 1015 | ASSERT_VK_SUCCESS(err); |
| 1016 | |
| 1017 | const VkPipelineShader vs_pipe_shader = { |
| 1018 | .stage = VK_SHADER_STAGE_VERTEX, |
| 1019 | .shader = vs, |
| 1020 | .linkConstBufferCount = 0, |
| 1021 | .pLinkConstBufferInfo = NULL, |
| 1022 | .pSpecializationInfo = NULL, |
| 1023 | }; |
| 1024 | const VkPipelineShaderStageCreateInfo pipe_vs_ci = { |
| 1025 | .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 1026 | .pNext = NULL, |
| 1027 | .shader = vs_pipe_shader, |
| 1028 | }; |
| 1029 | const VkGraphicsPipelineCreateInfo gp_ci = { |
| 1030 | .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, |
| 1031 | .pNext = &pipe_vs_ci, |
| 1032 | .flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT, |
| 1033 | .layout = pipeline_layout, |
| 1034 | }; |
| 1035 | |
| 1036 | VkPipeline pipeline; |
| 1037 | err = vkCreateGraphicsPipeline(m_device->device(), &gp_ci, &pipeline); |
| 1038 | ASSERT_VK_SUCCESS(err); |
| 1039 | |
| 1040 | vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 1041 | vkCmdBindDescriptorSets(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, 0, 1, &descriptorSet, 0, NULL); |
| 1042 | |
| 1043 | VkCmdBuffer localCmdBuffer = cmdBuffer.GetBufferHandle(); |
| 1044 | m_device->get_device_queue(); |
| 1045 | vkQueueSubmit(m_device->m_queue, 1, &localCmdBuffer, NULL); |
| 1046 | |
| 1047 | msgType = m_errorMonitor->GetState(&msgString); |
| 1048 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive error after vkEndDescriptorPoolUpdate() w/o first calling vkBeginDescriptorPoolUpdate()."; |
| 1049 | if (!strstr(msgString.c_str(),"You must call vkEndCommandBuffer() on CB ")) { |
| 1050 | FAIL() << "Error received was not 'You must call vkEndCommandBuffer() on CB <0xblah> before this call to vkQueueSubmit()!'"; |
| 1051 | } |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | TEST_F(VkLayerTest, InvalidDynamicStateObject) |
| 1055 | { |
| 1056 | // Create a valid cmd buffer |
| 1057 | // call vkCmdBindDynamicStateObject w/ false DS Obj |
Tobin Ehlis | 6bdfa37 | 2015-05-27 14:32:28 -0600 | [diff] [blame] | 1058 | // TODO : Simple check for bad object should be added to ObjectTracker to catch this case |
| 1059 | // 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] | 1060 | } |
Tobin Ehlis | 201b1ba | 2015-05-27 14:55:35 -0600 | [diff] [blame] | 1061 | |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 1062 | TEST_F(VkLayerTest, VtxBufferBadIndex) |
| 1063 | { |
| 1064 | // Bind VBO out-of-bounds for given PSO |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1065 | VK_DBG_MSG_TYPE msgType; |
| 1066 | std::string msgString; |
| 1067 | VkResult err; |
| 1068 | |
| 1069 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1070 | m_errorMonitor->ClearState(); |
| 1071 | VkCommandBufferObj cmdBuffer(m_device); |
| 1072 | const VkDescriptorTypeCount ds_type_count = { |
| 1073 | .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, |
| 1074 | .count = 1, |
| 1075 | }; |
| 1076 | const VkDescriptorPoolCreateInfo ds_pool_ci = { |
| 1077 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, |
| 1078 | .pNext = NULL, |
| 1079 | .count = 1, |
| 1080 | .pTypeCount = &ds_type_count, |
| 1081 | }; |
| 1082 | VkDescriptorPool ds_pool; |
| 1083 | err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool); |
| 1084 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1085 | |
| 1086 | const VkDescriptorSetLayoutBinding dsl_binding = { |
| 1087 | .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, |
Chia-I Wu | d3114a2 | 2015-05-25 16:22:52 +0800 | [diff] [blame] | 1088 | .arraySize = 1, |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1089 | .stageFlags = VK_SHADER_STAGE_ALL, |
| 1090 | .pImmutableSamplers = NULL, |
| 1091 | }; |
| 1092 | |
| 1093 | const VkDescriptorSetLayoutCreateInfo ds_layout_ci = { |
| 1094 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, |
| 1095 | .pNext = NULL, |
| 1096 | .count = 1, |
| 1097 | .pBinding = &dsl_binding, |
| 1098 | }; |
| 1099 | VkDescriptorSetLayout ds_layout; |
| 1100 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout); |
| 1101 | ASSERT_VK_SUCCESS(err); |
| 1102 | |
| 1103 | VkDescriptorSet descriptorSet; |
| 1104 | uint32_t ds_count = 0; |
| 1105 | err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count); |
| 1106 | ASSERT_VK_SUCCESS(err); |
| 1107 | |
| 1108 | const VkPipelineLayoutCreateInfo pipeline_layout_ci = { |
| 1109 | .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, |
| 1110 | .pNext = NULL, |
| 1111 | .descriptorSetCount = 1, |
| 1112 | .pSetLayouts = &ds_layout, |
| 1113 | }; |
| 1114 | |
| 1115 | VkPipelineLayout pipeline_layout; |
| 1116 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout); |
| 1117 | ASSERT_VK_SUCCESS(err); |
| 1118 | |
| 1119 | size_t shader_len = strlen(bindStateVertShaderText); |
| 1120 | size_t codeSize = 3 * sizeof(uint32_t) + shader_len + 1; |
| 1121 | void* pCode = malloc(codeSize); |
| 1122 | |
| 1123 | /* try version 0 first: VkShaderStage followed by GLSL */ |
| 1124 | ((uint32_t *) pCode)[0] = ICD_SPV_MAGIC; |
| 1125 | ((uint32_t *) pCode)[1] = 0; |
| 1126 | ((uint32_t *) pCode)[2] = VK_SHADER_STAGE_VERTEX; |
| 1127 | memcpy(((uint32_t *) pCode + 3), bindStateVertShaderText, shader_len + 1); |
| 1128 | |
| 1129 | const VkShaderCreateInfo vs_ci = { |
| 1130 | .sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO, |
| 1131 | .pNext = NULL, |
| 1132 | .codeSize = codeSize, |
| 1133 | .pCode = pCode, |
| 1134 | .flags = 0, |
| 1135 | }; |
| 1136 | VkShader vs; |
| 1137 | err = vkCreateShader(m_device->device(), &vs_ci, &vs); |
| 1138 | |
| 1139 | const VkPipelineShader vs_pipe_shader = { |
| 1140 | .stage = VK_SHADER_STAGE_VERTEX, |
| 1141 | .shader = vs, |
| 1142 | .linkConstBufferCount = 0, |
| 1143 | .pLinkConstBufferInfo = NULL, |
| 1144 | .pSpecializationInfo = NULL, |
| 1145 | }; |
| 1146 | const VkPipelineShaderStageCreateInfo pipe_vs_ci = { |
| 1147 | .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 1148 | .pNext = NULL, |
| 1149 | .shader = vs_pipe_shader, |
| 1150 | }; |
| 1151 | const VkGraphicsPipelineCreateInfo gp_ci = { |
| 1152 | .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, |
| 1153 | .pNext = &pipe_vs_ci, |
| 1154 | .flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT, |
| 1155 | .layout = pipeline_layout, |
| 1156 | }; |
| 1157 | |
| 1158 | VkPipeline pipeline; |
| 1159 | err = vkCreateGraphicsPipeline(m_device->device(), &gp_ci, &pipeline); |
| 1160 | ASSERT_VK_SUCCESS(err); |
| 1161 | |
| 1162 | err= cmdBuffer.BeginCommandBuffer(); |
| 1163 | ASSERT_VK_SUCCESS(err); |
| 1164 | vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 1165 | // Should error before calling to driver so don't care about actual data |
| 1166 | vkCmdBindVertexBuffers(cmdBuffer.GetBufferHandle(), 0, 1, NULL, NULL); |
| 1167 | |
| 1168 | msgType = m_errorMonitor->GetState(&msgString); |
| 1169 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive error after vkCmdBindVertexBuffers() w/o any Vtx Inputs in PSO."; |
| 1170 | if (!strstr(msgString.c_str(),"Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.")) { |
| 1171 | FAIL() << "Error received was not 'Vtx Buffer Index 0 was bound, but no vtx buffers are attached to PSO.'"; |
| 1172 | } |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | TEST_F(VkLayerTest, DSTypeMismatch) |
| 1176 | { |
| 1177 | // Create DS w/ layout of one type and attempt Update w/ mis-matched type |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1178 | VK_DBG_MSG_TYPE msgType; |
| 1179 | std::string msgString; |
| 1180 | VkResult err; |
| 1181 | |
| 1182 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1183 | m_errorMonitor->ClearState(); |
| 1184 | //VkDescriptorSetObj descriptorSet(m_device); |
| 1185 | const VkDescriptorTypeCount ds_type_count = { |
| 1186 | .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, |
| 1187 | .count = 1, |
| 1188 | }; |
| 1189 | const VkDescriptorPoolCreateInfo ds_pool_ci = { |
| 1190 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, |
| 1191 | .pNext = NULL, |
| 1192 | .count = 1, |
| 1193 | .pTypeCount = &ds_type_count, |
| 1194 | }; |
| 1195 | VkDescriptorPool ds_pool; |
| 1196 | err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool); |
| 1197 | ASSERT_VK_SUCCESS(err); |
| 1198 | const VkDescriptorSetLayoutBinding dsl_binding = { |
| 1199 | .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, |
Chia-I Wu | d3114a2 | 2015-05-25 16:22:52 +0800 | [diff] [blame] | 1200 | .arraySize = 1, |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1201 | .stageFlags = VK_SHADER_STAGE_ALL, |
| 1202 | .pImmutableSamplers = NULL, |
| 1203 | }; |
| 1204 | |
| 1205 | const VkDescriptorSetLayoutCreateInfo ds_layout_ci = { |
| 1206 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, |
| 1207 | .pNext = NULL, |
| 1208 | .count = 1, |
| 1209 | .pBinding = &dsl_binding, |
| 1210 | }; |
| 1211 | VkDescriptorSetLayout ds_layout; |
| 1212 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout); |
| 1213 | ASSERT_VK_SUCCESS(err); |
| 1214 | |
| 1215 | VkDescriptorSet descriptorSet; |
| 1216 | uint32_t ds_count = 0; |
| 1217 | err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count); |
| 1218 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1219 | |
| 1220 | const VkSamplerCreateInfo sampler_ci = { |
| 1221 | .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, |
| 1222 | .pNext = NULL, |
| 1223 | .magFilter = VK_TEX_FILTER_NEAREST, |
| 1224 | .minFilter = VK_TEX_FILTER_NEAREST, |
| 1225 | .mipMode = VK_TEX_MIPMAP_MODE_BASE, |
| 1226 | .addressU = VK_TEX_ADDRESS_CLAMP, |
| 1227 | .addressV = VK_TEX_ADDRESS_CLAMP, |
| 1228 | .addressW = VK_TEX_ADDRESS_CLAMP, |
| 1229 | .mipLodBias = 1.0, |
| 1230 | .maxAnisotropy = 1, |
| 1231 | .compareOp = VK_COMPARE_OP_NEVER, |
| 1232 | .minLod = 1.0, |
| 1233 | .maxLod = 1.0, |
| 1234 | .borderColor = VK_BORDER_COLOR_OPAQUE_WHITE, |
| 1235 | }; |
| 1236 | VkSampler sampler; |
| 1237 | err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler); |
| 1238 | ASSERT_VK_SUCCESS(err); |
| 1239 | |
Chia-I Wu | 8cd8ecd | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 1240 | VkDescriptorInfo descriptor_info; |
| 1241 | memset(&descriptor_info, 0, sizeof(descriptor_info)); |
| 1242 | descriptor_info.sampler = sampler; |
| 1243 | |
| 1244 | VkWriteDescriptorSet descriptor_write; |
| 1245 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 1246 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 1247 | descriptor_write.destSet = descriptorSet; |
| 1248 | descriptor_write.count = 1; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1249 | // This is a mismatched type for the layout which expects BUFFER |
Chia-I Wu | 8cd8ecd | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 1250 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 1251 | descriptor_write.pDescriptors = &descriptor_info; |
| 1252 | |
| 1253 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 1254 | |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1255 | msgType = m_errorMonitor->GetState(&msgString); |
Chia-I Wu | 8cd8ecd | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 1256 | std::cout << msgString << "\n"; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1257 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "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] | 1258 | if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET does not match ")) { |
| 1259 | 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] | 1260 | } |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | TEST_F(VkLayerTest, DSUpdateOutOfBounds) |
| 1264 | { |
| 1265 | // For overlapping Update, have arrayIndex exceed that of layout |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1266 | VK_DBG_MSG_TYPE msgType; |
| 1267 | std::string msgString; |
| 1268 | VkResult err; |
| 1269 | |
| 1270 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1271 | m_errorMonitor->ClearState(); |
| 1272 | //VkDescriptorSetObj descriptorSet(m_device); |
| 1273 | const VkDescriptorTypeCount ds_type_count = { |
| 1274 | .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, |
| 1275 | .count = 1, |
| 1276 | }; |
| 1277 | const VkDescriptorPoolCreateInfo ds_pool_ci = { |
| 1278 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, |
| 1279 | .pNext = NULL, |
| 1280 | .count = 1, |
| 1281 | .pTypeCount = &ds_type_count, |
| 1282 | }; |
| 1283 | VkDescriptorPool ds_pool; |
| 1284 | err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool); |
| 1285 | ASSERT_VK_SUCCESS(err); |
| 1286 | const VkDescriptorSetLayoutBinding dsl_binding = { |
| 1287 | .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, |
Chia-I Wu | d3114a2 | 2015-05-25 16:22:52 +0800 | [diff] [blame] | 1288 | .arraySize = 1, |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1289 | .stageFlags = VK_SHADER_STAGE_ALL, |
| 1290 | .pImmutableSamplers = NULL, |
| 1291 | }; |
| 1292 | |
| 1293 | const VkDescriptorSetLayoutCreateInfo ds_layout_ci = { |
| 1294 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, |
| 1295 | .pNext = NULL, |
| 1296 | .count = 1, |
| 1297 | .pBinding = &dsl_binding, |
| 1298 | }; |
| 1299 | VkDescriptorSetLayout ds_layout; |
| 1300 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout); |
| 1301 | ASSERT_VK_SUCCESS(err); |
| 1302 | |
| 1303 | VkDescriptorSet descriptorSet; |
| 1304 | uint32_t ds_count = 0; |
| 1305 | err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count); |
| 1306 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1307 | |
| 1308 | const VkSamplerCreateInfo sampler_ci = { |
| 1309 | .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, |
| 1310 | .pNext = NULL, |
| 1311 | .magFilter = VK_TEX_FILTER_NEAREST, |
| 1312 | .minFilter = VK_TEX_FILTER_NEAREST, |
| 1313 | .mipMode = VK_TEX_MIPMAP_MODE_BASE, |
| 1314 | .addressU = VK_TEX_ADDRESS_CLAMP, |
| 1315 | .addressV = VK_TEX_ADDRESS_CLAMP, |
| 1316 | .addressW = VK_TEX_ADDRESS_CLAMP, |
| 1317 | .mipLodBias = 1.0, |
| 1318 | .maxAnisotropy = 1, |
| 1319 | .compareOp = VK_COMPARE_OP_NEVER, |
| 1320 | .minLod = 1.0, |
| 1321 | .maxLod = 1.0, |
| 1322 | .borderColor = VK_BORDER_COLOR_OPAQUE_WHITE, |
| 1323 | }; |
| 1324 | VkSampler sampler; |
| 1325 | err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler); |
| 1326 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 8cd8ecd | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 1327 | |
| 1328 | VkDescriptorInfo descriptor_info; |
| 1329 | memset(&descriptor_info, 0, sizeof(descriptor_info)); |
| 1330 | descriptor_info.sampler = sampler; |
| 1331 | |
| 1332 | VkWriteDescriptorSet descriptor_write; |
| 1333 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 1334 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 1335 | descriptor_write.destSet = descriptorSet; |
| 1336 | descriptor_write.destArrayElement = 1; /* This index out of bounds for the update */ |
| 1337 | descriptor_write.count = 1; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1338 | // 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] | 1339 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 1340 | descriptor_write.pDescriptors = &descriptor_info; |
| 1341 | |
| 1342 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 1343 | |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1344 | msgType = m_errorMonitor->GetState(&msgString); |
| 1345 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "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] | 1346 | if (!strstr(msgString.c_str(),"Descriptor update type of VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET is out of bounds for matching binding")) { |
| 1347 | 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] | 1348 | } |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | TEST_F(VkLayerTest, InvalidDSUpdateIndex) |
| 1352 | { |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1353 | // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2 |
| 1354 | VK_DBG_MSG_TYPE msgType; |
| 1355 | std::string msgString; |
| 1356 | VkResult err; |
| 1357 | |
| 1358 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1359 | m_errorMonitor->ClearState(); |
| 1360 | //VkDescriptorSetObj descriptorSet(m_device); |
| 1361 | const VkDescriptorTypeCount ds_type_count = { |
| 1362 | .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, |
| 1363 | .count = 1, |
| 1364 | }; |
| 1365 | const VkDescriptorPoolCreateInfo ds_pool_ci = { |
| 1366 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, |
| 1367 | .pNext = NULL, |
| 1368 | .count = 1, |
| 1369 | .pTypeCount = &ds_type_count, |
| 1370 | }; |
| 1371 | VkDescriptorPool ds_pool; |
| 1372 | err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool); |
| 1373 | ASSERT_VK_SUCCESS(err); |
| 1374 | const VkDescriptorSetLayoutBinding dsl_binding = { |
| 1375 | .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, |
Chia-I Wu | d3114a2 | 2015-05-25 16:22:52 +0800 | [diff] [blame] | 1376 | .arraySize = 1, |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1377 | .stageFlags = VK_SHADER_STAGE_ALL, |
| 1378 | .pImmutableSamplers = NULL, |
| 1379 | }; |
| 1380 | |
| 1381 | const VkDescriptorSetLayoutCreateInfo ds_layout_ci = { |
| 1382 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, |
| 1383 | .pNext = NULL, |
| 1384 | .count = 1, |
| 1385 | .pBinding = &dsl_binding, |
| 1386 | }; |
| 1387 | VkDescriptorSetLayout ds_layout; |
| 1388 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout); |
| 1389 | ASSERT_VK_SUCCESS(err); |
| 1390 | |
| 1391 | VkDescriptorSet descriptorSet; |
| 1392 | uint32_t ds_count = 0; |
| 1393 | err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count); |
| 1394 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1395 | |
| 1396 | const VkSamplerCreateInfo sampler_ci = { |
| 1397 | .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, |
| 1398 | .pNext = NULL, |
| 1399 | .magFilter = VK_TEX_FILTER_NEAREST, |
| 1400 | .minFilter = VK_TEX_FILTER_NEAREST, |
| 1401 | .mipMode = VK_TEX_MIPMAP_MODE_BASE, |
| 1402 | .addressU = VK_TEX_ADDRESS_CLAMP, |
| 1403 | .addressV = VK_TEX_ADDRESS_CLAMP, |
| 1404 | .addressW = VK_TEX_ADDRESS_CLAMP, |
| 1405 | .mipLodBias = 1.0, |
| 1406 | .maxAnisotropy = 1, |
| 1407 | .compareOp = VK_COMPARE_OP_NEVER, |
| 1408 | .minLod = 1.0, |
| 1409 | .maxLod = 1.0, |
| 1410 | .borderColor = VK_BORDER_COLOR_OPAQUE_WHITE, |
| 1411 | }; |
| 1412 | VkSampler sampler; |
| 1413 | err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler); |
| 1414 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 8cd8ecd | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 1415 | |
| 1416 | VkDescriptorInfo descriptor_info; |
| 1417 | memset(&descriptor_info, 0, sizeof(descriptor_info)); |
| 1418 | descriptor_info.sampler = sampler; |
| 1419 | |
| 1420 | VkWriteDescriptorSet descriptor_write; |
| 1421 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 1422 | descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 1423 | descriptor_write.destSet = descriptorSet; |
| 1424 | descriptor_write.destBinding = 2; |
| 1425 | descriptor_write.count = 1; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1426 | // 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] | 1427 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 1428 | descriptor_write.pDescriptors = &descriptor_info; |
| 1429 | |
| 1430 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 1431 | |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1432 | msgType = m_errorMonitor->GetState(&msgString); |
| 1433 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive error after updating Descriptor w/ count too large for layout."; |
| 1434 | if (!strstr(msgString.c_str()," does not have binding to match update binding ")) { |
| 1435 | FAIL() << "Error received was not 'Descriptor Set <blah> does not have binding to match update binding '"; |
| 1436 | } |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 1437 | } |
| 1438 | |
| 1439 | TEST_F(VkLayerTest, InvalidDSUpdateStruct) |
| 1440 | { |
| 1441 | // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_* types |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1442 | VK_DBG_MSG_TYPE msgType; |
| 1443 | std::string msgString; |
| 1444 | VkResult err; |
| 1445 | |
| 1446 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1447 | m_errorMonitor->ClearState(); |
| 1448 | //VkDescriptorSetObj descriptorSet(m_device); |
| 1449 | const VkDescriptorTypeCount ds_type_count = { |
| 1450 | .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, |
| 1451 | .count = 1, |
| 1452 | }; |
| 1453 | const VkDescriptorPoolCreateInfo ds_pool_ci = { |
| 1454 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, |
| 1455 | .pNext = NULL, |
| 1456 | .count = 1, |
| 1457 | .pTypeCount = &ds_type_count, |
| 1458 | }; |
| 1459 | VkDescriptorPool ds_pool; |
| 1460 | err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool); |
| 1461 | ASSERT_VK_SUCCESS(err); |
| 1462 | const VkDescriptorSetLayoutBinding dsl_binding = { |
| 1463 | .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, |
Chia-I Wu | d3114a2 | 2015-05-25 16:22:52 +0800 | [diff] [blame] | 1464 | .arraySize = 1, |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1465 | .stageFlags = VK_SHADER_STAGE_ALL, |
| 1466 | .pImmutableSamplers = NULL, |
| 1467 | }; |
| 1468 | |
| 1469 | const VkDescriptorSetLayoutCreateInfo ds_layout_ci = { |
| 1470 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, |
| 1471 | .pNext = NULL, |
| 1472 | .count = 1, |
| 1473 | .pBinding = &dsl_binding, |
| 1474 | }; |
| 1475 | VkDescriptorSetLayout ds_layout; |
| 1476 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout); |
| 1477 | ASSERT_VK_SUCCESS(err); |
| 1478 | |
| 1479 | VkDescriptorSet descriptorSet; |
| 1480 | uint32_t ds_count = 0; |
| 1481 | err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count); |
| 1482 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1483 | |
| 1484 | const VkSamplerCreateInfo sampler_ci = { |
| 1485 | .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, |
| 1486 | .pNext = NULL, |
| 1487 | .magFilter = VK_TEX_FILTER_NEAREST, |
| 1488 | .minFilter = VK_TEX_FILTER_NEAREST, |
| 1489 | .mipMode = VK_TEX_MIPMAP_MODE_BASE, |
| 1490 | .addressU = VK_TEX_ADDRESS_CLAMP, |
| 1491 | .addressV = VK_TEX_ADDRESS_CLAMP, |
| 1492 | .addressW = VK_TEX_ADDRESS_CLAMP, |
| 1493 | .mipLodBias = 1.0, |
| 1494 | .maxAnisotropy = 1, |
| 1495 | .compareOp = VK_COMPARE_OP_NEVER, |
| 1496 | .minLod = 1.0, |
| 1497 | .maxLod = 1.0, |
| 1498 | .borderColor = VK_BORDER_COLOR_OPAQUE_WHITE, |
| 1499 | }; |
| 1500 | VkSampler sampler; |
| 1501 | err = vkCreateSampler(m_device->device(), &sampler_ci, &sampler); |
| 1502 | ASSERT_VK_SUCCESS(err); |
Chia-I Wu | 8cd8ecd | 2015-05-25 16:27:55 +0800 | [diff] [blame] | 1503 | |
| 1504 | |
| 1505 | VkDescriptorInfo descriptor_info; |
| 1506 | memset(&descriptor_info, 0, sizeof(descriptor_info)); |
| 1507 | descriptor_info.sampler = sampler; |
| 1508 | |
| 1509 | VkWriteDescriptorSet descriptor_write; |
| 1510 | memset(&descriptor_write, 0, sizeof(descriptor_write)); |
| 1511 | descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */ |
| 1512 | descriptor_write.destSet = descriptorSet; |
| 1513 | descriptor_write.count = 1; |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1514 | // 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] | 1515 | descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; |
| 1516 | descriptor_write.pDescriptors = &descriptor_info; |
| 1517 | |
| 1518 | vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL); |
| 1519 | |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1520 | msgType = m_errorMonitor->GetState(&msgString); |
| 1521 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive error after updating Descriptor w/ invalid struct type."; |
| 1522 | if (!strstr(msgString.c_str(),"Unexpected UPDATE struct of type ")) { |
| 1523 | FAIL() << "Error received was not 'Unexpected UPDATE struct of type '"; |
| 1524 | } |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 1525 | } |
| 1526 | |
| 1527 | TEST_F(VkLayerTest, NumSamplesMismatch) |
| 1528 | { |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1529 | // Create CmdBuffer where MSAA samples doesn't match RenderPass sampleCount |
| 1530 | VK_DBG_MSG_TYPE msgType; |
| 1531 | std::string msgString; |
| 1532 | VkResult err; |
| 1533 | |
| 1534 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1535 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 1536 | m_errorMonitor->ClearState(); |
| 1537 | VkCommandBufferObj cmdBuffer(m_device); |
| 1538 | const VkDescriptorTypeCount ds_type_count = { |
| 1539 | .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, |
| 1540 | .count = 1, |
| 1541 | }; |
| 1542 | const VkDescriptorPoolCreateInfo ds_pool_ci = { |
| 1543 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, |
| 1544 | .pNext = NULL, |
| 1545 | .count = 1, |
| 1546 | .pTypeCount = &ds_type_count, |
| 1547 | }; |
| 1548 | VkDescriptorPool ds_pool; |
| 1549 | err = vkCreateDescriptorPool(m_device->device(), VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &ds_pool_ci, &ds_pool); |
| 1550 | ASSERT_VK_SUCCESS(err); |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1551 | |
| 1552 | const VkDescriptorSetLayoutBinding dsl_binding = { |
| 1553 | .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, |
Chia-I Wu | d3114a2 | 2015-05-25 16:22:52 +0800 | [diff] [blame] | 1554 | .arraySize = 1, |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1555 | .stageFlags = VK_SHADER_STAGE_ALL, |
| 1556 | .pImmutableSamplers = NULL, |
| 1557 | }; |
| 1558 | |
| 1559 | const VkDescriptorSetLayoutCreateInfo ds_layout_ci = { |
| 1560 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, |
| 1561 | .pNext = NULL, |
| 1562 | .count = 1, |
| 1563 | .pBinding = &dsl_binding, |
| 1564 | }; |
| 1565 | VkDescriptorSetLayout ds_layout; |
| 1566 | err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, &ds_layout); |
| 1567 | ASSERT_VK_SUCCESS(err); |
| 1568 | |
| 1569 | VkDescriptorSet descriptorSet; |
| 1570 | uint32_t ds_count = 0; |
| 1571 | err = vkAllocDescriptorSets(m_device->device(), ds_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &ds_layout, &descriptorSet, &ds_count); |
| 1572 | ASSERT_VK_SUCCESS(err); |
| 1573 | |
| 1574 | const VkPipelineMsStateCreateInfo pipe_ms_state_ci = { |
| 1575 | .sType = VK_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO, |
| 1576 | .pNext = NULL, |
Tony Barbour | d1e9558 | 2015-06-03 12:30:49 -0600 | [diff] [blame^] | 1577 | .samples = 4, |
Tobin Ehlis | 2f87d2d | 2015-05-28 12:11:26 -0600 | [diff] [blame] | 1578 | .multisampleEnable = 1, |
| 1579 | .sampleShadingEnable = 0, |
| 1580 | .minSampleShading = 1.0, |
| 1581 | .sampleMask = 15, |
| 1582 | }; |
| 1583 | |
| 1584 | const VkPipelineLayoutCreateInfo pipeline_layout_ci = { |
| 1585 | .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, |
| 1586 | .pNext = NULL, |
| 1587 | .descriptorSetCount = 1, |
| 1588 | .pSetLayouts = &ds_layout, |
| 1589 | }; |
| 1590 | |
| 1591 | VkPipelineLayout pipeline_layout; |
| 1592 | err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, &pipeline_layout); |
| 1593 | ASSERT_VK_SUCCESS(err); |
| 1594 | |
| 1595 | size_t shader_len = strlen(bindStateVertShaderText); |
| 1596 | size_t codeSize = 3 * sizeof(uint32_t) + shader_len + 1; |
| 1597 | void* pCode = malloc(codeSize); |
| 1598 | |
| 1599 | /* try version 0 first: VkShaderStage followed by GLSL */ |
| 1600 | ((uint32_t *) pCode)[0] = ICD_SPV_MAGIC; |
| 1601 | ((uint32_t *) pCode)[1] = 0; |
| 1602 | ((uint32_t *) pCode)[2] = VK_SHADER_STAGE_VERTEX; |
| 1603 | memcpy(((uint32_t *) pCode + 3), bindStateVertShaderText, shader_len + 1); |
| 1604 | |
| 1605 | const VkShaderCreateInfo vs_ci = { |
| 1606 | .sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO, |
| 1607 | .pNext = NULL, |
| 1608 | .codeSize = codeSize, |
| 1609 | .pCode = pCode, |
| 1610 | .flags = 0, |
| 1611 | }; |
| 1612 | VkShader vs; |
| 1613 | err = vkCreateShader(m_device->device(), &vs_ci, &vs); |
| 1614 | ASSERT_VK_SUCCESS(err); |
| 1615 | |
| 1616 | const VkPipelineShader vs_pipe_shader = { |
| 1617 | .stage = VK_SHADER_STAGE_VERTEX, |
| 1618 | .shader = vs, |
| 1619 | .linkConstBufferCount = 0, |
| 1620 | .pLinkConstBufferInfo = NULL, |
| 1621 | .pSpecializationInfo = NULL, |
| 1622 | }; |
| 1623 | const VkPipelineShaderStageCreateInfo pipe_vs_ci = { |
| 1624 | .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 1625 | .pNext = &pipe_ms_state_ci, |
| 1626 | .shader = vs_pipe_shader, |
| 1627 | }; |
| 1628 | const VkGraphicsPipelineCreateInfo gp_ci = { |
| 1629 | .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, |
| 1630 | .pNext = &pipe_vs_ci, |
| 1631 | .flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT, |
| 1632 | .layout = pipeline_layout, |
| 1633 | }; |
| 1634 | |
| 1635 | VkPipeline pipeline; |
| 1636 | err = vkCreateGraphicsPipeline(m_device->device(), &gp_ci, &pipeline); |
| 1637 | ASSERT_VK_SUCCESS(err); |
| 1638 | |
| 1639 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
| 1640 | BeginCommandBuffer(cmdBuffer); |
| 1641 | vkCmdBindPipeline(cmdBuffer.GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
| 1642 | |
| 1643 | msgType = m_errorMonitor->GetState(&msgString); |
| 1644 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive error after binding RenderPass w/ mismatched MSAA from PSO."; |
| 1645 | if (!strstr(msgString.c_str(),"Num samples mismatch! ")) { |
| 1646 | FAIL() << "Error received was not 'Num samples mismatch!...'"; |
| 1647 | } |
Tobin Ehlis | 138b7f1 | 2015-05-22 12:38:55 -0600 | [diff] [blame] | 1648 | } |
Tobin Ehlis | 57e6a61 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 1649 | #endif |
| 1650 | #if THREADING_TESTS |
Mike Stroyan | 09aae81 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 1651 | #if GTEST_IS_THREADSAFE |
| 1652 | struct thread_data_struct { |
| 1653 | VkCmdBuffer cmdBuffer; |
| 1654 | VkEvent event; |
| 1655 | bool bailout; |
| 1656 | }; |
| 1657 | |
| 1658 | extern "C" void *AddToCommandBuffer(void *arg) |
| 1659 | { |
| 1660 | struct thread_data_struct *data = (struct thread_data_struct *) arg; |
| 1661 | std::string msgString; |
| 1662 | |
| 1663 | for (int i = 0; i<10000; i++) { |
| 1664 | vkCmdSetEvent(data->cmdBuffer, data->event, VK_PIPE_EVENT_COMMANDS_COMPLETE); |
| 1665 | if (data->bailout) { |
| 1666 | break; |
| 1667 | } |
| 1668 | } |
| 1669 | return NULL; |
| 1670 | } |
| 1671 | |
| 1672 | TEST_F(VkLayerTest, ThreadCmdBufferCollision) |
| 1673 | { |
| 1674 | VK_DBG_MSG_TYPE msgType; |
| 1675 | std::string msgString; |
| 1676 | pthread_t thread; |
| 1677 | pthread_attr_t thread_attr; |
| 1678 | |
| 1679 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 1680 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 1681 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 1682 | |
| 1683 | VkCommandBufferObj cmdBuffer(m_device); |
| 1684 | |
| 1685 | m_errorMonitor->ClearState(); |
| 1686 | pthread_attr_init(&thread_attr); |
| 1687 | BeginCommandBuffer(cmdBuffer); |
| 1688 | |
| 1689 | VkEventCreateInfo event_info; |
| 1690 | VkEvent event; |
| 1691 | VkMemoryRequirements mem_req; |
| 1692 | size_t data_size = sizeof(mem_req); |
| 1693 | VkResult err; |
| 1694 | |
| 1695 | memset(&event_info, 0, sizeof(event_info)); |
| 1696 | event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 1697 | |
| 1698 | err = vkCreateEvent(device(), &event_info, &event); |
| 1699 | ASSERT_VK_SUCCESS(err); |
| 1700 | |
| 1701 | err = vkGetObjectInfo(device(), VK_OBJECT_TYPE_EVENT, event, VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS, |
| 1702 | &data_size, &mem_req); |
| 1703 | ASSERT_VK_SUCCESS(err); |
| 1704 | |
| 1705 | VkMemoryAllocInfo mem_info; |
| 1706 | VkDeviceMemory event_mem; |
| 1707 | |
| 1708 | ASSERT_NE(0, mem_req.size) << "vkGetObjectInfo (Event): Failed - expect events to require memory"; |
| 1709 | |
| 1710 | memset(&mem_info, 0, sizeof(mem_info)); |
| 1711 | mem_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO; |
| 1712 | mem_info.allocationSize = mem_req.size; |
| 1713 | mem_info.memProps = VK_MEMORY_PROPERTY_SHAREABLE_BIT; |
| 1714 | mem_info.memPriority = VK_MEMORY_PRIORITY_NORMAL; |
| 1715 | err = vkAllocMemory(device(), &mem_info, &event_mem); |
| 1716 | ASSERT_VK_SUCCESS(err); |
| 1717 | |
Mark Lobodzinski | 2318261 | 2015-05-29 09:32:35 -0500 | [diff] [blame] | 1718 | err = vkBindObjectMemory(device(), VK_OBJECT_TYPE_EVENT, event, event_mem, 0); |
Mike Stroyan | 09aae81 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 1719 | ASSERT_VK_SUCCESS(err); |
| 1720 | |
| 1721 | err = vkResetEvent(device(), event); |
| 1722 | ASSERT_VK_SUCCESS(err); |
| 1723 | |
| 1724 | struct thread_data_struct data; |
| 1725 | data.cmdBuffer = cmdBuffer.obj(); |
| 1726 | data.event = event; |
| 1727 | data.bailout = false; |
| 1728 | m_errorMonitor->SetBailout(&data.bailout); |
| 1729 | // Add many entries to command buffer from another thread. |
| 1730 | pthread_create(&thread, &thread_attr, AddToCommandBuffer, (void *)&data); |
| 1731 | // Add many entries to command buffer from this thread at the same time. |
| 1732 | AddToCommandBuffer(&data); |
| 1733 | pthread_join(thread, NULL); |
| 1734 | EndCommandBuffer(cmdBuffer); |
| 1735 | |
| 1736 | msgType = m_errorMonitor->GetState(&msgString); |
| 1737 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive an err from using one VkCommandBufferObj in two threads"; |
| 1738 | if (!strstr(msgString.c_str(),"THREADING ERROR")) { |
Mark Lobodzinski | 5f25be4 | 2015-05-14 15:08:13 -0500 | [diff] [blame] | 1739 | FAIL() << "Error received was not 'THREADING ERROR'"; |
Mike Stroyan | 09aae81 | 2015-05-12 16:00:45 -0600 | [diff] [blame] | 1740 | } |
| 1741 | |
| 1742 | } |
| 1743 | #endif |
Tobin Ehlis | 57e6a61 | 2015-05-26 16:11:58 -0600 | [diff] [blame] | 1744 | #endif |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 1745 | int main(int argc, char **argv) { |
| 1746 | int result; |
| 1747 | |
| 1748 | ::testing::InitGoogleTest(&argc, argv); |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1749 | VkTestFramework::InitArgs(&argc, argv); |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 1750 | |
| 1751 | ::testing::AddGlobalTestEnvironment(new TestEnvironment); |
| 1752 | |
| 1753 | result = RUN_ALL_TESTS(); |
| 1754 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 1755 | VkTestFramework::Finish(); |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 1756 | return result; |
| 1757 | } |