aboutsummaryrefslogtreecommitdiff
path: root/dxg/dxcommon.ixx
diff options
context:
space:
mode:
authorMarc Sunet <marc.sunet@amd.com>2025-11-19 19:42:04 -0800
committerMarc Sunet <marc.sunet@amd.com>2025-11-19 19:42:04 -0800
commitb5697421bbc73ed17ef3a8bc003571d1b6351b5c (patch)
tree655dd8d239e582c6d37609cea95e76a4e6ce24f2 /dxg/dxcommon.ixx
parent0cca9d39108e0305d1e278feafa1ca737f436bc9 (diff)
Rename dxcommon -> dxg
Diffstat (limited to 'dxg/dxcommon.ixx')
-rw-r--r--dxg/dxcommon.ixx53
1 files changed, 53 insertions, 0 deletions
diff --git a/dxg/dxcommon.ixx b/dxg/dxcommon.ixx
new file mode 100644
index 0000000..b06ae95
--- /dev/null
+++ b/dxg/dxcommon.ixx
@@ -0,0 +1,53 @@
1module;
2
3#include <wrl.h>
4#include <stdexcept>
5
6export module dxcommon;
7
8using Microsoft::WRL::ComPtr;
9
10namespace dx {
11
12export {
13
14class exception : public std::exception
15{
16public:
17 exception() noexcept = default;
18
19 exception(HRESULT result, const char* file, int line) noexcept
20 {
21 sprintf_s(m_error, sizeof(m_error), "%s:%d Failed with HRESULT = %08X",
22 file, line, static_cast<unsigned int>(result));
23 }
24
25 exception(const char* error, const char* file, int line) noexcept
26 {
27 sprintf_s(m_error, sizeof(m_error), "%s:%d %s", file, line, error);
28 }
29
30 [[nodiscard]] const char* what() const noexcept final
31 {
32 return m_error;
33 }
34
35private:
36 static thread_local char m_error[1024];
37};
38
39template <typename T>
40void SafeRelease(ComPtr<T>& ptr)
41{
42 if (ptr)
43 {
44 ptr->Release();
45 ptr = nullptr;
46 }
47}
48
49} // export
50
51thread_local char exception::m_error[1024];
52
53} // dx