summaryrefslogtreecommitdiffstats
path: root/Graphics
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2019-03-08 03:00:46 +0000
committerEgor Yusov <egor.yusov@gmail.com>2019-03-08 03:00:46 +0000
commit07a7f4bd9e05a8c170d308af83063024bcdfaad4 (patch)
treeae222f99f91788dba53387e6f2eb5558fb309247 /Graphics
parentA bunch of minor code improvements (diff)
downloadDiligentCore-07a7f4bd9e05a8c170d308af83063024bcdfaad4.tar.gz
DiligentCore-07a7f4bd9e05a8c170d308af83063024bcdfaad4.zip
Added IShaderD3D interface and HLSLShaderResourceDesc structure
Diffstat (limited to 'Graphics')
-rw-r--r--Graphics/GraphicsEngineD3D11/CMakeLists.txt2
-rw-r--r--Graphics/GraphicsEngineD3D11/include/ShaderD3D11Impl.h9
-rw-r--r--Graphics/GraphicsEngineD3D11/interface/ShaderD3D11.h4
-rw-r--r--Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp15
-rw-r--r--Graphics/GraphicsEngineD3D12/CMakeLists.txt2
-rw-r--r--Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.h7
-rw-r--r--Graphics/GraphicsEngineD3D12/interface/ShaderD3D12.h4
-rw-r--r--Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp15
-rw-r--r--Graphics/GraphicsEngineD3DBase/CMakeLists.txt12
-rw-r--r--Graphics/GraphicsEngineD3DBase/include/ShaderResources.h5
-rw-r--r--Graphics/GraphicsEngineD3DBase/interface/ShaderD3D.h53
-rw-r--r--Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp97
12 files changed, 168 insertions, 57 deletions
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 <d3dcommon.h>
-#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<typename THandleCB,
typename THandleSampler,
diff --git a/Graphics/GraphicsEngineD3DBase/interface/ShaderD3D.h b/Graphics/GraphicsEngineD3DBase/interface/ShaderD3D.h
new file mode 100644
index 00000000..655e6469
--- /dev/null
+++ b/Graphics/GraphicsEngineD3DBase/interface/ShaderD3D.h
@@ -0,0 +1,53 @@
+/* Copyright 2015-2019 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+/// \file
+/// Definition of the Diligent::IShaderD3D interface and related data structures
+
+#include "../../GraphicsEngine/interface/Shader.h"
+
+namespace Diligent
+{
+
+// {1EA0898C-1612-457F-B74E-808843D2CBE3}
+static constexpr INTERFACE_ID IID_ShaderD3D =
+{ 0x1ea0898c, 0x1612, 0x457f, { 0xb7, 0x4e, 0x80, 0x88, 0x43, 0xd2, 0xcb, 0xe3 } };
+
+
+/// HLSL resource description
+struct HLSLShaderResourceDesc : ShaderResourceDesc
+{
+ Uint32 ShaderRegister = 0;
+};
+
+/// Interface to the Direct3D shader resource variable
+class IShaderD3D : public IShader
+{
+public:
+ /// Returns HLSL shader resource description
+ virtual HLSLShaderResourceDesc GetHLSLResource(Uint32 Index)const = 0;
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp
index df4122a4..37f09b42 100644
--- a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp
+++ b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp
@@ -337,56 +337,65 @@ bool ShaderResources::IsCompatibleWith(const ShaderResources &Res)const
return IsCompatible;
}
-ShaderResourceDesc ShaderResources::GetShaderResourceDesc(Uint32 Index)const
+HLSLShaderResourceDesc D3DShaderResourceAttribs::GetHLSLResourceDesc()const
+{
+ HLSLShaderResourceDesc ResourceDesc;
+ ResourceDesc.Name = Name;
+ ResourceDesc.ArraySize = BindCount;
+ ResourceDesc.ShaderRegister = BindPoint;
+ switch(GetInputType())
+ {
+ case D3D_SIT_CBUFFER:
+ ResourceDesc.Type = SHADER_RESOURCE_TYPE_CONSTANT_BUFFER;
+ break;
+
+ case D3D_SIT_TBUFFER:
+ UNSUPPORTED( "TBuffers are not supported" );
+ ResourceDesc.Type = SHADER_RESOURCE_TYPE_UNKNOWN;
+ break;
+
+ case D3D_SIT_TEXTURE:
+ ResourceDesc.Type = (GetSRVDimension() == D3D_SRV_DIMENSION_BUFFER ? SHADER_RESOURCE_TYPE_BUFFER_SRV : SHADER_RESOURCE_TYPE_TEXTURE_SRV);
+ break;
+
+ case D3D_SIT_SAMPLER:
+ ResourceDesc.Type = SHADER_RESOURCE_TYPE_SAMPLER;
+ break;
+
+ case D3D_SIT_UAV_RWTYPED:
+ ResourceDesc.Type = (GetSRVDimension() == D3D_SRV_DIMENSION_BUFFER ? SHADER_RESOURCE_TYPE_BUFFER_UAV : SHADER_RESOURCE_TYPE_TEXTURE_UAV);
+ break;
+
+ case D3D_SIT_STRUCTURED:
+ case D3D_SIT_BYTEADDRESS:
+ ResourceDesc.Type = SHADER_RESOURCE_TYPE_BUFFER_SRV;
+ break;
+
+ case D3D_SIT_UAV_RWSTRUCTURED:
+ case D3D_SIT_UAV_RWBYTEADDRESS:
+ case D3D_SIT_UAV_APPEND_STRUCTURED:
+ case D3D_SIT_UAV_CONSUME_STRUCTURED:
+ case D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER:
+ ResourceDesc.Type = SHADER_RESOURCE_TYPE_BUFFER_UAV;
+ break;
+
+ default:
+ UNEXPECTED("Unknown input type");
+ }
+
+ return ResourceDesc;
+}
+
+HLSLShaderResourceDesc ShaderResources::GetHLSLShaderResourceDesc(Uint32 Index)const
{
DEV_CHECK_ERR(Index < m_TotalResources, "Resource index (", Index, ") is out of range");
- ShaderResourceDesc ResourceDesc;
+ HLSLShaderResourceDesc HLSLResourceDesc = {};
if (Index < m_TotalResources)
{
const auto& Res = GetResAttribs(Index, m_TotalResources, 0);
- ResourceDesc.Name = Res.Name;
- ResourceDesc.ArraySize = Res.BindCount;
- switch(Res.GetInputType())
- {
- case D3D_SIT_CBUFFER:
- ResourceDesc.Type = SHADER_RESOURCE_TYPE_CONSTANT_BUFFER;
- break;
-
- case D3D_SIT_TBUFFER:
- UNSUPPORTED( "TBuffers are not supported" );
- ResourceDesc.Type = SHADER_RESOURCE_TYPE_UNKNOWN;
- break;
-
- case D3D_SIT_TEXTURE:
- ResourceDesc.Type = (Res.GetSRVDimension() == D3D_SRV_DIMENSION_BUFFER ? SHADER_RESOURCE_TYPE_BUFFER_SRV : SHADER_RESOURCE_TYPE_TEXTURE_SRV);
- break;
-
- case D3D_SIT_SAMPLER:
- ResourceDesc.Type = SHADER_RESOURCE_TYPE_SAMPLER;
- break;
-
- case D3D_SIT_UAV_RWTYPED:
- ResourceDesc.Type = (Res.GetSRVDimension() == D3D_SRV_DIMENSION_BUFFER ? SHADER_RESOURCE_TYPE_BUFFER_UAV : SHADER_RESOURCE_TYPE_TEXTURE_UAV);
- break;
-
- case D3D_SIT_STRUCTURED:
- case D3D_SIT_BYTEADDRESS:
- ResourceDesc.Type = SHADER_RESOURCE_TYPE_BUFFER_SRV;
- break;
-
- case D3D_SIT_UAV_RWSTRUCTURED:
- case D3D_SIT_UAV_RWBYTEADDRESS:
- case D3D_SIT_UAV_APPEND_STRUCTURED:
- case D3D_SIT_UAV_CONSUME_STRUCTURED:
- case D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER:
- ResourceDesc.Type = SHADER_RESOURCE_TYPE_BUFFER_UAV;
- break;
-
- default:
- UNEXPECTED("Unknown input type");
- }
+ return Res.GetHLSLResourceDesc();
}
- return ResourceDesc;
+ return HLSLResourceDesc;
}
size_t ShaderResources::GetHash()const