1 /*==============================================================================
2 Copyright(c) 2017 Intel Corporation
3 
4 Permission is hereby granted, free of charge, to any person obtaining a
5 copy of this software and associated documentation files(the "Software"),
6 to deal in the Software without restriction, including without limitation
7 the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 and / or sell copies of the Software, and to permit persons to whom the
9 Software is furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included
12 in all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 OTHER DEALINGS IN THE SOFTWARE.
21 ============================================================================*/
22 #pragma once
23 
24 // ------------------------------------------------------------------------
25 // This block determines where GMM gets definitions for debug assert and
26 // print functions. Location differs depending who is linking GMM lib.
27 // ------------------------------------------------------------------------
28 #if ( __GMM_KMD__ || GMM_OCL)
29 #include "../../Common/AssertTracer/AssertTracer.h"
30 #include "../../util/gfxDebug.h"
31 #else
32 #include "GmmCommonExt.h"
33 #include "GmmLog/GmmLog.h"
34 //===================== Debug Message Levels========================
35 #define GFXDBG_OFF                      (0x00000000)
36 #define GFXDBG_CRITICAL                 (0x00000001)
37 #define GFXDBG_NORMAL                   (0x00000002)
38 #define GFXDBG_VERBOSE                  (0x00000004)
39 #define GFXDBG_FUNCTION                 (0x80000000)
40 #define GFXDBG_NONCRITICAL              (0x00000010)
41 #define GFXDBG_CRITICAL_DEBUG           (0x00000020)
42 #define GFXDBG_VERBOSE_VERBOSITY        (0x00000040)
43 #define GFXDBG_PROTOCAL                 (0x00000100)
44 #define GFXDBG_FUNCTION_ENTRY           (0x80000000)
45 #define GFXDBG_FUNCTION_EXIT            (0x80000000)
46 #define GFXDBG_FUNCTION_ENTRY_VERBOSE   (0x20000000)
47 #define GFXDBG_FUNCTION_EXIT_VERBOSE    (0x20000000)
48 
49 #define VOIDRETURN
50 #endif
51 
52 
53 #if (__GMM_KMD__ || GMM_OCL)
54 
55 #if defined (GMM_OCL)
56 #include "../../3d/common/iStdLib/osinlines.h"
57 #endif
58 
59 // Enable GMM_ASSERTS and GMM_DEBUG only for Debug builds similar to what UMD clients used to do earlier
60 #if (_DEBUG) //(_DEBUG || _RELEASE_INTERNAL)
61     #define GMM_ASSERT          GMMASSERT           //gfxDebug.h
62     #define GMM_ASSERTPTR       GMMASSERTPTR        //gfxDebug.h
63 #else
64     #define GMMDebugMessage(...)
65     #define GMM_ASSERT(expr)
66     #define GMM_ASSERTPTR(expr, ret)
67 #endif
68 
69 // GMM_DPF Logging is enabled for Debug and Release_Internal
70 #if (_DEBUG || _RELEASE_INTERNAL)
71    #define GMM_DPF GMMDebugMessage //gfxDebug.h
72 #else
73    #define GMM_DPF GMMDebugMessage
74 #endif // (_DEBUG || _RELEASE_INTERNAL)
75 
76 #define __GMM_ASSERT        GMM_ASSERT
77 #define __GMM_ASSERTPTR     GMM_ASSERTPTR
78 
79 #else
80 
81 // Enable GMM_ASSERTS and GMM_DEBUG only for Debug builds similar to what UMD clients used to do earlier
82 #if (_DEBUG) //(_DEBUG || _RELEASE_INTERNAL)
83 
84 #if defined(_MSC_VER)
85 #define GMM_DBG_BREAK __debugbreak()
86 #elif defined(__GNUC__)
87 #define GMM_DBG_BREAK __builtin_trap()
88 #else
89 #include <assert.h>
90 #define GMM_DBG_BREAK assert(0)
91 #endif
92 
93 #define GMM_LIB_ASSERT(expr)                                    \
94 {                                                               \
95     if(!(expr) )                                                \
96     {                                                           \
97         GMM_DBG_BREAK;                                          \
98     }                                                           \
99 }
100 
101 #define GMM_LIB_ASSERTPTR(expr, ret)                            \
102 {                                                               \
103     GMM_LIB_ASSERT(expr);                                       \
104     if( !expr )                                                 \
105     {                                                           \
106         return ret;                                             \
107     }                                                           \
108 }
109 
110 #else
111 
112 #define GMM_LIB_ASSERT(expr)
113 #define GMM_LIB_ASSERTPTR(expr, ret)                            \
114 {                                                               \
115     if (!expr)                                                  \
116     {                                                           \
117         return ret;                                             \
118     }                                                           \
119 }                                                               \
120 
121 #endif // (_DEBUG) //_DEBUG || _RELEASE_INTERNAL
122 
123 #if (_DEBUG || _RELEASE_INTERNAL)
124     #define GMMLibDebugMessage(DebugLevel, message, ...)    \
125     {                                                   \
126         if(DebugLevel == GFXDBG_CRITICAL)               \
127         {                                               \
128             GMM_LOG_ERROR(message, ##__VA_ARGS__);      \
129         }                                               \
130         else if(DebugLevel == GFXDBG_VERBOSE)           \
131         {                                               \
132             GMM_LOG_TRACE(message, ##__VA_ARGS__);      \
133         }                                               \
134         else if(DebugLevel == GFXDBG_OFF)               \
135         {                                               \
136             GMM_LOG_TRACE_IF(0, message, ##__VA_ARGS__) \
137         }                                               \
138         else                                            \
139         {                                               \
140             GMM_LOG_INFO(message, ##__VA_ARGS__);       \
141         }                                               \
142     }
143 
144 #else
145     #define GMMLibDebugMessage(...)
146 #endif //_DEBUG || _RELEASE_INTERNAL
147 
148 #define GMM_DPF             GMMLibDebugMessage
149 #define __GMM_ASSERT        GMM_LIB_ASSERT
150 #define __GMM_ASSERTPTR     GMM_LIB_ASSERTPTR
151 
152 #endif
153 
154 
155 // ------------------------------------------------------------------------
156 // This block defines various debug print macros
157 // ------------------------------------------------------------------------
158 #define GMM_DPF_ENTER   \
159     GMM_DPF(GFXDBG_FUNCTION_ENTRY, "%s-->\n", __FUNCTION__);
160 
161 #define GMM_DPF_EXIT    \
162     GMM_DPF(GFXDBG_FUNCTION_EXIT, "%s<--\n", __FUNCTION__);
163 
164 #define GMM_DPF_CRITICAL(Message)    \
165     GMM_DPF(GFXDBG_CRITICAL, "%s:%d: %s\n", __FUNCTION__, __LINE__, (Message));
166 
167 #ifndef GMM_ASSERTDPF
168     #define GMM_ASSERTDPF(Expression, Message)  \
169     {                                           \
170         if (!(Expression))                      \
171         {                                       \
172             GMM_DPF_CRITICAL(Message);          \
173             __GMM_ASSERT(0);                    \
174         }                                       \
175     }
176 #endif
177