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" |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 5 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 6 | void VKAPI myDbgFunc( |
| 7 | VK_DBG_MSG_TYPE msgType, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 8 | VkValidationLevel validationLevel, |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 9 | VkObject srcObject, |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 10 | size_t location, |
| 11 | int32_t msgCode, |
| 12 | const char* pMsg, |
| 13 | void* pUserData); |
| 14 | |
| 15 | class ErrorMonitor { |
| 16 | public: |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 17 | ErrorMonitor(VkInstance inst) |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 18 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 19 | vkDbgRegisterMsgCallback(inst, myDbgFunc, this); |
| 20 | m_msgType = VK_DBG_MSG_UNKNOWN; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 21 | } |
| 22 | void ClearState() |
| 23 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 24 | m_msgType = VK_DBG_MSG_UNKNOWN; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 25 | m_msgString.clear(); |
| 26 | } |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 27 | VK_DBG_MSG_TYPE GetState(std::string *msgString) |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 28 | { |
| 29 | *msgString = m_msgString; |
| 30 | return m_msgType; |
| 31 | } |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 32 | void SetState(VK_DBG_MSG_TYPE msgType, const char *msgString) |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 33 | { |
| 34 | m_msgType = msgType; |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 35 | m_msgString.reserve(strlen(msgString)); |
| 36 | m_msgString = msgString; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | private: |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 40 | VK_DBG_MSG_TYPE m_msgType; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 41 | std::string m_msgString; |
| 42 | |
| 43 | }; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 44 | void VKAPI myDbgFunc( |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 45 | VK_DBG_MSG_TYPE msgType, |
| 46 | VkValidationLevel validationLevel, |
| 47 | VkObject srcObject, |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 48 | size_t location, |
| 49 | int32_t msgCode, |
| 50 | const char* pMsg, |
| 51 | void* pUserData) |
| 52 | { |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 53 | if (msgType == VK_DBG_MSG_WARNING || msgType == VK_DBG_MSG_ERROR) { |
| 54 | ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData; |
| 55 | errMonitor->SetState(msgType, pMsg); |
| 56 | } |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 57 | } |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 58 | class VkLayerTest : public VkRenderFramework |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 59 | { |
| 60 | public: |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 61 | VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer); |
| 62 | VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer); |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 63 | |
| 64 | protected: |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 65 | VkMemoryRefManager m_memoryRefManager; |
| 66 | ErrorMonitor *m_errorMonitor; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 67 | |
| 68 | virtual void SetUp() { |
Tony Barbour | 950ebc0 | 2015-04-23 12:55:36 -0600 | [diff] [blame^] | 69 | const char *layer_names[] = {"MemTracker", "ObjectTracker"}; |
| 70 | const std::vector<const char *> layers(layer_names, layer_names + 2); |
| 71 | |
| 72 | size_t extSize = sizeof(uint32_t); |
| 73 | uint32_t extCount = 0; |
| 74 | VkResult err; |
| 75 | err = vkGetGlobalExtensionInfo(VK_EXTENSION_INFO_TYPE_COUNT, 0, &extSize, &extCount); |
| 76 | assert(!err); |
| 77 | |
| 78 | VkExtensionProperties extProp; |
| 79 | extSize = sizeof(VkExtensionProperties); |
| 80 | bool32_t extFound; |
| 81 | |
| 82 | for (uint32_t i = 0; i < layers.size(); i++) { |
| 83 | extFound = 0; |
| 84 | for (uint32_t j = 0; j < extCount; j++) { |
| 85 | err = vkGetGlobalExtensionInfo(VK_EXTENSION_INFO_TYPE_PROPERTIES, j, &extSize, &extProp); |
| 86 | if (!strcmp(layers[i], extProp.extName)) { |
| 87 | extFound = 1; |
| 88 | break; |
| 89 | } |
| 90 | } |
| 91 | ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << layers[i] << " which is necessary to pass this test"; |
| 92 | } |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 93 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 94 | this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 95 | this->app_info.pNext = NULL; |
| 96 | this->app_info.pAppName = "layer_tests"; |
| 97 | this->app_info.appVersion = 1; |
| 98 | this->app_info.pEngineName = "unittest"; |
| 99 | this->app_info.engineVersion = 1; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 100 | this->app_info.apiVersion = VK_API_VERSION; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 101 | |
Tony Barbour | 950ebc0 | 2015-04-23 12:55:36 -0600 | [diff] [blame^] | 102 | InitFramework(layers); |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 103 | m_errorMonitor = new ErrorMonitor(inst); |
| 104 | } |
| 105 | |
| 106 | virtual void TearDown() { |
| 107 | // Clean up resources before we reset |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 108 | ShutdownFramework(); |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 109 | delete m_errorMonitor; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 110 | } |
| 111 | }; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 112 | VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer) |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 113 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 114 | VkResult result; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 115 | |
| 116 | result = cmdBuffer.BeginCommandBuffer(); |
| 117 | |
| 118 | /* |
| 119 | * For render test all drawing happens in a single render pass |
| 120 | * on a single command buffer. |
| 121 | */ |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 122 | if (VK_SUCCESS == result) { |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 123 | cmdBuffer.BeginRenderPass(renderPass(), framebuffer()); |
| 124 | } |
| 125 | |
| 126 | return result; |
| 127 | } |
| 128 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 129 | VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer) |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 130 | { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 131 | VkResult result; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 132 | |
| 133 | cmdBuffer.EndRenderPass(renderPass()); |
| 134 | |
| 135 | result = cmdBuffer.EndCommandBuffer(); |
| 136 | |
| 137 | return result; |
| 138 | } |
| 139 | |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 140 | TEST_F(VkLayerTest, SubmitSignaledFence) |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 141 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 142 | vk_testing::Fence testFence; |
| 143 | VK_DBG_MSG_TYPE msgType; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 144 | std::string msgString; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 145 | |
| 146 | VkFenceCreateInfo fenceInfo = {}; |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 147 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 148 | fenceInfo.pNext = NULL; |
| 149 | fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT; |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 150 | |
| 151 | // Verifiy that the appropriate layer is loaded |
| 152 | |
| 153 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 154 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 155 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 156 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 157 | VkCommandBufferObj cmdBuffer(m_device); |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 158 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
| 159 | |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 160 | BeginCommandBuffer(cmdBuffer); |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 161 | 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] | 162 | EndCommandBuffer(cmdBuffer); |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 163 | |
| 164 | testFence.init(*m_device, fenceInfo); |
| 165 | m_errorMonitor->ClearState(); |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 166 | cmdBuffer.QueueCommandBuffer(testFence.obj()); |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 167 | msgType = m_errorMonitor->GetState(&msgString); |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 168 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive an err from using a fence in SIGNALED state in call to vkQueueSubmit"; |
| 169 | if (!strstr(msgString.c_str(),"submitted in SIGNALED state. Fences must be reset before being submitted")) { |
Tony Barbour | 9c238c4 | 2015-04-09 16:00:51 -0600 | [diff] [blame] | 170 | FAIL() << "Error received was not VkQueueSubmit with fence in SIGNALED_STATE"; |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | } |
| 174 | |
| 175 | TEST_F(VkLayerTest, ResetUnsignaledFence) |
| 176 | { |
| 177 | vk_testing::Fence testFence; |
| 178 | VK_DBG_MSG_TYPE msgType; |
| 179 | std::string msgString; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 180 | VkFenceCreateInfo fenceInfo = {}; |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 181 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 182 | fenceInfo.pNext = NULL; |
| 183 | |
| 184 | // Verifiy that the appropriate layer is loaded |
| 185 | |
| 186 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 187 | testFence.init(*m_device, fenceInfo); |
| 188 | m_errorMonitor->ClearState(); |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 189 | VkFence fences[1] = {testFence.obj()}; |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 190 | vkResetFences(m_device->device(), 1, fences); |
| 191 | msgType = m_errorMonitor->GetState(&msgString); |
| 192 | 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] | 193 | if (!strstr(msgString.c_str(),"submitted to VkResetFences in UNSIGNALED STATE")) { |
Tony Barbour | 9c238c4 | 2015-04-09 16:00:51 -0600 | [diff] [blame] | 194 | FAIL() << "Error received was not VkResetFences with fence in UNSIGNALED_STATE"; |
Tony Barbour | 8508b8e | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 195 | } |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 196 | |
| 197 | } |
| 198 | |
Tony Barbour | 54cdd19 | 2015-04-22 15:12:07 -0600 | [diff] [blame] | 199 | TEST_F(VkLayerTest, WaitForUnsubmittedFence) |
| 200 | { |
| 201 | vk_testing::Fence testFence; |
| 202 | VK_DBG_MSG_TYPE msgType; |
| 203 | std::string msgString; |
| 204 | VkFenceCreateInfo fenceInfo = {}; |
| 205 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 206 | fenceInfo.pNext = NULL; |
| 207 | |
| 208 | // Verifiy that the appropriate layer is loaded |
| 209 | |
| 210 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 211 | testFence.init(*m_device, fenceInfo); |
| 212 | m_errorMonitor->ClearState(); |
| 213 | vkGetFenceStatus(m_device->device(),testFence.obj()); |
| 214 | msgType = m_errorMonitor->GetState(&msgString); |
| 215 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive an error asking for status of unsubmitted fence"; |
| 216 | if (!strstr(msgString.c_str(),"Status Requested for Unsubmitted Fence")) { |
| 217 | FAIL() << "Error received was not Status Requested for Unsubmitted Fence"; |
| 218 | } |
| 219 | |
| 220 | VkFence fences[1] = {testFence.obj()}; |
| 221 | m_errorMonitor->ClearState(); |
| 222 | vkWaitForFences(m_device->device(), 1, fences, VK_TRUE, 0); |
| 223 | msgType = m_errorMonitor->GetState(&msgString); |
| 224 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive an error for waiting for unsubmitted fence"; |
| 225 | if (!strstr(msgString.c_str(),"Waiting for Unsubmitted Fence")) { |
| 226 | FAIL() << "Error received was not Waiting for Unsubmitted Fence"; |
| 227 | } |
| 228 | } |
| 229 | |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 230 | int main(int argc, char **argv) { |
| 231 | int result; |
| 232 | |
| 233 | ::testing::InitGoogleTest(&argc, argv); |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 234 | VkTestFramework::InitArgs(&argc, argv); |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 235 | |
| 236 | ::testing::AddGlobalTestEnvironment(new TestEnvironment); |
| 237 | |
| 238 | result = RUN_ALL_TESTS(); |
| 239 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 240 | VkTestFramework::Finish(); |
Tony Barbour | 30486ea | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 241 | return result; |
| 242 | } |