From 07a7f4bd9e05a8c170d308af83063024bcdfaad4 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Thu, 7 Mar 2019 19:00:46 -0800 Subject: Added IShaderD3D interface and HLSLShaderResourceDesc structure --- Graphics/GraphicsEngineD3D11/CMakeLists.txt | 2 +- .../GraphicsEngineD3D11/include/ShaderD3D11Impl.h | 9 +- .../GraphicsEngineD3D11/interface/ShaderD3D11.h | 4 +- .../GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp | 15 ++++ Graphics/GraphicsEngineD3D12/CMakeLists.txt | 2 +- .../GraphicsEngineD3D12/include/ShaderD3D12Impl.h | 7 +- .../GraphicsEngineD3D12/interface/ShaderD3D12.h | 4 +- .../GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp | 15 +++- Graphics/GraphicsEngineD3DBase/CMakeLists.txt | 12 ++- .../include/ShaderResources.h | 5 +- .../GraphicsEngineD3DBase/interface/ShaderD3D.h | 53 ++++++++++++ .../GraphicsEngineD3DBase/src/ShaderResources.cpp | 97 ++++++++++++---------- 12 files changed, 168 insertions(+), 57 deletions(-) create mode 100644 Graphics/GraphicsEngineD3DBase/interface/ShaderD3D.h (limited to 'Graphics') diff --git a/Graphics/GraphicsEngineD3D11/CMakeLists.txt b/Graphics/GraphicsEngineD3D11/CMakeLists.txt index f54fa680..630de8cb 100644 --- a/Graphics/GraphicsEngineD3D11/CMakeLists.txt +++ b/Graphics/GraphicsEngineD3D11/CMakeLists.txt @@ -79,7 +79,7 @@ INTERFACE ) target_link_libraries(GraphicsEngineD3D11Interface INTERFACE - GraphicsEngineInterface + GraphicsEngineD3DBaseInterface ) diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/ShaderD3D11Impl.h index 35a50a08..f297bc47 100644 --- a/Graphics/GraphicsEngineD3D11/include/ShaderD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/ShaderD3D11Impl.h @@ -53,7 +53,7 @@ public: const ShaderCreateInfo& ShaderCI); ~ShaderD3D11Impl(); - IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_ShaderD3D11, TShaderBase); + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override final; virtual Uint32 GetResourceCount()const override final { @@ -62,7 +62,12 @@ public: virtual ShaderResourceDesc GetResource(Uint32 Index)const override final { - return m_pShaderResources->GetShaderResourceDesc(Index); + return GetHLSLResource(Index); + } + + virtual HLSLShaderResourceDesc GetHLSLResource(Uint32 Index)const override final + { + return m_pShaderResources->GetHLSLShaderResourceDesc(Index); } virtual ID3D11DeviceChild* GetD3D11Shader()override final diff --git a/Graphics/GraphicsEngineD3D11/interface/ShaderD3D11.h b/Graphics/GraphicsEngineD3D11/interface/ShaderD3D11.h index 15d7aed6..b2e5d6f5 100644 --- a/Graphics/GraphicsEngineD3D11/interface/ShaderD3D11.h +++ b/Graphics/GraphicsEngineD3D11/interface/ShaderD3D11.h @@ -26,7 +26,7 @@ /// \file /// Definition of the Diligent::IShaderD3D11 interface -#include "../../GraphicsEngine/interface/Shader.h" +#include "../../GraphicsEngineD3DBase/interface/ShaderD3D.h" namespace Diligent { @@ -36,7 +36,7 @@ static constexpr INTERFACE_ID IID_ShaderD3D11 = { 0xc513e83e, 0xb037, 0x405b, { 0x8b, 0x49, 0xbf, 0x8f, 0x5c, 0x22, 0xd, 0xee } }; /// Interface to the shader object implemented in D3D11 -class IShaderD3D11 : public IShader +class IShaderD3D11 : public IShaderD3D { public: diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp index 677cd40c..7a6d1d91 100644 --- a/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp @@ -88,4 +88,19 @@ ShaderD3D11Impl::~ShaderD3D11Impl() { } +void ShaderD3D11Impl::QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) +{ + if (ppInterface == nullptr) + return; + if (IID == IID_ShaderD3D || IID == IID_ShaderD3D11) + { + *ppInterface = this; + (*ppInterface)->AddRef(); + } + else + { + TShaderBase::QueryInterface( IID, ppInterface ); + } +} + } diff --git a/Graphics/GraphicsEngineD3D12/CMakeLists.txt b/Graphics/GraphicsEngineD3D12/CMakeLists.txt index a5fac952..0f5aea78 100644 --- a/Graphics/GraphicsEngineD3D12/CMakeLists.txt +++ b/Graphics/GraphicsEngineD3D12/CMakeLists.txt @@ -109,7 +109,7 @@ INTERFACE ) target_link_libraries(GraphicsEngineD3D12Interface INTERFACE - GraphicsEngineInterface + GraphicsEngineD3DBaseInterface ) add_library(GraphicsEngineD3D12-static STATIC diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.h index 9227287e..f9dd4037 100644 --- a/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.h @@ -59,7 +59,12 @@ public: virtual ShaderResourceDesc GetResource(Uint32 Index)const override final { - return m_pShaderResources->GetShaderResourceDesc(Index); + return GetHLSLResource(Index); + } + + virtual HLSLShaderResourceDesc GetHLSLResource(Uint32 Index)const override final + { + return m_pShaderResources->GetHLSLShaderResourceDesc(Index); } ID3DBlob* GetShaderByteCode(){return m_pShaderByteCode;} diff --git a/Graphics/GraphicsEngineD3D12/interface/ShaderD3D12.h b/Graphics/GraphicsEngineD3D12/interface/ShaderD3D12.h index 31dec253..9a28a404 100644 --- a/Graphics/GraphicsEngineD3D12/interface/ShaderD3D12.h +++ b/Graphics/GraphicsEngineD3D12/interface/ShaderD3D12.h @@ -26,7 +26,7 @@ /// \file /// Definition of the Diligent::IShaderD3D12 interface -#include "../../GraphicsEngine/interface/Shader.h" +#include "../../GraphicsEngineD3DBase/interface/ShaderD3D.h" namespace Diligent { @@ -36,7 +36,7 @@ static constexpr INTERFACE_ID IID_ShaderD3D12 = { 0xc059b160, 0x7f31, 0x4029, { 0x94, 0x3d, 0x9, 0x96, 0xb9, 0x8e, 0xe7, 0x9a } }; /// Interface to the shader object implemented in D3D12 -class IShaderD3D12 : public IShader +class IShaderD3D12 : public IShaderD3D { public: diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp index ba069332..f4128b88 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp @@ -49,6 +49,19 @@ ShaderD3D12Impl::~ShaderD3D12Impl() { } -IMPLEMENT_QUERY_INTERFACE( ShaderD3D12Impl, IID_ShaderD3D12, TShaderBase ) +void ShaderD3D12Impl::QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) +{ + if (ppInterface == nullptr) + return; + if (IID == IID_ShaderD3D || IID == IID_ShaderD3D12) + { + *ppInterface = this; + (*ppInterface)->AddRef(); + } + else + { + TShaderBase::QueryInterface( IID, ppInterface ); + } +} } diff --git a/Graphics/GraphicsEngineD3DBase/CMakeLists.txt b/Graphics/GraphicsEngineD3DBase/CMakeLists.txt index 1e80ae42..b4352094 100644 --- a/Graphics/GraphicsEngineD3DBase/CMakeLists.txt +++ b/Graphics/GraphicsEngineD3DBase/CMakeLists.txt @@ -17,6 +17,10 @@ set(INCLUDE include/SwapChainD3DBase.h ) +set(INTERFACE + interface/ShaderD3D.h +) + set(SOURCE src/DXGITypeConversions.cpp src/ShaderD3DBase.cpp @@ -24,7 +28,7 @@ set(SOURCE ) add_library(GraphicsEngineD3DBase STATIC - ${SOURCE} ${INCLUDE} include/HLSLDefinitions_inc.fxh + ${SOURCE} ${INCLUDE} ${INTERFACE} include/HLSLDefinitions_inc.fxh ) set_source_files_properties( @@ -50,6 +54,10 @@ add_custom_command(TARGET ProcessHLSLDefinitions add_dependencies(GraphicsEngineD3DBase ProcessHLSLDefinitions) +add_library(GraphicsEngineD3DBaseInterface INTERFACE) +target_link_libraries(GraphicsEngineD3DBaseInterface INTERFACE GraphicsEngineInterface) +target_include_directories(GraphicsEngineD3DBaseInterface INTERFACE interface) + target_include_directories(GraphicsEngineD3DBase PUBLIC include @@ -59,6 +67,7 @@ target_link_libraries(GraphicsEngineD3DBase PUBLIC BuildSettings GraphicsEngine + GraphicsEngineD3DBaseInterface ) if(D3D12_SUPPORTED) target_link_libraries(GraphicsEngineD3DBase PRIVATE D3D12.lib) @@ -67,6 +76,7 @@ set_common_target_properties(GraphicsEngineD3DBase) source_group("src" FILES ${SOURCE}) source_group("include" FILES ${INCLUDE}) +source_group("interface" FILES ${INTERFACE}) source_group("generated" FILES include/HLSLDefinitions_inc.fxh) set_target_properties(GraphicsEngineD3DBase PROPERTIES diff --git a/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h index 272ad08e..602c6fb3 100644 --- a/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h +++ b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h @@ -57,7 +57,7 @@ #define NOMINMAX #include -#include "Shader.h" +#include "ShaderD3D.h" #include "STDAllocator.h" #include "HashUtils.h" #include "StringPool.h" @@ -212,6 +212,7 @@ public: return ComputeHash(BindPoint, BindCount, InputType, SRVDimension, SamplerOrTexSRVId); } + HLSLShaderResourceDesc GetHLSLResourceDesc()const; private: friend class ShaderResources; @@ -283,7 +284,7 @@ public: SHADER_TYPE GetShaderType()const noexcept{return m_ShaderType;} - ShaderResourceDesc GetShaderResourceDesc(Uint32 Index)const; + HLSLShaderResourceDesc GetHLSLShaderResourceDesc(Uint32 Index)const; template