OSDN Git Service

Implement indirect draws
[android-x86/external-swiftshader.git] / src / Vulkan / VkDebug.hpp
1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
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 // debug.h: Debugging utilities.
16
17 #ifndef VK_DEBUG_H_
18 #define VK_DEBUG_H_
19
20 #include <stdlib.h>
21 #include <assert.h>
22 #include <stdio.h>
23
24 #if !defined(TRACE_OUTPUT_FILE)
25 #define TRACE_OUTPUT_FILE "debug.txt"
26 #endif
27
28 namespace vk
29 {
30         // Outputs text to the debugging log
31         void trace(const char *format, ...);
32         inline void trace() {}
33
34         // Outputs text to the debugging log and prints to stderr.
35         void warn(const char *format, ...);
36         inline void warn() {}
37
38         // Outputs the message to the debugging log and stderr, and calls abort().
39         void abort(const char *format, ...);
40 }
41
42 // A macro to output a trace of a function call and its arguments to the
43 // debugging log. Disabled if SWIFTSHADER_DISABLE_TRACE is defined.
44 #if defined(SWIFTSHADER_DISABLE_TRACE)
45 #define TRACE(message, ...) (void(0))
46 #else
47 #define TRACE(message, ...) vk::trace("%s:%d TRACE: " message "\n", __FILE__, __LINE__, ##__VA_ARGS__)
48 #endif
49
50 // A macro to print a warning message to the debugging log and stderr to denote
51 // an issue that needs fixing.
52 #define FIXME(message, ...) vk::warn("%s:%d FIXME: " message "\n", __FILE__, __LINE__, ##__VA_ARGS__);
53
54 // A macro to print a warning message to the debugging log and stderr.
55 #define WARN(message, ...) vk::warn("%s:%d WARNING: " message "\n", __FILE__, __LINE__, ##__VA_ARGS__);
56
57 // A macro that prints the message to the debugging log and stderr and
58 // immediately aborts execution of the application.
59 //
60 // Note: This will terminate the application regardless of build flags!
61 //       Use with extreme caution!
62 #undef ABORT
63 #define ABORT(message, ...) vk::abort("%s:%d ABORT: " message "\n", __FILE__, __LINE__, ##__VA_ARGS__)
64
65 // A macro that delegates to:
66 //   ABORT() in debug builds (!NDEBUG || DCHECK_ALWAYS_ON)
67 // or
68 //   WARN() in release builds (NDEBUG && !DCHECK_ALWAYS_ON)
69 #undef DABORT
70 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
71 #define DABORT(message, ...) ABORT(message, ##__VA_ARGS__)
72 #else
73 #define DABORT(message, ...) WARN(message, ##__VA_ARGS__)
74 #endif
75
76 // A macro asserting a condition.
77 // If the condition fails, the condition and message is passed to DABORT().
78 #undef ASSERT_MSG
79 #define ASSERT_MSG(expression, format, ...) do { \
80         if(!(expression)) { \
81                 DABORT("ASSERT(%s): " format "\n", #expression, ##__VA_ARGS__); \
82         } } while(0)
83
84 // A macro asserting a condition.
85 // If the condition fails, the condition is passed to DABORT().
86 #undef ASSERT
87 #define ASSERT(expression) do { \
88         if(!(expression)) { \
89                 DABORT("ASSERT(%s)\n", #expression); \
90         } } while(0)
91
92 // A macro to indicate unimplemented functionality.
93 #undef UNIMPLEMENTED
94 #define UNIMPLEMENTED(format, ...) DABORT("UNIMPLEMENTED: " format, ##__VA_ARGS__)
95
96 // A macro for code which is not expected to be reached under valid assumptions.
97 #undef UNREACHABLE
98 #define UNREACHABLE(format, ...) DABORT("UNREACHABLE: " format, ##__VA_ARGS__)
99
100 // A macro asserting a condition and performing a return.
101 #undef ASSERT_OR_RETURN
102 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
103 #define ASSERT_OR_RETURN(expression) ASSERT(expression)
104 #else
105 #define ASSERT_OR_RETURN(expression) do { \
106         if(!(expression)) { \
107                 return; \
108         } } while(0)
109 #endif
110
111 #endif   // VK_DEBUG_H_