Skip to content

Commit 9cf85ef

Browse files
Graphics Utilities: added GetDeviceDXCompiler function
1 parent 03e1151 commit 9cf85ef

File tree

4 files changed

+106
-7
lines changed

4 files changed

+106
-7
lines changed

Graphics/GraphicsTools/interface/GraphicsUtilities.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -278,6 +278,15 @@ void DILIGENT_GLOBAL_FUNCTION(CreateGeometryPrimitiveBuffers)(IRenderDevice*
278278
IBuffer** ppIndices,
279279
GeometryPrimitiveInfo* pInfo DEFAULT_VALUE(nullptr));
280280

281+
282+
/// Returns the DirectX shader compiler interface associated with the specified render device.
283+
284+
/// \param [in] pDevice - A pointer to the render device.
285+
/// \return A pointer to the DirectX shader compiler interface.
286+
/// If the device does not support DirectX shader compiler,
287+
/// or if the compiler is not loaded, returns null.
288+
struct IDXCompiler* DILIGENT_GLOBAL_FUNCTION(GetDeviceDXCompiler)(IRenderDevice* pDevice);
289+
281290
#include "../../../Primitives/interface/UndefRefMacro.h"
282291

283292
DILIGENT_END_NAMESPACE // namespace Diligent

Graphics/GraphicsTools/src/GraphicsUtilities.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ TEXTURE_FORMAT GetTextureFormatFromNativeD3D11(int64_t NativeFormat);
4949
#if D3D12_SUPPORTED
5050
int64_t GetNativeTextureFormatD3D12(TEXTURE_FORMAT TexFormat);
5151
TEXTURE_FORMAT GetTextureFormatFromNativeD3D12(int64_t NativeFormat);
52+
IDXCompiler* GetDeviceDXCompilerD3D12(IRenderDevice* pDevice);
5253
#endif
5354

5455
#if GL_SUPPORTED || GLES_SUPPORTED
@@ -59,6 +60,7 @@ TEXTURE_FORMAT GetTextureFormatFromNativeGL(int64_t NativeFormat);
5960
#if VULKAN_SUPPORTED
6061
int64_t GetNativeTextureFormatVk(TEXTURE_FORMAT TexFormat);
6162
TEXTURE_FORMAT GetTextureFormatFromNativeVk(int64_t NativeFormat);
63+
IDXCompiler* GetDeviceDXCompilerVk(IRenderDevice* pDevice);
6264
#endif
6365

6466
#if METAL_SUPPORTED
@@ -580,6 +582,7 @@ const char* GetWebGPUEmulatedArrayIndexSuffix(IShader* pShader)
580582

581583
int64_t GetNativeTextureFormat(TEXTURE_FORMAT TexFormat, RENDER_DEVICE_TYPE DeviceType)
582584
{
585+
static_assert(RENDER_DEVICE_TYPE_COUNT == 8, "Please handle the new device type below");
583586
switch (DeviceType)
584587
{
585588
#if D3D11_SUPPORTED
@@ -621,6 +624,7 @@ int64_t GetNativeTextureFormat(TEXTURE_FORMAT TexFormat, RENDER_DEVICE_TYPE Devi
621624

622625
TEXTURE_FORMAT GetTextureFormatFromNative(int64_t NativeFormat, RENDER_DEVICE_TYPE DeviceType)
623626
{
627+
static_assert(RENDER_DEVICE_TYPE_COUNT == 8, "Please handle the new device type below");
624628
switch (DeviceType)
625629
{
626630
#if D3D11_SUPPORTED
@@ -731,6 +735,55 @@ void CreateGeometryPrimitiveBuffers(IRenderDevice* pD
731735
}
732736
}
733737

738+
739+
IDXCompiler* GetDeviceDXCompiler(IRenderDevice* pDevice)
740+
{
741+
if (pDevice == nullptr)
742+
{
743+
return nullptr;
744+
}
745+
746+
const RENDER_DEVICE_TYPE DeviceType = pDevice->GetDeviceInfo().Type;
747+
static_assert(RENDER_DEVICE_TYPE_COUNT == 8, "Please handle the new device type below");
748+
switch (DeviceType)
749+
{
750+
#if D3D11_SUPPORTED
751+
case RENDER_DEVICE_TYPE_D3D11:
752+
return nullptr;
753+
#endif
754+
755+
#if D3D12_SUPPORTED
756+
case RENDER_DEVICE_TYPE_D3D12:
757+
return GetDeviceDXCompilerD3D12(pDevice);
758+
#endif
759+
760+
#if GL_SUPPORTED || GLES_SUPPORTED
761+
case RENDER_DEVICE_TYPE_GL:
762+
case RENDER_DEVICE_TYPE_GLES:
763+
return nullptr;
764+
#endif
765+
766+
#if METAL_SUPPORTED
767+
case RENDER_DEVICE_TYPE_METAL:
768+
return nullptr;
769+
#endif
770+
771+
#if VULKAN_SUPPORTED
772+
case RENDER_DEVICE_TYPE_VULKAN:
773+
return GetDeviceDXCompilerVk(pDevice);
774+
#endif
775+
776+
#if WEBGPU_SUPPORTED
777+
case RENDER_DEVICE_TYPE_WEBGPU:
778+
return nullptr;
779+
#endif
780+
781+
default:
782+
UNSUPPORTED("Unsupported device type");
783+
return nullptr;
784+
}
785+
}
786+
734787
} // namespace Diligent
735788

736789

@@ -827,4 +880,9 @@ extern "C"
827880
{
828881
Diligent::CreateGeometryPrimitiveBuffers(pDevice, Attribs, pBufferCI, ppVertices, ppIndices, pInfo);
829882
}
883+
884+
Diligent::IDXCompiler* Diligent_GetDeviceDXCompiler(Diligent::IRenderDevice* pDevice)
885+
{
886+
return Diligent::GetDeviceDXCompiler(pDevice);
887+
}
830888
}

Graphics/GraphicsTools/src/GraphicsUtilitiesD3D12.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,8 +26,16 @@
2626

2727
#include "GraphicsUtilities.h"
2828

29+
#include "WinHPreface.h"
30+
#include <d3d12.h>
31+
#include <atlbase.h>
32+
#include "WinHPostface.h"
33+
2934
#include "../../GraphicsEngineD3DBase/include/DXGITypeConversions.hpp"
3035

36+
#include "RenderDeviceD3D12.h"
37+
#include "RefCntAutoPtr.hpp"
38+
3139
namespace Diligent
3240
{
3341

@@ -41,4 +49,16 @@ TEXTURE_FORMAT GetTextureFormatFromNativeD3D12(int64_t NativeFormat)
4149
return DXGI_FormatToTexFormat(static_cast<DXGI_FORMAT>(NativeFormat));
4250
}
4351

52+
IDXCompiler* GetDeviceDXCompilerD3D12(IRenderDevice* pDevice)
53+
{
54+
if (RefCntAutoPtr<IRenderDeviceD3D12> pDeviceD3D12{pDevice, IID_RenderDeviceD3D12})
55+
{
56+
return pDeviceD3D12->GetDXCompiler();
57+
}
58+
else
59+
{
60+
return nullptr;
61+
}
62+
}
63+
4464
} // namespace Diligent

Graphics/GraphicsTools/src/GraphicsUtilitiesVk.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,12 +27,12 @@
2727
#include "GraphicsUtilities.h"
2828
#include "DeviceContext.h"
2929

30-
#if VULKAN_SUPPORTED
31-
# include "../../GraphicsEngineVulkan/include/VulkanUtilities/VulkanHeaders.h"
32-
#endif
33-
30+
#include "../../GraphicsEngineVulkan/include/VulkanUtilities/VulkanHeaders.h"
3431
#include "../../GraphicsEngineVulkan/include/VulkanTypeConversions.hpp"
3532

33+
#include "RenderDeviceVk.h"
34+
#include "RefCntAutoPtr.hpp"
35+
3636
namespace Diligent
3737
{
3838

@@ -46,4 +46,16 @@ TEXTURE_FORMAT GetTextureFormatFromNativeVk(int64_t NativeFormat)
4646
return VkFormatToTexFormat(static_cast<VkFormat>(NativeFormat));
4747
}
4848

49+
IDXCompiler* GetDeviceDXCompilerVk(IRenderDevice* pDevice)
50+
{
51+
if (RefCntAutoPtr<IRenderDeviceVk> pDeviceVk{pDevice, IID_RenderDeviceVk})
52+
{
53+
return pDeviceVk->GetDXCompiler();
54+
}
55+
else
56+
{
57+
return nullptr;
58+
}
59+
}
60+
4961
} // namespace Diligent

0 commit comments

Comments
 (0)