| 1 | // This file is part of the FidelityFX SDK. |
| 2 | // |
| 3 | // Copyright (c) 2022-2023 Advanced Micro Devices, Inc. All rights reserved. |
| 4 | // |
| 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | // of this software and associated documentation files (the "Software"), to deal |
| 7 | // in the Software without restriction, including without limitation the rights |
| 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | // copies of the Software, and to permit persons to whom the Software is |
| 10 | // furnished to do so, subject to the following conditions: |
| 11 | // The above copyright notice and this permission notice shall be included in |
| 12 | // all copies or substantial portions of the Software. |
| 13 | // |
| 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 20 | // THE SOFTWARE. |
| 21 | |
| 22 | #pragma once |
| 23 | |
| 24 | #include "ffx_types.h" |
| 25 | #include "ffx_util.h" |
| 26 | |
| 27 | #ifdef __cplusplus |
| 28 | extern "C" { |
| 29 | #endif // #ifdef __cplusplus |
| 30 | |
| 31 | #ifdef _DEBUG |
| 32 | #ifdef _WIN32 |
| 33 | |
| 34 | #ifdef DISABLE_FFX_DEBUG_BREAK |
| 35 | #define FFX_DEBUG_BREAK \ |
| 36 | { \ |
| 37 | } |
| 38 | #else |
| 39 | /// Macro to force the debugger to break at this point in the code. |
| 40 | #define FFX_DEBUG_BREAK __debugbreak(); |
| 41 | #endif |
| 42 | #else |
| 43 | #define FFX_DEBUG_BREAK \ |
| 44 | { \ |
| 45 | } |
| 46 | #endif |
| 47 | #else |
| 48 | // don't allow debug break in release builds. |
| 49 | #define FFX_DEBUG_BREAK |
| 50 | #endif |
| 51 | |
| 52 | /// A typedef for the callback function for assert printing. |
| 53 | /// |
| 54 | /// This can be used to re-route printing of assert messages from the FFX backend |
| 55 | /// to another destination. For example instead of the default behaviour of printing |
| 56 | /// the assert messages to the debugger's TTY the message can be re-routed to a |
| 57 | /// MessageBox in a GUI application. |
| 58 | /// |
| 59 | /// @param [in] message The message generated by the assert. |
| 60 | /// |
| 61 | typedef void (*FfxAssertCallback)(const char* message); |
| 62 | |
| 63 | /// Function to report an assert. |
| 64 | /// |
| 65 | /// @param [in] file The name of the file as a string. |
| 66 | /// @param [in] line The index of the line in the file. |
| 67 | /// @param [in] condition The boolean condition that was tested. |
| 68 | /// @param [in] msg The optional message to print. |
| 69 | /// |
| 70 | /// @returns |
| 71 | /// Always returns true. |
| 72 | /// |
| 73 | FFX_API bool ffxAssertReport(const char* file, int32_t line, const char* condition, const char* msg); |
| 74 | |
| 75 | /// Provides the ability to set a callback for assert messages. |
| 76 | /// |
| 77 | /// @param [in] callback The callback function that will receive assert messages. |
| 78 | /// |
| 79 | FFX_API void ffxAssertSetPrintingCallback(FfxAssertCallback callback); |
| 80 | |
| 81 | #ifdef _DEBUG |
| 82 | /// Standard assert macro. |
| 83 | #define FFX_ASSERT(condition) \ |
| 84 | do \ |
| 85 | { \ |
| 86 | if (!(condition) && ffxAssertReport(__FILE__, __LINE__, #condition, NULL)) \ |
| 87 | FFX_DEBUG_BREAK \ |
| 88 | } while (0) |
| 89 | |
| 90 | /// Assert macro with message. |
| 91 | #define FFX_ASSERT_MESSAGE(condition, msg) \ |
| 92 | do \ |
| 93 | { \ |
| 94 | if (!(condition) && ffxAssertReport(__FILE__, __LINE__, #condition, msg)) \ |
| 95 | FFX_DEBUG_BREAK \ |
| 96 | } while (0) |
| 97 | |
| 98 | /// Assert macro that always fails. |
| 99 | #define FFX_ASSERT_FAIL(message) \ |
| 100 | do \ |
| 101 | { \ |
| 102 | ffxAssertReport(__FILE__, __LINE__, NULL, message); \ |
| 103 | FFX_DEBUG_BREAK \ |
| 104 | } while (0) |
| 105 | #else |
| 106 | // asserts disabled |
| 107 | #define FFX_ASSERT(condition) \ |
| 108 | do \ |
| 109 | { \ |
| 110 | FFX_UNUSED(condition); \ |
| 111 | } while (0) |
| 112 | |
| 113 | #define FFX_ASSERT_MESSAGE(condition, message) \ |
| 114 | do \ |
| 115 | { \ |
| 116 | FFX_UNUSED(condition); \ |
| 117 | FFX_UNUSED(message); \ |
| 118 | } while (0) |
| 119 | |
| 120 | #define FFX_ASSERT_FAIL(message) \ |
| 121 | do \ |
| 122 | { \ |
| 123 | FFX_UNUSED(message); \ |
| 124 | } while (0) |
| 125 | #endif // #if _DEBUG |
| 126 | |
| 127 | /// Simple static assert. |
| 128 | #define FFX_STATIC_ASSERT(condition) static_assert(condition, #condition) |
| 129 | |
| 130 | #ifdef __cplusplus |
| 131 | } |
| 132 | #endif // #ifdef __cplusplus |