aboutsummaryrefslogtreecommitdiff
path: root/dxcommon
diff options
context:
space:
mode:
authormarsunet <marc.sunet@amd.com>2021-12-21 17:04:22 -0800
committermarsunet <marc.sunet@amd.com>2021-12-21 17:04:22 -0800
commitfba8184491e0b7ae6fab7ac01b4600d230dc4569 (patch)
treec13194764867a4ad8f46702356b22dccc1e56dd3 /dxcommon
parent8b1583b65d77188ef35a89e75f145f29c3e3b5d7 (diff)
Initial commit with window demo.HEADmain
Diffstat (limited to 'dxcommon')
-rw-r--r--dxcommon/CMakeLists.txt12
-rw-r--r--dxcommon/include/dxcommon.h55
-rw-r--r--dxcommon/src/dxcommon.cc8
3 files changed, 75 insertions, 0 deletions
diff --git a/dxcommon/CMakeLists.txt b/dxcommon/CMakeLists.txt
new file mode 100644
index 0000000..ad8e2b6
--- /dev/null
+++ b/dxcommon/CMakeLists.txt
@@ -0,0 +1,12 @@
1cmake_minimum_required(VERSION 3.0)
2
3add_library(dxcommon
4 src/dxcommon.cc)
5
6target_include_directories(dxcommon PUBLIC
7 ${CMAKE_CURRENT_SOURCE_DIR}/include)
8
9target_link_libraries(dxcommon PUBLIC
10 DirectX-Headers
11 D3D12.lib
12 DXGI.lib)
diff --git a/dxcommon/include/dxcommon.h b/dxcommon/include/dxcommon.h
new file mode 100644
index 0000000..0270629
--- /dev/null
+++ b/dxcommon/include/dxcommon.h
@@ -0,0 +1,55 @@
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
9namespace dx {
10
11using Microsoft::WRL::ComPtr;
12
13class exception : public std::exception {
14public:
15 exception() noexcept {}
16
17 exception(HRESULT result, const char* file, int line) noexcept
18 {
19 sprintf_s(m_error, sizeof(m_error), "%s:%d Failed with HRESULT = %08X",
20 file, line, static_cast<unsigned int>(result));
21 }
22
23 exception(const char* error, const char* file, int line) noexcept
24 {
25 sprintf_s(m_error, sizeof(m_error), "%s:%d %s", file, line, error);
26 }
27
28 const char* what() const noexcept
29 {
30 return m_error;
31 }
32
33private:
34 static char m_error[1024];
35};
36
37#define THROW(error) throw exception(error, __FILE__, __LINE__)
38
39#define ThrowIfFailed(result) {\
40 if (result != S_OK) {\
41 THROW(result);\
42 }\
43}
44
45template <typename T>
46void SafeRelease(ComPtr<T>& ptr)
47{
48 if (ptr)
49 {
50 ptr->Release();
51 ptr = nullptr;
52 }
53}
54
55} // dx
diff --git a/dxcommon/src/dxcommon.cc b/dxcommon/src/dxcommon.cc
new file mode 100644
index 0000000..841ebcd
--- /dev/null
+++ b/dxcommon/src/dxcommon.cc
@@ -0,0 +1,8 @@
1#include "dxcommon.h"
2
3namespace dx
4{
5
6char exception::m_error[1024];
7
8} // namespace dx