diff options
| author | Marc Sunet <marc.sunet@amd.com> | 2025-11-19 11:24:21 -0800 |
|---|---|---|
| committer | Marc Sunet <marc.sunet@amd.com> | 2025-11-19 11:24:21 -0800 |
| commit | 556cf073d61875368fe8511b75f5cb7db04ccb52 (patch) | |
| tree | 356c3cfdfa926b7e3b11767dc76ab981610a463b /dxcommon/include/dxcommon.h | |
| parent | 5516490fd5bea08d253dcaed59c430c2dada5c2d (diff) | |
Use C++ modules
Diffstat (limited to 'dxcommon/include/dxcommon.h')
| -rw-r--r-- | dxcommon/include/dxcommon.h | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/dxcommon/include/dxcommon.h b/dxcommon/include/dxcommon.h deleted file mode 100644 index 35ec0e2..0000000 --- a/dxcommon/include/dxcommon.h +++ /dev/null | |||
| @@ -1,58 +0,0 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <wrl.h> | ||
| 4 | |||
| 5 | #include <stdexcept> | ||
| 6 | |||
| 7 | //#define IID_PPV_ARGS(ppType) __uuidof(**(ppType)), static_cast<void**>(ppType) | ||
| 8 | |||
| 9 | namespace dx { | ||
| 10 | |||
| 11 | using Microsoft::WRL::ComPtr; | ||
| 12 | |||
| 13 | class exception : public std::exception | ||
| 14 | { | ||
| 15 | public: | ||
| 16 | exception() noexcept = default; | ||
| 17 | |||
| 18 | exception(HRESULT result, const char* file, int line) noexcept | ||
| 19 | { | ||
| 20 | sprintf_s(m_error, sizeof(m_error), "%s:%d Failed with HRESULT = %08X", | ||
| 21 | file, line, static_cast<unsigned int>(result)); | ||
| 22 | } | ||
| 23 | |||
| 24 | exception(const char* error, const char* file, int line) noexcept | ||
| 25 | { | ||
| 26 | sprintf_s(m_error, sizeof(m_error), "%s:%d %s", file, line, error); | ||
| 27 | } | ||
| 28 | |||
| 29 | [[nodiscard]] const char* what() const noexcept final | ||
| 30 | { | ||
| 31 | return m_error; | ||
| 32 | } | ||
| 33 | |||
| 34 | private: | ||
| 35 | static thread_local char m_error[1024]; | ||
| 36 | }; | ||
| 37 | |||
| 38 | #define THROW(error) throw exception(error, __FILE__, __LINE__) | ||
| 39 | |||
| 40 | #define ThrowIfFailed(result) \ | ||
| 41 | {\ | ||
| 42 | if (result != S_OK) \ | ||
| 43 | {\ | ||
| 44 | THROW(result);\ | ||
| 45 | }\ | ||
| 46 | } | ||
| 47 | |||
| 48 | template <typename T> | ||
| 49 | void SafeRelease(ComPtr<T>& ptr) | ||
| 50 | { | ||
| 51 | if (ptr) | ||
| 52 | { | ||
| 53 | ptr->Release(); | ||
| 54 | ptr = nullptr; | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | } // dx | ||
