From f4ca6a856ac589e4de485325e8c4e41d544817e2 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Sun, 18 Feb 2024 00:44:06 +0200 Subject: [Windows] Make D3D12 loading dynamic to support pre Windows 10 versions. --- .../include/directx/d3dx12_root_signature.h | 30 ++++++-- .../patches/patch_d3d12_dynamic_load.diff | 82 ++++++++++++++++++++++ 2 files changed, 107 insertions(+), 5 deletions(-) create mode 100644 thirdparty/directx_headers/patches/patch_d3d12_dynamic_load.diff (limited to 'thirdparty/directx_headers') diff --git a/thirdparty/directx_headers/include/directx/d3dx12_root_signature.h b/thirdparty/directx_headers/include/directx/d3dx12_root_signature.h index 572efed852..a83d9d017c 100644 --- a/thirdparty/directx_headers/include/directx/d3dx12_root_signature.h +++ b/thirdparty/directx_headers/include/directx/d3dx12_root_signature.h @@ -996,6 +996,9 @@ struct CD3DX12_GPU_DESCRIPTOR_HANDLE : public D3D12_GPU_DESCRIPTOR_HANDLE // two code paths for building root signatures, this helper method reconstructs a 1.0 signature when // 1.1 is not supported. inline HRESULT D3DX12SerializeVersionedRootSignature( +/* GODOT start */ + _In_ HMODULE pLibD3D12, +/* GODOT end */ _In_ const D3D12_VERSIONED_ROOT_SIGNATURE_DESC* pRootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION MaxVersion, _Outptr_ ID3DBlob** ppBlob, @@ -1006,13 +1009,22 @@ inline HRESULT D3DX12SerializeVersionedRootSignature( *ppErrorBlob = nullptr; } + /* GODOT start */ + PFN_D3D12_SERIALIZE_ROOT_SIGNATURE d3d_D3D12SerializeRootSignature = (PFN_D3D12_SERIALIZE_ROOT_SIGNATURE)(void *)GetProcAddress(pLibD3D12, "D3D12SerializeRootSignature"); + if (d3d_D3D12SerializeRootSignature == nullptr) { + return E_INVALIDARG; + } + PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE d3d_D3D12SerializeVersionedRootSignature = (PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE)(void *)GetProcAddress(pLibD3D12, "D3D12SerializeVersionedRootSignature"); + /* GODOT end */ switch (MaxVersion) { case D3D_ROOT_SIGNATURE_VERSION_1_0: switch (pRootSignatureDesc->Version) { case D3D_ROOT_SIGNATURE_VERSION_1_0: - return D3D12SerializeRootSignature(&pRootSignatureDesc->Desc_1_0, D3D_ROOT_SIGNATURE_VERSION_1, ppBlob, ppErrorBlob); +/* GODOT start */ + return d3d_D3D12SerializeRootSignature(&pRootSignatureDesc->Desc_1_0, D3D_ROOT_SIGNATURE_VERSION_1, ppBlob, ppErrorBlob); +/* GODOT end */ case D3D_ROOT_SIGNATURE_VERSION_1_1: #if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 609) @@ -1114,7 +1126,9 @@ inline HRESULT D3DX12SerializeVersionedRootSignature( if (SUCCEEDED(hr)) { const CD3DX12_ROOT_SIGNATURE_DESC desc_1_0(desc_1_1.NumParameters, pParameters_1_0, desc_1_1.NumStaticSamplers, pStaticSamplers == nullptr ? desc_1_1.pStaticSamplers : pStaticSamplers, desc_1_1.Flags); - hr = D3D12SerializeRootSignature(&desc_1_0, D3D_ROOT_SIGNATURE_VERSION_1, ppBlob, ppErrorBlob); +/* GODOT start */ + hr = d3d_D3D12SerializeRootSignature(&desc_1_0, D3D_ROOT_SIGNATURE_VERSION_1, ppBlob, ppErrorBlob); +/* GODOT end */ } if (pParameters) @@ -1145,7 +1159,9 @@ inline HRESULT D3DX12SerializeVersionedRootSignature( { case D3D_ROOT_SIGNATURE_VERSION_1_0: case D3D_ROOT_SIGNATURE_VERSION_1_1: - return D3D12SerializeVersionedRootSignature(pRootSignatureDesc, ppBlob, ppErrorBlob); +/* GODOT start */ + return d3d_D3D12SerializeVersionedRootSignature(pRootSignatureDesc, ppBlob, ppErrorBlob); +/* GODOT end */ #if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 609) case D3D_ROOT_SIGNATURE_VERSION_1_2: @@ -1181,7 +1197,9 @@ inline HRESULT D3DX12SerializeVersionedRootSignature( if (SUCCEEDED(hr)) { const CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC desc(desc_1_1.NumParameters, desc_1_1.pParameters, desc_1_1.NumStaticSamplers, pStaticSamplers == nullptr ? desc_1_1.pStaticSamplers : pStaticSamplers, desc_1_1.Flags); - hr = D3D12SerializeVersionedRootSignature(&desc, ppBlob, ppErrorBlob); +/* GODOT start */ + hr = d3d_D3D12SerializeVersionedRootSignature(&desc, ppBlob, ppErrorBlob); +/* GODOT end */ } if (pStaticSamplers) @@ -1197,7 +1215,9 @@ inline HRESULT D3DX12SerializeVersionedRootSignature( #if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 609) case D3D_ROOT_SIGNATURE_VERSION_1_2: #endif - return D3D12SerializeVersionedRootSignature(pRootSignatureDesc, ppBlob, ppErrorBlob); +/* GODOT start */ + return d3d_D3D12SerializeVersionedRootSignature(pRootSignatureDesc, ppBlob, ppErrorBlob); +/* GODOT end */ } return E_INVALIDARG; diff --git a/thirdparty/directx_headers/patches/patch_d3d12_dynamic_load.diff b/thirdparty/directx_headers/patches/patch_d3d12_dynamic_load.diff new file mode 100644 index 0000000000..d520a44172 --- /dev/null +++ b/thirdparty/directx_headers/patches/patch_d3d12_dynamic_load.diff @@ -0,0 +1,82 @@ +diff --git a/thirdparty/directx_headers/include/directx/d3dx12_root_signature.h b/thirdparty/directx_headers/include/directx/d3dx12_root_signature.h +index 572efed852..18efa7a0cb 100644 +--- a/thirdparty/directx_headers/include/directx/d3dx12_root_signature.h ++++ b/thirdparty/directx_headers/include/directx/d3dx12_root_signature.h +@@ -996,6 +996,9 @@ struct CD3DX12_GPU_DESCRIPTOR_HANDLE : public D3D12_GPU_DESCRIPTOR_HANDLE + // two code paths for building root signatures, this helper method reconstructs a 1.0 signature when + // 1.1 is not supported. + inline HRESULT D3DX12SerializeVersionedRootSignature( ++/* GODOT start */ ++ _In_ HMODULE pLibD3D12, ++/* GODOT end */ + _In_ const D3D12_VERSIONED_ROOT_SIGNATURE_DESC* pRootSignatureDesc, + D3D_ROOT_SIGNATURE_VERSION MaxVersion, + _Outptr_ ID3DBlob** ppBlob, +@@ -1006,13 +1009,22 @@ inline HRESULT D3DX12SerializeVersionedRootSignature( + *ppErrorBlob = nullptr; + } + ++ /* GODOT start */ ++ PFN_D3D12_SERIALIZE_ROOT_SIGNATURE d3d_D3D12SerializeRootSignature = (PFN_D3D12_SERIALIZE_ROOT_SIGNATURE)(void *)GetProcAddress(pLibD3D12, "D3D12SerializeRootSignature"); ++ if (d3d_D3D12SerializeRootSignature == nullptr) { ++ return E_INVALIDARG; ++ } ++ PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE d3d_D3D12SerializeVersionedRootSignature = (PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE)(void *)GetProcAddress(pLibD3D12, "D3D12SerializeVersionedRootSignature"); ++ /* GODOT end */ + switch (MaxVersion) + { + case D3D_ROOT_SIGNATURE_VERSION_1_0: + switch (pRootSignatureDesc->Version) + { + case D3D_ROOT_SIGNATURE_VERSION_1_0: +- return D3D12SerializeRootSignature(&pRootSignatureDesc->Desc_1_0, D3D_ROOT_SIGNATURE_VERSION_1, ppBlob, ppErrorBlob); ++/* GODOT start */ ++ return d3d_D3D12SerializeRootSignature(&pRootSignatureDesc->Desc_1_0, D3D_ROOT_SIGNATURE_VERSION_1, ppBlob, ppErrorBlob); ++/* GODOT end */ + + case D3D_ROOT_SIGNATURE_VERSION_1_1: + #if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 609) +@@ -1114,7 +1126,9 @@ inline HRESULT D3DX12SerializeVersionedRootSignature( + if (SUCCEEDED(hr)) + { + const CD3DX12_ROOT_SIGNATURE_DESC desc_1_0(desc_1_1.NumParameters, pParameters_1_0, desc_1_1.NumStaticSamplers, pStaticSamplers == nullptr ? desc_1_1.pStaticSamplers : pStaticSamplers, desc_1_1.Flags); +- hr = D3D12SerializeRootSignature(&desc_1_0, D3D_ROOT_SIGNATURE_VERSION_1, ppBlob, ppErrorBlob); ++/* GODOT start */ ++ hr = d3d_D3D12SerializeRootSignature(&desc_1_0, D3D_ROOT_SIGNATURE_VERSION_1, ppBlob, ppErrorBlob); ++/* GODOT end */ + } + + if (pParameters) +@@ -1145,7 +1159,9 @@ inline HRESULT D3DX12SerializeVersionedRootSignature( + { + case D3D_ROOT_SIGNATURE_VERSION_1_0: + case D3D_ROOT_SIGNATURE_VERSION_1_1: +- return D3D12SerializeVersionedRootSignature(pRootSignatureDesc, ppBlob, ppErrorBlob); ++/* GODOT start */ ++ return d3d_D3D12SerializeVersionedRootSignature(pRootSignatureDesc, ppBlob, ppErrorBlob); ++/* GODOT end */ + + #if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 609) + case D3D_ROOT_SIGNATURE_VERSION_1_2: +@@ -1181,7 +1197,9 @@ inline HRESULT D3DX12SerializeVersionedRootSignature( + if (SUCCEEDED(hr)) + { + const CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC desc(desc_1_1.NumParameters, desc_1_1.pParameters, desc_1_1.NumStaticSamplers, pStaticSamplers == nullptr ? desc_1_1.pStaticSamplers : pStaticSamplers, desc_1_1.Flags); +- hr = D3D12SerializeVersionedRootSignature(&desc, ppBlob, ppErrorBlob); ++/* GODOT start */ ++ hr = d3d_D3D12SerializeVersionedRootSignature(&desc, ppBlob, ppErrorBlob); ++/* GODOT end */ + } + + if (pStaticSamplers) +@@ -1197,7 +1215,9 @@ inline HRESULT D3DX12SerializeVersionedRootSignature( + #if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 609) + case D3D_ROOT_SIGNATURE_VERSION_1_2: + #endif +- return D3D12SerializeVersionedRootSignature(pRootSignatureDesc, ppBlob, ppErrorBlob); ++/* GODOT start */ ++ return d3d_D3D12SerializeVersionedRootSignature(pRootSignatureDesc, ppBlob, ppErrorBlob); ++/* GODOT end */ + } + + return E_INVALIDARG; -- cgit v1.2.3