summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineD3D11
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2019-03-03 06:43:26 +0000
committerEgor Yusov <egor.yusov@gmail.com>2019-03-03 06:43:26 +0000
commitf57fc688a659087f5e85d8533f61c4a1fd914810 (patch)
treead7ca6016e0c9e005baa06e3dcbd2cf2ee79e3a3 /Graphics/GraphicsEngineD3D11
parentReworked ShaderD3DBase to comply with the updated API (diff)
downloadDiligentCore-f57fc688a659087f5e85d8533f61c4a1fd914810.tar.gz
DiligentCore-f57fc688a659087f5e85d8533f61c4a1fd914810.zip
Reworked ShaderD3D11Impl to comply with the updated API
Diffstat (limited to 'Graphics/GraphicsEngineD3D11')
-rw-r--r--Graphics/GraphicsEngineD3D11/include/RenderDeviceD3D11Impl.h3
-rw-r--r--Graphics/GraphicsEngineD3D11/include/ShaderD3D11Impl.h33
-rw-r--r--Graphics/GraphicsEngineD3D11/include/ShaderResourceLayoutD3D11.h40
-rw-r--r--Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp30
4 files changed, 33 insertions, 73 deletions
diff --git a/Graphics/GraphicsEngineD3D11/include/RenderDeviceD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/RenderDeviceD3D11Impl.h
index 95548464..0e7f66ad 100644
--- a/Graphics/GraphicsEngineD3D11/include/RenderDeviceD3D11Impl.h
+++ b/Graphics/GraphicsEngineD3D11/include/RenderDeviceD3D11Impl.h
@@ -49,7 +49,7 @@ public:
virtual void CreateBuffer(const BufferDesc& BuffDesc, const BufferData* pBuffData, IBuffer** ppBuffer)override final;
- virtual void CreateShader(const ShaderCreationAttribs& ShaderCreationAttribs, IShader** ppShader)override final;
+ virtual void CreateShader(const ShaderCreateInfo& ShaderCI, IShader** ppShader)override final;
virtual void CreateTexture(const TextureDesc& TexDesc, const TextureData* pData, ITexture** ppTexture)override final;
@@ -81,3 +81,4 @@ private:
};
}
+
diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/ShaderD3D11Impl.h
index 5bafbb1f..c5005c4e 100644
--- a/Graphics/GraphicsEngineD3D11/include/ShaderD3D11Impl.h
+++ b/Graphics/GraphicsEngineD3D11/include/ShaderD3D11Impl.h
@@ -50,31 +50,10 @@ public:
ShaderD3D11Impl(IReferenceCounters* pRefCounters,
class RenderDeviceD3D11Impl* pRenderDeviceD3D11,
- const ShaderCreationAttribs& CreationAttribs);
+ const ShaderCreateInfo& ShaderCI);
~ShaderD3D11Impl();
- virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject** ppInterface )override final;
-
- virtual void BindResources( IResourceMapping* pResourceMapping, Uint32 Flags )override final
- {
- m_StaticResLayout.BindResources(pResourceMapping, Flags, m_StaticResCache);
- }
-
- virtual IShaderVariable* GetShaderVariable( const Char* Name )override final
- {
- return m_StaticResLayout.GetShaderVariable(Name);
- }
-
- virtual Uint32 GetVariableCount() const override final
- {
- return m_StaticResLayout.GetTotalResourceCount();
- }
-
- virtual IShaderVariable* GetShaderVariable(Uint32 Index)override final
- {
- return m_StaticResLayout.GetShaderVariable(Index);
- }
-
+ IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_ShaderD3D11, TShaderBase);
virtual ID3D11DeviceChild* GetD3D11Shader()override final
{
@@ -83,20 +62,12 @@ public:
ID3DBlob* GetBytecode(){return m_pShaderByteCode;}
- ShaderResourceLayoutD3D11& GetStaticResourceLayout(){return m_StaticResLayout;}
- const std::shared_ptr<const ShaderResourcesD3D11>& GetResources()const{return m_pShaderResources;}
Uint32 GetShaderTypeIndex()const{return m_ShaderTypeIndex;}
private:
/// D3D11 shader
CComPtr<ID3D11DeviceChild> m_pShader;
- // ShaderResources class instance must be referenced through the shared pointer, because
- // it is referenced by ShaderResourceLayoutD3D11 class instances
- std::shared_ptr<const ShaderResourcesD3D11> m_pShaderResources;
-
- ShaderResourceCacheD3D11 m_StaticResCache;
- ShaderResourceLayoutD3D11 m_StaticResLayout;
Uint32 m_ShaderTypeIndex; // VS == 0, PS == 1, GS == 2, HS == 3, DS == 4, CS == 5
};
diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderResourceLayoutD3D11.h b/Graphics/GraphicsEngineD3D11/include/ShaderResourceLayoutD3D11.h
index 61970f9d..b6079b0c 100644
--- a/Graphics/GraphicsEngineD3D11/include/ShaderResourceLayoutD3D11.h
+++ b/Graphics/GraphicsEngineD3D11/include/ShaderResourceLayoutD3D11.h
@@ -54,11 +54,11 @@ public:
ShaderResourceLayoutD3D11& operator = ( ShaderResourceLayoutD3D11&&) = delete;
static size_t GetRequiredMemorySize(const ShaderResourcesD3D11& SrcResources,
- const SHADER_VARIABLE_TYPE* VarTypes,
+ const SHADER_RESOURCE_VARIABLE_TYPE* VarTypes,
Uint32 NumVarTypes);
void Initialize(std::shared_ptr<const ShaderResourcesD3D11> pSrcResources,
- const SHADER_VARIABLE_TYPE* VarTypes,
+ const SHADER_RESOURCE_VARIABLE_TYPE* VarTypes,
Uint32 NumVarTypes,
ShaderResourceCacheD3D11& ResourceCache,
IMemoryAllocator& ResCacheDataAllocator,
@@ -71,8 +71,9 @@ public:
struct ConstBuffBindInfo final : ShaderVariableD3D11Base
{
ConstBuffBindInfo( const D3DShaderResourceAttribs& ResourceAttribs,
- ShaderResourceLayoutD3D11& ParentResLayout ) :
- ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs)
+ ShaderResourceLayoutD3D11& ParentResLayout,
+ SHADER_RESOURCE_VARIABLE_TYPE VariableType) :
+ ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs, VariableType)
{}
// Non-virtual function
__forceinline void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex);
@@ -91,8 +92,9 @@ public:
{
TexSRVBindInfo( const D3DShaderResourceAttribs& _TextureAttribs,
Uint32 _SamplerIndex,
- ShaderResourceLayoutD3D11& ParentResLayout) :
- ShaderVariableD3D11Base(ParentResLayout, _TextureAttribs),
+ ShaderResourceLayoutD3D11& ParentResLayout,
+ SHADER_RESOURCE_VARIABLE_TYPE VariableType) :
+ ShaderVariableD3D11Base(ParentResLayout, _TextureAttribs, VariableType),
SamplerIndex(_SamplerIndex)
{}
@@ -117,8 +119,9 @@ public:
struct TexUAVBindInfo final : ShaderVariableD3D11Base
{
TexUAVBindInfo( const D3DShaderResourceAttribs& ResourceAttribs,
- ShaderResourceLayoutD3D11& ParentResLayout ) :
- ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs)
+ ShaderResourceLayoutD3D11& ParentResLayout,
+ SHADER_RESOURCE_VARIABLE_TYPE VariableType ) :
+ ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs, VariableType)
{}
// Provide non-virtual function
@@ -137,8 +140,9 @@ public:
struct BuffUAVBindInfo final : ShaderVariableD3D11Base
{
BuffUAVBindInfo( const D3DShaderResourceAttribs& ResourceAttribs,
- ShaderResourceLayoutD3D11& ParentResLayout ) :
- ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs)
+ ShaderResourceLayoutD3D11& ParentResLayout,
+ SHADER_RESOURCE_VARIABLE_TYPE VariableType ) :
+ ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs, VariableType)
{}
// Non-virtual function
@@ -157,8 +161,9 @@ public:
struct BuffSRVBindInfo final : ShaderVariableD3D11Base
{
BuffSRVBindInfo( const D3DShaderResourceAttribs& ResourceAttribs,
- ShaderResourceLayoutD3D11& ParentResLayout ) :
- ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs)
+ ShaderResourceLayoutD3D11& ParentResLayout,
+ SHADER_RESOURCE_VARIABLE_TYPE VariableType ) :
+ ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs, VariableType)
{}
// Non-virtual function
@@ -177,8 +182,9 @@ public:
struct SamplerBindInfo final : ShaderVariableD3D11Base
{
SamplerBindInfo( const D3DShaderResourceAttribs& ResourceAttribs,
- ShaderResourceLayoutD3D11& ParentResLayout ) :
- ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs)
+ ShaderResourceLayoutD3D11& ParentResLayout,
+ SHADER_RESOURCE_VARIABLE_TYPE VariableType ) :
+ ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs, VariableType)
{}
// Non-virtual function
@@ -202,8 +208,8 @@ public:
bool dvpVerifyBindings()const;
#endif
- IShaderVariable* GetShaderVariable( const Char* Name );
- IShaderVariable* GetShaderVariable( Uint32 Index );
+ IShaderResourceVariable* GetShaderVariable( const Char* Name );
+ IShaderResourceVariable* GetShaderVariable( Uint32 Index );
__forceinline SHADER_TYPE GetShaderType()const{return m_pResources->GetShaderType();}
IObject& GetOwner(){return m_Owner;}
@@ -280,7 +286,7 @@ private:
}
template<typename ResourceType>
- IShaderVariable* GetResourceByName( const Char* Name );
+ IShaderResourceVariable* GetResourceByName( const Char* Name );
template<typename THandleCB,
typename THandleTexSRV,
diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp
index 12288cdd..3af91c50 100644
--- a/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp
+++ b/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp
@@ -32,14 +32,13 @@ namespace Diligent
ShaderD3D11Impl::ShaderD3D11Impl(IReferenceCounters* pRefCounters,
RenderDeviceD3D11Impl* pRenderDeviceD3D11,
- const ShaderCreationAttribs& CreationAttribs) :
- TShaderBase(pRefCounters, pRenderDeviceD3D11, CreationAttribs.Desc),
- ShaderD3DBase(CreationAttribs),
- m_StaticResLayout(*this),
- m_ShaderTypeIndex(Diligent::GetShaderTypeIndex(CreationAttribs.Desc.ShaderType))
+ const ShaderCreateInfo& ShaderCI) :
+ TShaderBase(pRefCounters, pRenderDeviceD3D11, ShaderCI.Desc),
+ ShaderD3DBase(ShaderCI),
+ m_ShaderTypeIndex(Diligent::GetShaderTypeIndex(ShaderCI.Desc.ShaderType))
{
auto *pDeviceD3D11 = pRenderDeviceD3D11->GetD3D11Device();
- switch(CreationAttribs.Desc.ShaderType)
+ switch (ShaderCI.Desc.ShaderType)
{
#define CREATE_SHADER(SHADER_NAME, ShaderName)\
@@ -75,30 +74,13 @@ ShaderD3D11Impl::ShaderD3D11Impl(IReferenceCounters* pRefCounters,
DEV_CHECK_ERR(SUCCEEDED(hr), "Failed to set shader name");
}
- // Load shader resources
- auto &Allocator = GetRawAllocator();
- auto *pRawMem = ALLOCATE(Allocator, "Allocator for ShaderResources", sizeof(ShaderResourcesD3D11));
- auto *pResources = new (pRawMem) ShaderResourcesD3D11(pRenderDeviceD3D11, m_pShaderByteCode, m_Desc, CreationAttribs.UseCombinedTextureSamplers ? CreationAttribs.CombinedSamplerSuffix : nullptr);
- m_pShaderResources.reset(pResources, STDDeleterRawMem<ShaderResourcesD3D11>(Allocator));
-
- // Clone only static resources that will be set directly in the shader
- SHADER_VARIABLE_TYPE VarTypes[] = {SHADER_VARIABLE_TYPE_STATIC};
- // The method will also initialize resource cache to have enough space to hold static variables only!
- m_StaticResLayout.Initialize(m_pShaderResources, VarTypes, _countof(VarTypes), m_StaticResCache, GetRawAllocator(), GetRawAllocator());
-
- // This is not required, but still...
- m_pShaderResources->SetStaticSamplers(m_StaticResCache);
-
// Byte code is only required for the vertex shader to create input layout
- if( CreationAttribs.Desc.ShaderType != SHADER_TYPE_VERTEX )
+ if( ShaderCI.Desc.ShaderType != SHADER_TYPE_VERTEX )
m_pShaderByteCode.Release();
}
ShaderD3D11Impl::~ShaderD3D11Impl()
{
- m_StaticResCache.Destroy(GetRawAllocator());
}
-IMPLEMENT_QUERY_INTERFACE( ShaderD3D11Impl, IID_ShaderD3D11, TShaderBase )
-
}