From 0b5491e0a2f1a9a4023e2c4eb171287bede41388 Mon Sep 17 00:00:00 2001 From: Marc Sunet Date: Fri, 21 Nov 2025 09:41:06 -0800 Subject: Switch to plain C --- dxg/CMakeLists.txt | 23 ++++++++++--------- dxg/dxcommon.h | 17 -------------- dxg/dxcommon.ixx | 53 -------------------------------------------- dxg/include/dxg/dxcommon.h | 55 ++++++++++++++++++++++++++++++++++++++++++++++ dxg/src/dxg.c | 1 + 5 files changed, 69 insertions(+), 80 deletions(-) delete mode 100644 dxg/dxcommon.h delete mode 100644 dxg/dxcommon.ixx create mode 100644 dxg/include/dxg/dxcommon.h create mode 100644 dxg/src/dxg.c (limited to 'dxg') 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 @@ -cmake_minimum_required(VERSION 3.25) +cmake_minimum_required(VERSION 3.20) project(dxg) -add_library(dxg) +add_library(dxg + include/dxg/dxcommon.h + src/dxg.c) -target_sources(dxg PUBLIC - dxcommon.h) - -target_sources(dxg PUBLIC - FILE_SET cxx_modules TYPE CXX_MODULES FILES - dxcommon.ixx) +# target_sources(dxg PUBLIC +# FILE_SET cxx_modules TYPE CXX_MODULES FILES +# asset.ixx +# dxcommon.ixx +# dxg.ixx +# imm.ixx) target_include_directories(dxg PUBLIC - .) + include) target_link_libraries(dxg PUBLIC DirectX-Headers D3D12.lib - DXGI.lib) + DXGI.lib + 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 @@ -#pragma once - -#include -#include -#include - -#define THROW(error) throw exception(error, __FILE__, __LINE__) - -#define ThrowIfFailed(result) \ -{\ - if (result != S_OK) \ - {\ - THROW(result);\ - }\ -} - -//#define IID_PPV_ARGS(ppType) __uuidof(**(ppType)), static_cast(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 @@ -module; - -#include -#include - -export module dxcommon; - -using Microsoft::WRL::ComPtr; - -namespace dx { - -export { - -class exception : public std::exception -{ -public: - exception() noexcept = default; - - exception(HRESULT result, const char* file, int line) noexcept - { - sprintf_s(m_error, sizeof(m_error), "%s:%d Failed with HRESULT = %08X", - file, line, static_cast(result)); - } - - exception(const char* error, const char* file, int line) noexcept - { - sprintf_s(m_error, sizeof(m_error), "%s:%d %s", file, line, error); - } - - [[nodiscard]] const char* what() const noexcept final - { - return m_error; - } - -private: - static thread_local char m_error[1024]; -}; - -template -void SafeRelease(ComPtr& ptr) -{ - if (ptr) - { - ptr->Release(); - ptr = nullptr; - } -} - -} // export - -thread_local char exception::m_error[1024]; - -} // 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 @@ +#pragma once + +#include +#include +#include + +#include +#include + +#define TRAP(ERROR) { \ + fprintf(stderr, "Error in file:[%s] line:%d: %s", __FILE__, __LINE__, ERROR);\ + assert(false);\ + __debugbreak();\ +} + +#define TRAP_HRESULT(RESULT) { \ + fprintf(stderr, "HRESULT: %u", RESULT);\ + TRAP("API call failed")\ +} + +#define TrapIfFailed(RESULT) {\ + if (RESULT != S_OK) {\ + TRAP_HRESULT(RESULT);\ + }\ +} + +#define SafeRelease(PTR) {\ + if (PTR) {\ + PTR->lpVtbl->Release(PTR);\ + PTR = 0;\ + }\ +} + +#define CD3DX12_CPU_DESCRIPTOR_HANDLE(HANDLE, INDEX, SIZE) \ + (D3D12_CPU_DESCRIPTOR_HANDLE){HANDLE.ptr + (INDEX * SIZE)} + +#define OFFSET_HANDLE(HANDLE, OFFSET, SIZE) \ + (D3D12_CPU_DESCRIPTOR_HANDLE){HANDLE.ptr + (OFFSET * SIZE)} + +static inline D3D12_RESOURCE_BARRIER CD3DX12_RESOURCE_BARRIER_Transition( + _In_ ID3D12Resource* pResource, + D3D12_RESOURCE_STATES stateBefore, + D3D12_RESOURCE_STATES stateAfter) { + return (D3D12_RESOURCE_BARRIER){ + .Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, + .Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE, + .Transition.pResource = pResource, + .Transition.StateBefore = stateBefore, + .Transition.StateAfter = stateAfter, + .Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES}; +} + +typedef enum SampleMask { + PointSampling = 0xffffffff +} 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; -- cgit v1.2.3