diff options
| author | Marc Sunet <marc.sunet@amd.com> | 2025-11-21 09:41:06 -0800 |
|---|---|---|
| committer | Marc Sunet <marc.sunet@amd.com> | 2025-11-21 09:41:06 -0800 |
| commit | 0b5491e0a2f1a9a4023e2c4eb171287bede41388 (patch) | |
| tree | e82e93313f1fcfcc5622bae706aea9335dbc43ef /dxg | |
| parent | b5697421bbc73ed17ef3a8bc003571d1b6351b5c (diff) | |
Switch to plain C
Diffstat (limited to 'dxg')
| -rw-r--r-- | dxg/CMakeLists.txt | 23 | ||||
| -rw-r--r-- | dxg/dxcommon.h | 17 | ||||
| -rw-r--r-- | dxg/dxcommon.ixx | 53 | ||||
| -rw-r--r-- | dxg/include/dxg/dxcommon.h | 55 | ||||
| -rw-r--r-- | dxg/src/dxg.c | 1 |
5 files changed, 69 insertions, 80 deletions
diff --git a/dxg/CMakeLists.txt b/dxg/CMakeLists.txt index 6fa5401..b7607c0 100644 --- a/dxg/CMakeLists.txt +++ b/dxg/CMakeLists.txt | |||
| @@ -1,20 +1,23 @@ | |||
| 1 | cmake_minimum_required(VERSION 3.25) | 1 | cmake_minimum_required(VERSION 3.20) |
| 2 | 2 | ||
| 3 | project(dxg) | 3 | project(dxg) |
| 4 | 4 | ||
| 5 | add_library(dxg) | 5 | add_library(dxg |
| 6 | include/dxg/dxcommon.h | ||
| 7 | src/dxg.c) | ||
| 6 | 8 | ||
| 7 | target_sources(dxg PUBLIC | 9 | # target_sources(dxg PUBLIC |
| 8 | dxcommon.h) | 10 | # FILE_SET cxx_modules TYPE CXX_MODULES FILES |
| 9 | 11 | # asset.ixx | |
| 10 | target_sources(dxg PUBLIC | 12 | # dxcommon.ixx |
| 11 | FILE_SET cxx_modules TYPE CXX_MODULES FILES | 13 | # dxg.ixx |
| 12 | dxcommon.ixx) | 14 | # imm.ixx) |
| 13 | 15 | ||
| 14 | target_include_directories(dxg PUBLIC | 16 | target_include_directories(dxg PUBLIC |
| 15 | .) | 17 | include) |
| 16 | 18 | ||
| 17 | target_link_libraries(dxg PUBLIC | 19 | target_link_libraries(dxg PUBLIC |
| 18 | DirectX-Headers | 20 | DirectX-Headers |
| 19 | D3D12.lib | 21 | D3D12.lib |
| 20 | DXGI.lib) | 22 | DXGI.lib |
| 23 | DXGUID.lib) # For IID_Xyz symbols | ||
diff --git a/dxg/dxcommon.h b/dxg/dxcommon.h deleted file mode 100644 index addb8c3..0000000 --- a/dxg/dxcommon.h +++ /dev/null | |||
| @@ -1,17 +0,0 @@ | |||
| 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 deleted file mode 100644 index b06ae95..0000000 --- a/dxg/dxcommon.ixx +++ /dev/null | |||
| @@ -1,53 +0,0 @@ | |||
| 1 | module; | ||
| 2 | |||
| 3 | #include <wrl.h> | ||
| 4 | #include <stdexcept> | ||
| 5 | |||
| 6 | export module dxcommon; | ||
| 7 | |||
| 8 | using Microsoft::WRL::ComPtr; | ||
| 9 | |||
| 10 | namespace dx { | ||
| 11 | |||
| 12 | export { | ||
| 13 | |||
| 14 | class exception : public std::exception | ||
| 15 | { | ||
| 16 | public: | ||
| 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 | |||
| 35 | private: | ||
| 36 | static thread_local char m_error[1024]; | ||
| 37 | }; | ||
| 38 | |||
| 39 | template <typename T> | ||
| 40 | void SafeRelease(ComPtr<T>& ptr) | ||
| 41 | { | ||
| 42 | if (ptr) | ||
| 43 | { | ||
| 44 | ptr->Release(); | ||
| 45 | ptr = nullptr; | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | } // export | ||
| 50 | |||
| 51 | thread_local char exception::m_error[1024]; | ||
| 52 | |||
| 53 | } // dx | ||
diff --git a/dxg/include/dxg/dxcommon.h b/dxg/include/dxg/dxcommon.h new file mode 100644 index 0000000..bfcdbe8 --- /dev/null +++ b/dxg/include/dxg/dxcommon.h | |||
| @@ -0,0 +1,55 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <d3d12.h> | ||
| 4 | #include <dxgi1_4.h> | ||
| 5 | #include <directx/d3dx12.h> | ||
| 6 | |||
| 7 | #include <assert.h> | ||
| 8 | #include <stdio.h> | ||
| 9 | |||
| 10 | #define TRAP(ERROR) { \ | ||
| 11 | fprintf(stderr, "Error in file:[%s] line:%d: %s", __FILE__, __LINE__, ERROR);\ | ||
| 12 | assert(false);\ | ||
| 13 | __debugbreak();\ | ||
| 14 | } | ||
| 15 | |||
| 16 | #define TRAP_HRESULT(RESULT) { \ | ||
| 17 | fprintf(stderr, "HRESULT: %u", RESULT);\ | ||
| 18 | TRAP("API call failed")\ | ||
| 19 | } | ||
| 20 | |||
| 21 | #define TrapIfFailed(RESULT) {\ | ||
| 22 | if (RESULT != S_OK) {\ | ||
| 23 | TRAP_HRESULT(RESULT);\ | ||
| 24 | }\ | ||
| 25 | } | ||
| 26 | |||
| 27 | #define SafeRelease(PTR) {\ | ||
| 28 | if (PTR) {\ | ||
| 29 | PTR->lpVtbl->Release(PTR);\ | ||
| 30 | PTR = 0;\ | ||
| 31 | }\ | ||
| 32 | } | ||
| 33 | |||
| 34 | #define CD3DX12_CPU_DESCRIPTOR_HANDLE(HANDLE, INDEX, SIZE) \ | ||
| 35 | (D3D12_CPU_DESCRIPTOR_HANDLE){HANDLE.ptr + (INDEX * SIZE)} | ||
| 36 | |||
| 37 | #define OFFSET_HANDLE(HANDLE, OFFSET, SIZE) \ | ||
| 38 | (D3D12_CPU_DESCRIPTOR_HANDLE){HANDLE.ptr + (OFFSET * SIZE)} | ||
| 39 | |||
| 40 | static inline D3D12_RESOURCE_BARRIER CD3DX12_RESOURCE_BARRIER_Transition( | ||
| 41 | _In_ ID3D12Resource* pResource, | ||
| 42 | D3D12_RESOURCE_STATES stateBefore, | ||
| 43 | D3D12_RESOURCE_STATES stateAfter) { | ||
| 44 | return (D3D12_RESOURCE_BARRIER){ | ||
| 45 | .Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, | ||
| 46 | .Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE, | ||
| 47 | .Transition.pResource = pResource, | ||
| 48 | .Transition.StateBefore = stateBefore, | ||
| 49 | .Transition.StateAfter = stateAfter, | ||
| 50 | .Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES}; | ||
| 51 | } | ||
| 52 | |||
| 53 | typedef enum SampleMask { | ||
| 54 | PointSampling = 0xffffffff | ||
| 55 | } SampleMask; | ||
diff --git a/dxg/src/dxg.c b/dxg/src/dxg.c new file mode 100644 index 0000000..e985d3d --- /dev/null +++ b/dxg/src/dxg.c | |||
| @@ -0,0 +1 @@ | |||
| int x = 2; | |||
