Vulkan SDK for Android 1.1.1 Mali Developer Center
All Classes Functions Variables Enumerations Enumerator Pages
common.hpp
1 /* Copyright (c) 2016-2017, ARM Limited and Contributors
2  *
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge,
6  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19  */
20 
21 #ifndef FRAMEWORK_COMMON_HPP
22 #define FRAMEWORK_COMMON_HPP
23 
24 #include "libvulkan-stub.h"
25 #include <stdio.h>
26 #include <stdlib.h>
27 
28 #ifdef ANDROID
29 #include <android/log.h>
30 #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, "MaliSDK", __VA_ARGS__)
31 #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, "MaliSDK", __VA_ARGS__)
32 #else
33 #define LOGE(...) fprintf(stderr, "ERROR: " __VA_ARGS__)
34 #define LOGI(...) fprintf(stderr, "INFO: " __VA_ARGS__)
35 #endif
36 
39 #define VK_CHECK(x) \
40  do \
41  { \
42  VkResult err = x; \
43  if (err) \
44  { \
45  LOGE("Detected Vulkan error %d at %s:%d.\n", int(err), __FILE__, __LINE__); \
46  abort(); \
47  } \
48  } while (0)
49 
50 #define ASSERT_VK_HANDLE(handle) \
51  do \
52  { \
53  if ((handle) == VK_NULL_HANDLE) \
54  { \
55  LOGE("Handle is NULL at %s:%d.\n", __FILE__, __LINE__); \
56  abort(); \
57  } \
58  } while (0)
59 
60 namespace MaliSDK
61 {
62 
64 enum Result
65 {
67  RESULT_SUCCESS = 0,
68 
70  RESULT_ERROR_GENERIC = -1,
71 
74  RESULT_ERROR_OUTDATED_SWAPCHAIN = -2,
75 
77  RESULT_ERROR_IO = -3,
78 
80  RESULT_ERROR_OUT_OF_MEMORY = -4
81 };
82 
84 #define SUCCEEDED(x) ((x) == RESULT_SUCCESS)
85 #define FAILED(x) ((x) != RESULT_SUCCESS)
87 }
88 
89 #endif