1 // Copyright 2019 The Dawn Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef DAWNNATIVE_VULKAN_VULKANERROR_H_ 16 #define DAWNNATIVE_VULKAN_VULKANERROR_H_ 17 18 #include "dawn_native/ErrorInjector.h" 19 #include "dawn_native/vulkan/VulkanFunctions.h" 20 21 constexpr VkResult VK_FAKE_ERROR_FOR_TESTING = VK_RESULT_MAX_ENUM; 22 constexpr VkResult VK_FAKE_DEVICE_OOM_FOR_TESTING = static_cast<VkResult>(VK_RESULT_MAX_ENUM - 1); 23 24 namespace dawn_native { namespace vulkan { 25 26 // Returns a string version of the result. 27 const char* VkResultAsString(::VkResult result); 28 29 MaybeError CheckVkSuccessImpl(VkResult result, const char* context); 30 MaybeError CheckVkOOMThenSuccessImpl(VkResult result, const char* context); 31 32 // Returns a success only if result if VK_SUCCESS, an error with the context and stringified 33 // result value instead. Can be used like this: 34 // 35 // DAWN_TRY(CheckVkSuccess(vkDoSomething, "doing something")); 36 #define CheckVkSuccess(resultIn, contextIn) \ 37 ::dawn_native::vulkan::CheckVkSuccessImpl( \ 38 ::dawn_native::vulkan::VkResult::WrapUnsafe( \ 39 INJECT_ERROR_OR_RUN(resultIn, VK_FAKE_ERROR_FOR_TESTING)), \ 40 contextIn) 41 42 #define CheckVkOOMThenSuccess(resultIn, contextIn) \ 43 ::dawn_native::vulkan::CheckVkOOMThenSuccessImpl( \ 44 ::dawn_native::vulkan::VkResult::WrapUnsafe(INJECT_ERROR_OR_RUN( \ 45 resultIn, VK_FAKE_DEVICE_OOM_FOR_TESTING, VK_FAKE_ERROR_FOR_TESTING)), \ 46 contextIn) 47 48 }} // namespace dawn_native::vulkan 49 50 #endif // DAWNNATIVE_VULKAN_VULKANERROR_H_ 51