aboutsummaryrefslogtreecommitdiff
path: root/dxg
diff options
context:
space:
mode:
Diffstat (limited to 'dxg')
-rw-r--r--dxg/CMakeLists.txt20
-rw-r--r--dxg/dxcommon.h17
-rw-r--r--dxg/dxcommon.ixx53
3 files changed, 90 insertions, 0 deletions
diff --git a/dxg/CMakeLists.txt b/dxg/CMakeLists.txt
new file mode 100644
index 0000000..6fa5401
--- /dev/null
+++ b/dxg/CMakeLists.txt
@@ -0,0 +1,20 @@
1cmake_minimum_required(VERSION 3.25)
2
3project(dxg)
4
5add_library(dxg)
6
7target_sources(dxg PUBLIC
8 dxcommon.h)
9
10target_sources(dxg PUBLIC
11 FILE_SET cxx_modules TYPE CXX_MODULES FILES
12 dxcommon.ixx)
13
14target_include_directories(dxg PUBLIC
15 .)
16
17target_link_libraries(dxg PUBLIC
18 DirectX-Headers
19 D3D12.lib
20 DXGI.lib)
diff --git a/dxg/dxcommon.h b/dxg/dxcommon.h
new file mode 100644
index 0000000..addb8c3
--- /dev/null
+++ b/dxg/dxcommon.h
@@ -0,0 +1,17 @@
1#pragma once
2
3#include <d3d12.h>
4#include <dxgi1_4.h>
5#include <directx/d3dx12.h>
6
7#define THROW(error) throw exception(error, __FILE__, __LINE__)
8
9#define ThrowIfFailed(result) \
10{\
11 if (result != S_OK) \
12 {\
13 THROW(result);\
14 }\
15}
16
17//#define IID_PPV_ARGS(ppType) __uuidof(**(ppType)), static_cast<void**>(ppType)
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