gallium/swr: add OpenSWR rasterizer
[mesa.git] / src / gallium / drivers / swr / rasterizer / common / swr_assert.h
1 /****************************************************************************
2 * Copyright (C) 2014-2015 Intel Corporation. All Rights Reserved.
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 (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 ****************************************************************************/
23
24 #ifndef __SWR_ASSERT_H__
25 #define __SWR_ASSERT_H__
26
27 #if !defined(__SWR_OS_H__)
28 #error swr_assert.h should not be included directly, please include "common/os.h" instead.
29 #endif
30
31 #if !defined(SWR_ENABLE_ASSERTS)
32
33 #if !defined(NDEBUG)
34 #define SWR_ENABLE_ASSERTS 1
35 #else
36 #define SWR_ENABLE_ASSERTS 0
37 #endif // _DEBUG
38
39 #endif // SWR_ENABLE_ASSERTS
40
41 #if !defined(SWR_ENABLE_REL_ASSERTS)
42 #define SWR_ENABLE_REL_ASSERTS 1
43 #endif
44
45 #if SWR_ENABLE_ASSERTS || SWR_ENABLE_REL_ASSERTS
46 #include "assert.h"
47
48 #if !defined(__cplusplus)
49
50 #pragma message("C++ is required for SWR Asserts, falling back to assert.h")
51
52 #if SWR_ENABLE_ASSERTS
53 #define SWR_ASSERT(e, ...) assert(e)
54 #endif
55
56 #if SWR_ENABLE_REL_ASSERTS
57 #define SWR_REL_ASSERT(e, ...) assert(e)
58 #endif
59
60 #else
61
62 #if SWR_ENABLE_ASSERTS
63 #if defined(assert)
64 #undef assert
65 #endif
66 #define assert(exp) SWR_ASSERT(exp)
67 #endif
68
69 bool SwrAssert(
70 bool chkDebugger,
71 bool& enabled,
72 const char* pExpression,
73 const char* pFileName,
74 uint32_t lineNum,
75 const char* function,
76 const char* pFmtString = nullptr,
77 ...);
78
79 #define _SWR_ASSERT(chkDebugger, e, ...) {\
80 bool expFailed = !(e);\
81 if (expFailed) {\
82 static bool swrAssertEnabled = true;\
83 expFailed = SwrAssert(chkDebugger, swrAssertEnabled, #e, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);\
84 if (expFailed) { DEBUGBREAK; }\
85 }\
86 }
87
88 #if SWR_ENABLE_ASSERTS
89 #define SWR_ASSERT(e, ...) _SWR_ASSERT(true, e, ##__VA_ARGS__)
90 #endif
91
92 #if SWR_ENABLE_REL_ASSERTS
93 #define SWR_REL_ASSERT(e, ...) _SWR_ASSERT(false, e, ##__VA_ARGS__)
94 #endif
95 #endif // C++
96
97 #endif // SWR_ENABLE_ASSERTS || SWR_ENABLE_REL_ASSERTS
98
99 #if !SWR_ENABLE_ASSERTS
100 #define SWR_ASSERT(e, ...)
101 #endif
102
103 #if !SWR_ENABLE_REL_ASSERTS
104 #define SWR_REL_ASSERT(e, ...)
105 #endif
106
107 #define SWR_NOT_IMPL SWR_ASSERT(0, "%s not implemented", __FUNCTION__)
108
109 #endif//__SWR_ASSERT_H__